Testing Database Management Systems via Pivoted Query Synthesis - - PowerPoint PPT Presentation

testing database management systems via pivoted query
SMART_READER_LITE
LIVE PREVIEW

Testing Database Management Systems via Pivoted Query Synthesis - - PowerPoint PPT Presentation

Testing Database Management Systems via Pivoted Query Synthesis Manuel Rigger Oct 18., 2019 Workshop on Dependable and Secure Software Systems 2019 @RiggerManuel @ast_eth Database Management Systems PostgreSQL 2 Database Management Systems


slide-1
SLIDE 1

Testing Database Management Systems via Pivoted Query Synthesis

Manuel Rigger

Oct 18., 2019 Workshop on Dependable and Secure Software Systems 2019

@RiggerManuel @ast_eth

slide-2
SLIDE 2

2

Database Management Systems

PostgreSQL

slide-3
SLIDE 3

3

Database Management Systems

PostgreSQL

Who has heard about/used these Database Management Systems?

slide-4
SLIDE 4

4

Databases are Used Ubiquitously

“SQLite is the most used database engine in the world. SQLite is built into all mobile phones and most computers and comes bundled inside countless other applications that people use every day.”

https://www.sqlite.org

slide-5
SLIDE 5

5

animal description picture Cat A cute toast cat Dog Cute dog pic Cat Cat plants (cute!)

animal_pictures

Relational Data Model

slide-6
SLIDE 6

6

animal description picture Cat A cute toast cat Dog Cute dog pic Cat Cat plants (cute!)

animal_pictures

A database schema describes the tables (relations) in the database

Relational Data Model

slide-7
SLIDE 7

7

animal_pictures

Structured Query Language (SQL) is a declarative DSL to query and manipulate data

SELECT picture, description FROM animal_pictures WHERE animal = 'Cat' AND description LIKE '%cute%'

Relational Data Model

slide-8
SLIDE 8

8

Database Management Systems

Database Database Management System (DBMS)

SELECT * FROM <table> WHERE <cond>

Client Application

slide-9
SLIDE 9

9

Database Management Systems

Database Database Management System (DBMS)

SELECT * FROM <table> WHERE <cond>

Client Application row1 <cond> row2 <cond> row3

¬<cond>

slide-10
SLIDE 10

10

Database Management Systems

Database Database Management System (DBMS)

SELECT * FROM <table> WHERE <cond>

Client Application

row1 <cond> row2 <cond> row3

¬<cond>

row1 <cond> row2 <cond>

slide-11
SLIDE 11

11

Goal

Aim: Detect logic bugs in DBMS

slide-12
SLIDE 12

12

Database Management Systems

Database Database Management System (DBMS)

SELECT * FROM <table> WHERE <cond>

Client Application

row1 <cond> row2 <cond> row3

¬<cond>

row1 <cond> row2 <cond>

slide-13
SLIDE 13

13

Database Management Systems

Database Database Management System (DBMS) Client Application

row1 <cond> row2 <cond> row3

¬<cond>

SELECT * FROM <table> WHERE <cond>

row1 <cond> row3 ¬<cond>

slide-14
SLIDE 14

14

Example Bug: SQLite

CREATE TABLE t1(c1, c2, c3, c4, PRIMARY KEY (c4, c3)); INSERT INTO t1(c3) VALUES (0), (0), (0), (0), (0), (0), (0), (0), (0), (0), (NULL), (1), (0); UPDATE t1 SET c2 = 0; INSERT INTO t1(c1) VALUES (0), (0), (NULL), (0), (0); ANALYZE t1; UPDATE t1 SET c3 = 1; SELECT DISTINCT * FROM t1 WHERE t1.c3 = 1;

slide-15
SLIDE 15

15

Example Bug: SQLite

CREATE TABLE t1(c1, c2, c3, c4, PRIMARY KEY (c4, c3)); INSERT INTO t1(c3) VALUES (0), (0), (0), (0), (0), (0), (0), (0), (0), (0), (NULL), (1), (0); UPDATE t1 SET c2 = 0; INSERT INTO t1(c1) VALUES (0), (0), (NULL), (0), (0); ANALYZE t1; UPDATE t1 SET c3 = 1; SELECT DISTINCT * FROM t1 WHERE t1.c3 = 1;

