Skip to content

Commit 1aeb0f6

Browse files
authored
doc: add CERT (#843)
* cockroachdb: formatting * doc: add CERT * cert: collect every tables for any cert oracle
1 parent 03ddf95 commit 1aeb0f6

4 files changed

Lines changed: 13 additions & 12 deletions

File tree

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ SQLancer (Synthesized Query Lancer) is a tool to automatically test Database Man
99

1010
SQLancer operates in the following two phases:
1111

12-
1. Database generation: The goal of this phase is to create a populated database, and stress the DBMS to increase the probability of causing an inconsistent database state that could be detected subsequently. First, random tables are created. Then, randomly SQL statements are chosen to generate, modify, and delete data. Also other statements, such as those to create indexes as well as views and to set DBMS-specific options are sent to the DBMS. **New: we support query plan guided generation now. See Generation Approaches below.**
13-
2. Testing: The goal of this phase is to detect the logic bugs based on the generated database. See Testing Approaches below.
12+
1. Database generation: The goal of this phase is to create a populated database, and stress the DBMS to increase the probability of causing an inconsistent database state that could be detected subsequently. First, random tables are created. Then, randomly SQL statements are chosen to generate, modify, and delete data. Also other statements, such as those to create indexes as well as views and to set DBMS-specific options are sent to the DBMS. **News: we support Query Plan Guidance (QPG) now. See Generation Approaches below.**
13+
2. Testing: The goal of this phase is to detect the logic bugs based on the generated database. See Testing Approaches below. **News: we support Cardinality Estimation Restriction Testing (CERT) oracle now. See Testing Approaches below.**
1414

1515
# Getting Started
1616

@@ -40,6 +40,8 @@ If you launch SQLancer without parameters, available options and commands are di
4040
| Pivoted Query Synthesis (PQS) | PQS is the first technique that we designed and implemented. It randomly selects a row, called a pivot row, for which a query is generated that is guaranteed to fetch the row. If the row is not contained in the result set, a bug has been detected. It is fully described [here](https://arxiv.org/abs/2001.04174). PQS is the most powerful technique, but also requires more implementation effort than the other two techniques. It is currently unmaintained. |
4141
| Non-optimizing Reference Engine Construction (NoREC) | NoREC aims to find optimization bugs. It is described [here](https://www.manuelrigger.at/preprints/NoREC.pdf). It translates a query that is potentially optimized by the DBMS to one for which hardly any optimizations are applicable, and compares the two result sets. A mismatch between the result sets indicates a bug in the DBMS. |
4242
| Ternary Logic Partitioning (TLP) | TLP partitions a query into three partitioning queries, whose results are composed and compare to the original query's result set. A mismatch in the result sets indicates a bug in the DBMS. In contrast to NoREC and PQS, it can detect bugs in advanced features such as aggregate functions. |
43+
| Cardinality Estimation Restriction Testing (CERT) | CERT aims to find performance issues through unexpected estimated cardinalities, which represent the estimated number of returned rows. It is described [here](https://arxiv.org/abs/2306.00355). It derives a query to a more restrict query, whose estimated cardinality should be no more than that for the original query. An violation indicates a potential performance issue. CERT supports TiDB, CockroachDB, and MySQL. |
44+
4345
# Generation Approaches
4446
| Approach | Description |
4547
|----------|-------------|

src/sqlancer/cockroachdb/CockroachDBProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import sqlancer.SQLConnection;
2020
import sqlancer.SQLGlobalState;
2121
import sqlancer.SQLProviderAdapter;
22+
import sqlancer.cockroachdb.CockroachDBOptions.CockroachDBOracleFactory;
2223
import sqlancer.cockroachdb.CockroachDBProvider.CockroachDBGlobalState;
2324
import sqlancer.cockroachdb.CockroachDBSchema.CockroachDBTable;
2425
import sqlancer.cockroachdb.gen.CockroachDBCommentOnGenerator;
@@ -36,7 +37,6 @@
3637
import sqlancer.cockroachdb.gen.CockroachDBTruncateGenerator;
3738
import sqlancer.cockroachdb.gen.CockroachDBUpdateGenerator;
3839
import sqlancer.cockroachdb.gen.CockroachDBViewGenerator;
39-
import sqlancer.cockroachdb.oracle.CockroachDBCERTOracle;
4040
import sqlancer.common.query.ExpectedErrors;
4141
import sqlancer.common.query.SQLQueryAdapter;
4242
import sqlancer.common.query.SQLQueryProvider;
@@ -252,8 +252,8 @@ public void generateDatabase(CockroachDBGlobalState globalState) throws Exceptio
252252
total--;
253253
}
254254

255-
if (globalState.getDbmsSpecificOptions().getTestOracleFactory().size() == 1 && globalState
256-
.getDbmsSpecificOptions().getTestOracleFactory().get(0).create(globalState) instanceof CockroachDBCERTOracle) {
255+
if (globalState.getDbmsSpecificOptions().getTestOracleFactory().stream()
256+
.anyMatch((o) -> o == CockroachDBOracleFactory.CERT)) {
257257
// Enfore statistic collected for all tables
258258
ExpectedErrors errors = new ExpectedErrors();
259259
CockroachDBErrors.addExpressionErrors(errors);

src/sqlancer/mysql/MySQLProvider.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import sqlancer.common.query.ExpectedErrors;
2222
import sqlancer.common.query.SQLQueryAdapter;
2323
import sqlancer.common.query.SQLQueryProvider;
24+
import sqlancer.mysql.MySQLOptions.MySQLOracleFactory;
2425
import sqlancer.mysql.MySQLSchema.MySQLColumn;
2526
import sqlancer.mysql.MySQLSchema.MySQLTable;
2627
import sqlancer.mysql.gen.MySQLAlterTable;
@@ -38,7 +39,6 @@
3839
import sqlancer.mysql.gen.tblmaintenance.MySQLChecksum;
3940
import sqlancer.mysql.gen.tblmaintenance.MySQLOptimize;
4041
import sqlancer.mysql.gen.tblmaintenance.MySQLRepair;
41-
import sqlancer.mysql.oracle.MySQLCERTOracle;
4242

4343
@AutoService(DatabaseProvider.class)
4444
public class MySQLProvider extends SQLProviderAdapter<MySQLGlobalState, MySQLOptions> {
@@ -157,9 +157,8 @@ public void generateDatabase(MySQLGlobalState globalState) throws Exception {
157157
});
158158
se.executeStatements();
159159

160-
if (globalState.getDbmsSpecificOptions().getTestOracleFactory().size() == 1
161-
&& globalState.getDbmsSpecificOptions().getTestOracleFactory().get(0)
162-
.create(globalState) instanceof MySQLCERTOracle) {
160+
if (globalState.getDbmsSpecificOptions().getTestOracleFactory().stream()
161+
.anyMatch((o) -> o == MySQLOracleFactory.CERT)) {
163162
// Enfore statistic collected for all tables
164163
ExpectedErrors errors = new ExpectedErrors();
165164
MySQLErrors.addExpressionErrors(errors);

src/sqlancer/tidb/TiDBProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import sqlancer.common.query.SQLQueryAdapter;
2424
import sqlancer.common.query.SQLQueryProvider;
2525
import sqlancer.common.query.SQLancerResultSet;
26+
import sqlancer.tidb.TiDBOptions.TiDBOracleFactory;
2627
import sqlancer.tidb.TiDBProvider.TiDBGlobalState;
2728
import sqlancer.tidb.TiDBSchema.TiDBTable;
2829
import sqlancer.tidb.gen.TiDBAlterTableGenerator;
@@ -36,7 +37,6 @@
3637
import sqlancer.tidb.gen.TiDBTableGenerator;
3738
import sqlancer.tidb.gen.TiDBUpdateGenerator;
3839
import sqlancer.tidb.gen.TiDBViewGenerator;
39-
import sqlancer.tidb.oracle.TiDBCERTOracle;
4040

4141
@AutoService(DatabaseProvider.class)
4242
public class TiDBProvider extends SQLProviderAdapter<TiDBGlobalState, TiDBOptions> {
@@ -139,8 +139,8 @@ public void generateDatabase(TiDBGlobalState globalState) throws Exception {
139139
}
140140
}
141141

142-
if (globalState.getDbmsSpecificOptions().getTestOracleFactory().size() == 1 && globalState
143-
.getDbmsSpecificOptions().getTestOracleFactory().get(0).create(globalState) instanceof TiDBCERTOracle) {
142+
if (globalState.getDbmsSpecificOptions().getTestOracleFactory().stream()
143+
.anyMatch((o) -> o == TiDBOracleFactory.CERT)) {
144144
// Disable strict Group By constraints for ROW oracle
145145
globalState.executeStatement(new SQLQueryAdapter(
146146
"SET @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';"));

0 commit comments

Comments
 (0)