SQLancer, a tool to automatically test DBMSs to find logic bugs
github.com
github.com
Indeed is curious as to how it runs against Oracle or MSSQL, but maybe commercial guys should fund the work first otherwise they’ll just thanku-for-the-job which actually would potentially save them millions...
We will also consider testing DBMS with a DeWitt Clause in the future. For now, we have indirect evidence that our approaches could find bugs in Oracle. Specifically, we found a case in MySQL, which we consider a bug, but which was closed by the bug verifiers, partly because Oracle computes the same - we believe incorrect - result. Our bug report can be found here: https://bugs.mysql.com/bug.php?id=99182.
We believe that it is a bug, because:
* the invariants that we are testing using TLP, which is the approach that we used to find the bug, should hold for all DBMS;
* dropping the UNIQUE constraint would yield the result we would expect, and we believe that an index should never affect a query's result;
* an earlier version of MySQL computed the result we would expect;
* and DBMS that strive to support the MySQL SQL dialect, computed the result we would expect (e.g., TiDB).
Writing 100% bug-free databases is probably not possible with current development tools, but it might also not be required. Every extra "nine" of reliability costs exponentially more, whether you're looking at uptime, durability or any other metric. At some point the extra costs just don't measure up to the extra correctness gained.
Before we proposed our testing approaches, the state of the art of finding logic bugs was writing unit tests, which does not scale well, since it requires much manual effort. We believe that we provide the first practical approaches to automatically finding logic bugs. Companies have already started adopting them. For example, PingCAP implemented all three approaches that we proposed in https://github.com/chaos-mesh/go-sqlancer to test their DBMS TiDB.
A number of tools are available to test other aspects, like performance or for crash bugs. SQLsmith, for example, is one effective tool that allows finding crash bugs (see https://github.com/anse1/sqlsmith).
When the user reported the bug, it had actually already been fixed on the latest SQLite3 trunk based on one of our bug reports. The query in our test case used a “NOT NULL NOT NULL” predicate, which is unnecessary complex as well: https://www.sqlite.org/src/tktview?name=c31034044b. We believe that this is interesting evidence that even “obscure” bugs matter in practice, for example, when the queries are automatically generated, as demonstrated above.
Manual correctness checking of SQL is cumbersome and error-prone since developers may write queries in several different ways, while using fixed datasets (independent of the query) may fail to catch errors in them. XData automatically generates small datasets designed to catch errors in the queries (an example error is using a left-join instead of a full outer join).
Any ideas about how we can combine the utilities of SQLancer and XData / Cosette? I was a research intern at IITB Database Group, who developed XData and I still contribute to the project.
Implementation-wise, supporting CouchDB and MongoDB in SQLancer would be feasible. SQLancer shares little infrastructure between the testing implementations for the individual DBMS, and thus imposes only few restrictions on them. We would definitely welcome implementations for any NoSQL DBMS in SQLancer!
* Pivoted Query Synthesis (PQS): The main idea is to generate a query that is guaranteed to fetch a randomly-selected row, to which we refer as the pivot row. If the pivot row is not contained in the result set, we have detected a bug.
* Non-Optimizing Reference Engine Construction (NoREC): The idea is to transform a query so that it cannot be optimized effectively by the DBMS. By comparing the result set of the "optimized" query with the result set of the "unoptimized" query, we can detect bugs that affect the DBMS' query optimizer.
* Ternary Logic Partitioning (TLP): The main idea of this approach is that we can partition a given query into multiple "partitioning" queries, each of which computes a partition of the result, and to then combine these partitions to derive the same result as the original query. If the two results differ, we have detected a bug in the DBMS.
Same applies for Microsoft's SQL Server.
[1] http://www.oracle.com/us/corporate/pricing/olsa-ire-v122304-...