ANALYZE gathers statistics about tables, which are then used for query planning

slide-16
SLIDE 16

16

Example Bug: SQLite

CREATE TABLE t1(c1, c2, c3, c4, PRIMARY KEY (c4, c3)); INSERT INTO t1(c3) VALUES (0), (0), (0), (0), (0), (0), (0), (0), (0), (0), (NULL), (1), (0); UPDATE t1 SET c2 = 0; INSERT INTO t1(c1) VALUES (0), (0), (NULL), (0), (0); ANALYZE t1; UPDATE t1 SET c3 = 1; SELECT DISTINCT * FROM t1 WHERE t1.c3 = 1;

slide-17
SLIDE 17

17

Example Bug: SQLite

CREATE TABLE t1(c1, c2, c3, c4, PRIMARY KEY (c4, c3)); INSERT INTO t1(c3) VALUES (0), (0), (0), (0), (0), (0), (0), (0), (0), (0), (NULL), (1), (0); UPDATE t1 SET c2 = 0; INSERT INTO t1(c1) VALUES (0), (0), (NULL), (0), (0); ANALYZE t1; UPDATE t1 SET c3 = 1; SELECT DISTINCT * FROM t1 WHERE t1.c3 = 1;

c1 c2 c3 c4 NULL 1 NULL NULL 1 NULL NULL NULL 1 NULL

Expected result set

slide-18
SLIDE 18

18

Example Bug: SQLite

CREATE TABLE t1(c1, c2, c3, c4, PRIMARY KEY (c4, c3)); INSERT INTO t1(c3) VALUES (0), (0), (0), (0), (0), (0), (0), (0), (0), (0), (NULL), (1), (0); UPDATE t1 SET c2 = 0; INSERT INTO t1(c1) VALUES (0), (0), (NULL), (0), (0); ANALYZE t1; UPDATE t1 SET c3 = 1; SELECT DISTINCT * FROM t1 WHERE t1.c3 = 1;

c1 c2 c3 c4 NULL 1 NULL NULL 1 NULL NULL NULL 1 NULL

Expected result set

c1 c2 c3 c4 NULL 1 NULL

Actual result set

slide-19
SLIDE 19

19

Example Bug: SQLite

CREATE TABLE t1(c1, c2, c3, c4, PRIMARY KEY (c4, c3)); INSERT INTO t1(c3) VALUES (0), (0), (0), (0), (0), (0), (0), (0), (0), (0), (NULL), (1), (0); UPDATE t1 SET c2 = 0; INSERT INTO t1(c1) VALUES (0), (0), (NULL), (0), (0); ANALYZE t1; UPDATE t1 SET c3 = 1; SELECT DISTINCT * FROM t1 WHERE t1.c3 = 1;

A bug in the skip-scan

  • ptimization caused

this logic bug

c1 c2 c3 c4 NULL 1 NULL NULL 1 NULL NULL NULL 1 NULL

Expected result set

c1 c2 c3 c4 NULL 1 NULL

Actual result set

slide-20
SLIDE 20

20

Challenges

  • DBMS are tested well
slide-21
SLIDE 21

21

Databases are Tested Well

SQLite (~150,000 LOC) has 662 times as much test code as source code

https://www.sqlite.org/testing.html

slide-22
SLIDE 22

22

Databases are Tested Well

SQLite (~150,000 LOC) has 662 times as much test code as source code SQLite’s test cases achieve 100% branch test coverage

https://www.sqlite.org/testing.html

slide-23
SLIDE 23

23

Databases are Tested Well

SQLite (~150,000 LOC) has 662 times as much test code as source code SQLite is extensively fuzzed (e.g., by Google’s OS-Fuzz Project) SQLite’s test cases achieve 100% branch test coverage

https://www.sqlite.org/testing.html

slide-24
SLIDE 24

24

Databases are Tested Well

SQLite (~150,000 LOC) has 662 times as much test code as source code SQLite is extensively fuzzed (e.g., by Google’s OS-Fuzz Project) SQLite’s test cases achieve 100% branch test coverage SQLite’s performs anomaly testing (out-

  • f-memory, I/O error, power failures)

https://www.sqlite.org/testing.html

slide-25
SLIDE 25

25

Databases are Tested Well

SQLite (~150,000 LOC) has 662 times as much test code as source code SQLite is extensively fuzzed (e.g., by Google’s OS-Fuzz Project) SQLite’s test cases achieve 100% branch test coverage SQLite’s performs anomaly testing (out-

  • f-memory, I/O error, power failures)

https://www.sqlite.org/testing.html

  • Small. Fast. Reliable. Choose any three.
slide-26
SLIDE 26

26

Challenges

  • DBMS are tested well
  • Fuzzers are ineffective in finding logic bugs
slide-27
SLIDE 27

27

Existing Work: Fuzzers and Query Generators

Database

Database Management System (DBMS) Random SQL Query Fuzzer

AFL, SQLSmith, QGEN (Poess et al. 2014), …

slide-28
SLIDE 28

28

Existing Work: Fuzzers and Query Generators

Database

Database Management System (DBMS) Random SQL Query Fuzzer

SEGMENTATION FAULT

AFL, SQLSmith, QGEN (Poess et al. 2014), …

slide-29
SLIDE 29

29

Existing Work: Fuzzers and Query Generators

Database

Database Management System (DBMS) Random SQL Query Fuzzer

Fuzzers are effective in detecting bugs that result in crashes

SEGMENTATION FAULT

AFL, SQLSmith, QGEN (Poess et al. 2014), …

slide-30
SLIDE 30

30

Challenges

  • DBMS are tested well
  • Fuzzers are ineffective in finding logic bugs
  • Knowing the precise result set for a query is difficult
slide-31
SLIDE 31

31

Differential Testing

Query Generator

PostgreSQL

RS1 RS2 RS3 RS1 = RS2 = RS3?

slide-32
SLIDE 32

32

Differential Testing

Query Generator

PostgreSQL

Differential testing applies only when systems implement the same language RS1 RS2 RS3 RS1 = RS2 = RS3?

slide-33
SLIDE 33

33

Problem: Differential Testing

DBMS- specific SQL

Common SQL Core

Problem: The common SQL core is small

slide-34
SLIDE 34

34

Differential Testing: RAGS (Slutz 1998)

“[Differential testing] proved to be extremely useful, but only for the small set of common SQL”

slide-35
SLIDE 35

35

Constraint Solving (Khalek et al. 2010)

Idea: Use a solver to generate queries, generate data, and provide a test oracle

Query Generation Database and Test Oracle Generation

Could reproduce already reported bugs, injected bugs, but only one (potentially) new bug

slide-36
SLIDE 36

36

Challenges

  • DBMS are tested well
  • Fuzzers are ineffective in finding logic bugs
  • Knowing the precise result set for a query is difficult

The problem of automatically testing DBMS has not yet been well addressed

slide-37
SLIDE 37

37

Approach: Pivoted Query Synthesis

Pivoted Query Synthesis (PQS)

Pivoted Query Synthesis is an automatic testing approach that can be used to effectively test DBMS

>100 bugs in widely used DBMS

slide-38
SLIDE 38

38

Idea: PQS

Idea: Construct an automatic testing approach considering only a single row

Column0 Column1 Column2 … … …

Valuei,0 Valuei,1 Valuei,2

… … …

Pivot Row

slide-39
SLIDE 39

39

Intuition

  • Simpler conceptually and implementation-wise

Column0 Column1 Column2 … … …

Valuei,0 Valuei,1 Valuei,2

… … …

<cond>? SELECT * FROM <table> WHERE <cond>

slide-40
SLIDE 40

40

Intuition

  • Simpler conceptually and implementation-wise
  • Same effectiveness as checking all rows

Column0 Column1 Column2 … … …

Valuei,0 Valuei,1 Valuei,2

… … …

SELECT * FROM <table> WHERE <cond>

slide-41
SLIDE 41

41

Intuition

  • Simpler conceptually and implementation-wise
  • Same effectiveness as checking all rows

Column0 Column1 Column2 … … …

Valuei,0 Valuei,1 Valuei,2

… … …

SELECT * FROM <table> WHERE <cond>

slide-42
SLIDE 42

42

Intuition

  • Simpler conceptually and implementation-wise
  • Same effectiveness as checking all rows
slide-43
SLIDE 43

43

Intuition

  • Simpler conceptually and implementation-wise
  • Same effectiveness as checking all rows
  • Precise oracle for a single row
slide-44
SLIDE 44

Approach

slide-45
SLIDE 45

45

Database Generation

Randomly Generate Database

slide-46
SLIDE 46

46

Database Generation

Randomly Generate Database

To explore “all possible database states” we randomly create databases

slide-47
SLIDE 47

47

Pivot Row Selection

Randomly Generate Database Select Pivot Row

slide-48
SLIDE 48

48

Query Generation

Randomly Generate Database Select Pivot Row Generate Query for the Pivot Row animal description picture Cat Cat plants (cute!)

SELECT picture, description FROM animal_pictures WHERE animal = 'Cat' AND description LIKE '%cute%'

slide-49
SLIDE 49

49

Verifying the Result

Randomly Generate Database Select Pivot Row Generate Query for the Pivot Row Verify that the Pivot Row is contained DBMS

SELECT picture, description FROM animal_pictures WHERE animal = 'Cat' AND description LIKE '%cute%'

result set pivot row

slide-50
SLIDE 50

50

Verifying the Result

Randomly Generate Database Select Pivot Row Generate Query for the Pivot Row Verify that the Pivot Row is contained DBMS

SELECT picture, description FROM animal_pictures WHERE animal = 'Cat' AND description LIKE '%cute%'

result set pivot row

pivot row ∈ result set

slide-51
SLIDE 51

51

Verifying the Result

Randomly Generate Database Select Pivot Row Generate Query for the Pivot Row Verify that the Pivot Row is contained DBMS

SELECT picture, description FROM animal_pictures WHERE animal = 'Cat' AND description LIKE '%cute%'

result set pivot row

slide-52
SLIDE 52

52

Verifying the Result

Randomly Generate Database Select Pivot Row Generate Query for the Pivot Row Verify that the Pivot Row is contained DBMS

SELECT picture, description FROM animal_pictures WHERE animal = 'Cat' AND description LIKE '%cute%'

result set pivot row

pivot row ∉ result set

slide-53
SLIDE 53

53

Verifying the Result

Randomly Generate Database Select Pivot Row Generate Query for the Pivot Row Verify that the Pivot Row is contained

pivot row ∉ result set

The “containment oracle” is PQS’ primary oracle

slide-54
SLIDE 54

54

Approach

Randomly Generate Database Select Pivot Row Generate Query for the Pivot Row Verify that the Pivot Row is contained

slide-55
SLIDE 55

55

Approach

Randomly Generate Database Select Pivot Row Generate Query for the Pivot Row Verify that the Pivot Row is contained

slide-56
SLIDE 56

56

Approach

Randomly Generate Database Select Pivot Row Generate Query for the Pivot Row Verify that the Pivot Row is contained

slide-57
SLIDE 57

57

Approach

Randomly Generate Database Select Pivot Row Generate Query for the Pivot Row Verify that the Pivot Row is contained

How do we generate this query?

slide-58
SLIDE 58

58

How do we Generate Queries?

Generate an expression that yields TRUE for the pivot row SELECT picture, description FROM animal_pictures WHERE

slide-59
SLIDE 59

59

How do we Generate Queries?

Randomly Generate Expression Evaluate Expression on Pivot Row Modify expression to yield TRUE Use in WHERE clause

slide-60
SLIDE 60

60

Random Expression Generation

animal description picture

https://www.sqlite.org/syntax/expr.html

animal_pictures

We first generate a random expression

slide-61
SLIDE 61

61

Random Expression Generation

animal = 'Cat' AND description LIKE '%cute%'

AND = LIKE animal 'Cat' descrip tion '%cute%'

slide-62
SLIDE 62

62

Random Expression Generation

animal = 'Cat' AND description LIKE '%cute%'

Evaluate the tree based

  • n the pivot row

AND = LIKE animal 'Cat' descrip tion '%cute%'

slide-63
SLIDE 63

63

Random Expression Evaluation

AND = LIKE animal 'Cat' descrip tion 'Cat' '%cute%'

Constant nodes return their assigned literal values

'%cute%'

slide-64
SLIDE 64

64

Random Expression Evaluation

AND = LIKE animal 'Cat' descrip tion 'Cat plants (cute!)' 'Cat' 'Cat' '%cute%'

Column references return the values from the pivot row

'%cute%'

slide-65
SLIDE 65

65

Random Expression Evaluation

AND = LIKE animal 'Cat' descrip tion 'Cat plants (cute!)' 'Cat' TRUE TRUE 'Cat' '%cute%'

Compound nodes compute their result based on their children

'%cute%'

slide-66
SLIDE 66

66

Random Expression Evaluation

AND = LIKE animal 'Cat' descrip tion 'Cat plants (cute!)' 'Cat' TRUE TRUE TRUE 'Cat' '%cute%' '%cute%'

slide-67
SLIDE 67

67

SELECT picture, description FROM animal_pictures WHERE animal = 'Cat' AND description LIKE '%cute%'

Query Synthesis

slide-68
SLIDE 68

68

Random Expression Evaluation

AND = LIKE animal 'Cat' descrip tion 'Cat plants (cute!)' 'Cat' TRUE TRUE TRUE 'Cat' '%cute%'

What about when the expression does not evaluate to TRUE?

'%cute%'

slide-69
SLIDE 69

69

Random Expression Evaluation

= animal 'Dog' 'Cat' FALSE 'Dog'

What about when the expression does not evaluate to TRUE?

animal = 'Dog'

slide-70
SLIDE 70

70

Random Expression Rectification

switch (result) { case TRUE: result = randexpr; case FALSE: result = NOT randexpr; case NULL: result = randexpr ISNULL; }

slide-71
SLIDE 71

71

Random Expression Rectification

switch (result) { case TRUE: result = randexpr; case FALSE: result = NOT randexpr; case NULL: result = randexpr ISNULL; } animal = 'Dog'

FALSE

slide-72
SLIDE 72

72

Random Expression Rectification

switch (result) { case TRUE: result = randexpr; case FALSE: result = NOT randexpr; case NULL: result = randexpr ISNULL; } NOT(animal = 'Dog')

TRUE

slide-73
SLIDE 73

73

How do we Generate Queries?

SELECT picture, description FROM animal_pictures WHERE NOT(animal = 'Dog')

slide-74
SLIDE 74

Evaluation

slide-75
SLIDE 75

75

Tested DBMS

PostgreSQL

slide-76
SLIDE 76

76

Tested DBMS

PostgreSQL

We tested these (and other DBMS) in a period of 3-4 months

slide-77
SLIDE 77

77

DBMS

slide-78
SLIDE 78

78

DBMS

slide-79
SLIDE 79

79

DBMS

slide-80
SLIDE 80

80

Bugs Overview

DBMS Fixed Verified SQLite 65 MySQL 15 10 PostgreSQL 5 4 Sum 85 14

Real Bugs

slide-81
SLIDE 81

81

Bugs Overview

DBMS Fixed Verified SQLite 65 MySQL 15 10 PostgreSQL 5 4 Sum 85 14

99 real bugs: addressed by code or documentation fixes, or verified as bugs

Real Bugs

slide-82
SLIDE 82

82

Bugs Overview

The SQLite developers quickly responded to all

  • ur bug reports → we focused on this DBMS

Real Bugs

DBMS Fixed Verified SQLite 65 MySQL 15 10 PostgreSQL 5 4 Sum 85 14

slide-83
SLIDE 83

83

Bugs Overview

Real Bugs

DBMS Fixed Verified SQLite 65 MySQL 15 10 PostgreSQL 5 4 Sum 85 14

All MySQL bug reports were verified quickly

slide-84
SLIDE 84

84

Bugs Overview

Real Bugs

DBMS Fixed Verified SQLite 65 MySQL 15 10 PostgreSQL 5 4 Sum 85 14

MySQL’s trunk is not available, and it has a long release cycle

slide-85
SLIDE 85

85

Bugs Overview

Real Bugs

DBMS Fixed Verified SQLite 65 MySQL 15 10 PostgreSQL 5 4 Sum 85 14

We found the fewest bugs in PostgreSQL and not all could be easily addressed

slide-86
SLIDE 86

86

Oracles

DBMS Containment Error SEGFAULT SQLite 46 17 2 MySQL 14 10 1 PostgreSQL 1 7 1 Sum 61 34 4

Real Bugs

slide-87
SLIDE 87

87

Oracles

DBMS Containment Error SEGFAULT SQLite 46 17 2 MySQL 14 10 1 PostgreSQL 1 7 1 Sum 61 34 4

Real Bugs Containment Oracle

Our Containment oracle allowed us to detect most errors

slide-88
SLIDE 88

88

Result: Bug in SQLite3

CREATE TABLE t0(c1 TEXT PRIMARY KEY) WITHOUT ROWID; CREATE INDEX i0 ON t0(c1 COLLATE NOCASE); INSERT INTO t0(c1) VALUES ('A'); INSERT INTO t0(c1) VALUES ('a');

Real Bugs Containment Oracle

slide-89
SLIDE 89

89

Result: Bug in SQLite3

CREATE TABLE t0(c1 TEXT PRIMARY KEY) WITHOUT ROWID; CREATE INDEX i0 ON t0(c1 COLLATE NOCASE); INSERT INTO t0(c1) VALUES ('A'); INSERT INTO t0(c1) VALUES ('a');

An index is an auxiliary data structure that should not affect the query’s result

Real Bugs Containment Oracle

slide-90
SLIDE 90

90

Result: Bug in SQLite3

CREATE TABLE t0(c1 TEXT PRIMARY KEY) WITHOUT ROWID; CREATE INDEX i0 ON t0(c1 COLLATE NOCASE); INSERT INTO t0(c1) VALUES ('A'); INSERT INTO t0(c1) VALUES ('a');

c1

'A' 'a'

Real Bugs Containment Oracle

slide-91
SLIDE 91

91

Result: Bug in SQLite3

CREATE TABLE t0(c1 TEXT PRIMARY KEY) WITHOUT ROWID; CREATE INDEX i0 ON t0(c1 COLLATE NOCASE); INSERT INTO t0(c1) VALUES ('A'); INSERT INTO t0(c1) VALUES ('a');

c1

'A' 'a'

SELECT * FROM t0;

c1

'A'

Real Bugs Containment Oracle

slide-92
SLIDE 92

92

Result: Bug in SQLite3

CREATE TABLE t0(c1 TEXT PRIMARY KEY) WITHOUT ROWID; CREATE INDEX i0 ON t0(c1 COLLATE NOCASE); INSERT INTO t0(c1) VALUES ('A'); INSERT INTO t0(c1) VALUES ('a');

c1

'A' 'a'

SELECT * FROM t0;

c1

'A' 

SQLite failed to fetch 'a'!

Real Bugs Containment Oracle

slide-93
SLIDE 93

93

Result: Bug in PostgreSQL

CREATE TABLE t0(c0 INT PRIMARY KEY, c1 INT); CREATE TABLE t1(c0 INT) INHERITS (t0);

c0 c1 c0 c1

t0 t1

Real Bugs Containment Oracle

slide-94
SLIDE 94

94

Result: Bug in PostgreSQL

CREATE TABLE t0(c0 INT PRIMARY KEY, c1 INT); CREATE TABLE t1(c0 INT) INHERITS (t0); INSERT INTO t0(c0, c1) VALUES(0, 0);

c0 c1 c0 c1

t0 t1

Real Bugs Containment Oracle

slide-95
SLIDE 95

95

Result: Bug in PostgreSQL

CREATE TABLE t0(c0 INT PRIMARY KEY, c1 INT); CREATE TABLE t1(c0 INT) INHERITS (t0); INSERT INTO t0(c0, c1) VALUES(0, 0); INSERT INTO t1(c0, c1) VALUES(0, 1);

c0 c1 1 c0 c1 1

t0 t1

Real Bugs Containment Oracle

slide-96
SLIDE 96

96

Result: Bug in PostgreSQL

CREATE TABLE t0(c0 INT PRIMARY KEY, c1 INT); CREATE TABLE t1(c0 INT) INHERITS (t0); INSERT INTO t0(c0, c1) VALUES(0, 0); INSERT INTO t1(c0, c1) VALUES(0, 1);

c0 c1 1 c0 c1 1

t0 t1

The inheritance relationship causes the row to be inserted both in t0 and t1

Real Bugs Containment Oracle

slide-97
SLIDE 97

97

Result: Bug in PostgreSQL

CREATE TABLE t0(c0 INT PRIMARY KEY, c1 INT); CREATE TABLE t1(c0 INT) INHERITS (t0); INSERT INTO t0(c0, c1) VALUES(0, 0); INSERT INTO t1(c0, c1) VALUES(0, 1);

c0 c1 1 c0 c1 1

t0 t1 SELECT c0, c1 FROM t0 GROUP BY c0, c1;

c0 c1

Real Bugs Containment Oracle

slide-98
SLIDE 98

98

Result: Bug in PostgreSQL

CREATE TABLE t0(c0 INT PRIMARY KEY, c1 INT); CREATE TABLE t1(c0 INT) INHERITS (t0); INSERT INTO t0(c0, c1) VALUES(0, 0); INSERT INTO t1(c0, c1) VALUES(0, 1);

c0 c1 1 c0 c1 1

t0 t1 SELECT c0, c1 FROM t0 GROUP BY c0, c1;

c0 c1

PostgreSQL failed to fetch the row 0 | 1

Real Bugs Containment Oracle

slide-99
SLIDE 99

99

Result: Bug in MySQL

CREATE TABLE t0(c0 TINYINT); INSERT INTO t0(c0) VALUES(NULL);

c0 NULL

t0

Real Bugs Containment Oracle

slide-100
SLIDE 100

100

Result: Bug in MySQL

CREATE TABLE t0(c0 TINYINT); INSERT INTO t0(c0) VALUES(NULL);

c0 NULL

t0

SELECT * FROM t0 WHERE NOT(t0.c0 <=> 2035382037);

c0

FALSE Real Bugs Containment Oracle

slide-101
SLIDE 101

101

Result: Bug in MySQL

CREATE TABLE t0(c0 TINYINT); INSERT INTO t0(c0) VALUES(NULL);

c0 NULL

t0

SELECT * FROM t0 WHERE NOT(t0.c0 <=> 2035382037);

c0

The MySQL-specific equality operator <=> malfunctioned for large numbers

FALSE Real Bugs Containment Oracle

slide-102
SLIDE 102

102

Oracles

DBMS Containment Error SEGFAULT SQLite 46 17 2 MySQL 14 10 1 PostgreSQL 1 7 1 Sum 61 34 4

We also found many bugs using an Error oracle

Real Bugs Error Oracle

slide-103
SLIDE 103

103

SQLite3 Bug

CREATE TABLE t1 (c0, c1 REAL PRIMARY KEY); INSERT INTO t1(c0, c1) VALUES (TRUE, 9223372036854775807), (TRUE, 0); UPDATE t1 SET c0 = NULL; UPDATE OR REPLACE t1 SET c1 = 1; SELECT DISTINCT * FROM t1 WHERE (t1.c0 IS NULL);

Real Bugs Error Oracle

slide-104
SLIDE 104

104

SQLite3 Bug

CREATE TABLE t1 (c0, c1 REAL PRIMARY KEY); INSERT INTO t1(c0, c1) VALUES (TRUE, 9223372036854775807), (TRUE, 0); UPDATE t1 SET c0 = NULL; UPDATE OR REPLACE t1 SET c1 = 1; SELECT DISTINCT * FROM t1 WHERE (t1.c0 IS NULL);

Database disk image is malformed

Real Bugs Error Oracle

slide-105
SLIDE 105

105

SQLite3 Bug

CREATE TABLE t1 (c0, c1 REAL PRIMARY KEY); INSERT INTO t1(c0, c1) VALUES (TRUE, 9223372036854775807), (TRUE, 0); UPDATE t1 SET c0 = NULL; UPDATE OR REPLACE t1 SET c1 = 1; SELECT DISTINCT * FROM t1 WHERE (t1.c0 IS NULL);

The INSERT and UPDATE statements corrupted the database

Database disk image is malformed

Real Bugs Error Oracle

slide-106
SLIDE 106

106

Oracles

DBMS Containment Error SEGFAULT SQLite 46 17 2 MySQL 14 10 1 PostgreSQL 1 7 1 Sum 61 34 4

We found only a low number of crash bugs, likely because DBMS are fuzzed extensively

Real Bugs SEGFAULTs

slide-107
SLIDE 107

107

Average Number of Statements

Half of all bugs can be reproduced with only 4 SQL statements

Real Bugs

slide-108
SLIDE 108

108

SQLite3 Bug with a Single Statement

Real Bugs

SELECT '' - 2851427734582196970;

  • 2851427734582196936

Subtracting a large integer from a string resulted in an incorrect result

slide-109
SLIDE 109

109

Discussion

  • Are the bugs relevant?
slide-110
SLIDE 110

110

Discussion

  • Are the bugs relevant?

The SQLite developers (inconsistently) assigned severity levels

Severity Level # Critical 14 Severe 8 Important 14

slide-111
SLIDE 111

111

Discussion

  • Are the bugs relevant?
  • Statement coverage
slide-112
SLIDE 112

112

Discussion

  • Are the bugs relevant?
  • Statement coverage

Low coverage 20%-50%, DBMS provide a lot more than pure database management

slide-113
SLIDE 113

113

Discussion

  • Are the bugs relevant?
  • Statement coverage
  • Implementation effort
slide-114
SLIDE 114

114

Discussion

  • Are the bugs relevant?
  • Statement coverage
  • Implementation effort

4,000-6,000 LOC per DBMS → significantly smaller than the DBMS

slide-115
SLIDE 115

115

Discussion

  • Are the bugs relevant?
  • Statement coverage
  • Implementation effort
  • Limitations
slide-116
SLIDE 116

116

Discussion

  • Are the bugs relevant?
  • Statement coverage
  • Implementation effort
  • Limitations
  • Aggregate and window functions
  • Difficult-to-implement functionality
slide-117
SLIDE 117

117

Larger Picture

Pivoted Query Synthesis (PQS)

slide-118
SLIDE 118

118

Larger Picture

Pivoted Query Synthesis (PQS) Metamorphic Testing Aggregate Testing

PQS is one of multiple DBMS testing approaches we have been working on

slide-119
SLIDE 119

119

Larger Picture

Pivoted Query Synthesis (PQS) Metamorphic Testing Aggregate Testing

We have found about 15 bugs by a novel metamorphic testing approach that can compute a precise result set

slide-120
SLIDE 120

120

Larger Picture

Pivoted Query Synthesis (PQS) Metamorphic Testing Aggregate Testing

PQS is not applicable for testing aggregate and window functions

slide-121
SLIDE 121

121

@RiggerManuel

Challenge: Precise Oracle is Difficult to Construct Aim: Find Logic Bugs in DBMS Idea: Consider Only a Single Row PQS is Highly Effective Create Expressions that Yield TRUE for the Pivot Row