Skip to content

Commit b71ef36

Browse files
committed
[CockroachDB] Create an option to use HASH indexes
1 parent 21f7009 commit b71ef36

6 files changed

Lines changed: 38 additions & 2 deletions

File tree

src/sqlancer/cockroachdb/CockroachDBErrors.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,28 @@
55
public class CockroachDBErrors {
66

77
public static void addExpressionErrors(Set<String> errors) {
8+
errors.add(" non-streaming operator encountered when vectorize=auto");
89

910
if (true) {
1011
// https://github.com/cockroachdb/cockroach/issues/46403
1112
errors.add("duplicate column name");
1213
}
1314

15+
if (true) {
16+
// https://github.com/pingcap/tidb/issues/16017
17+
errors.add("Can't find a proper physical plan for this query");
18+
}
19+
1420
if (true) {
1521
// https://github.com/cockroachdb/cockroach/issues/46915
1622
errors.add("ERROR: at or near \"unknown\": syntax error");
1723
}
1824

25+
if (true) {
26+
// https://github.com/cockroachdb/cockroach/issues/45703
27+
errors.add("github.com/cockroachdb/cockroach/pkg/sql/execinfra/expr.go:78: processExpression()");
28+
}
29+
1930
errors.add("cannot cast negative integer to bit varying with unbounded width");
2031

2132
errors.add("negative value for LIMIT");
@@ -224,12 +235,16 @@ private static void addArrayErrors(Set<String> errors) {
224235
errors.add("unknown signature: max(bit[])");
225236
errors.add("unknown signature: min(float[])");
226237
errors.add("unknown signature: max(float[])");
238+
227239
errors.add("array must be enclosed in { and }"); // when casting a string to an array
240+
errors.add("extra text after closing right brace");
228241
errors.add("unimplemented: nested arrays not supported"); // e.g., casting a string {{1}} to an array
242+
errors.add("malformed array");
229243

230244
errors.add("https://github.com/cockroachdb/cockroach/issues/35707"); // arrays don't support ORDER BY
231245

232246
errors.add("as bytes[], found type: varbit[]");
247+
errors.add("to be of type decimal[], found type float[]");
233248

234249
errors.add("to be of type unknown[]"); // IF with null array
235250
}
@@ -259,6 +274,7 @@ private static void addGroupByErrors(Set<String> errors) {
259274
errors.add("incompatible value type");
260275
errors.add(" ERROR: incompatible IF expressions");
261276
errors.add(" to be of type string");
277+
errors.add("found type string");
262278

263279
errors.add("unknown signature: abs(string)");
264280
errors.add("unknown signature: acos(string)");

src/sqlancer/cockroachdb/CockroachDBOptions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,8 @@ public TestOracle create(CockroachDBGlobalState globalState) throws SQLException
6363

6464
}
6565

66+
@Parameter(names = {
67+
"--test_hash_indexes" }, description = "Test the USING HASH WITH BUCKET_COUNT=n_buckets option in CREATE INDEX")
68+
public boolean testHashIndexes = true;
69+
6670
}

src/sqlancer/cockroachdb/CockroachDBProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ public void generateAndTestDatabase(CockroachDBGlobalState globalState) throws S
134134
manager.execute(
135135
new QueryAdapter("SET CLUSTER SETTING diagnostics.reporting.send_crash_reports = false;"));
136136
manager.execute(new QueryAdapter("SET experimental_enable_temp_tables = 'on'"));
137+
if (globalState.getCockroachdbOptions().testHashIndexes) {
138+
manager.execute(new QueryAdapter("set experimental_enable_hash_sharded_indexes='on';"));
139+
}
137140

138141
for (int i = 0; i < Randomly.fromOptions(1, 2, 3); i++) {
139142
boolean success = false;

src/sqlancer/cockroachdb/ast/CockroachDBFunction.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public enum CockroachDBFunction {
3333
// }
3434
// },
3535

36+
// ARRAY_CAT(CockroachDBDataType.ARRAY, CockroachDBDataType.ARRAY, CockroachDBDataType.ARRAY),
37+
38+
3639
IF(null) {
3740
@Override
3841
public boolean isCompatibleWithReturnType(CockroachDBCompositeDataType returnType) {

src/sqlancer/cockroachdb/gen/CockroachDBCreateStatisticsGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static Query create(CockroachDBGlobalState globalState) {
2121
sb.append(" FROM ");
2222
sb.append(randomTable.getName());
2323

24-
Query q = new QueryAdapter(sb.toString(), Arrays.asList("current transaction is aborted, commands ignored until end of transaction block"));
24+
Query q = new QueryAdapter(sb.toString(), Arrays.asList("current transaction is aborted, commands ignored until end of transaction block", "ERROR: unable to encode table key: *tree.DArray" /* https://github.com/cockroachdb/cockroach/issues/46964 */));
2525
return q;
2626
}
2727

src/sqlancer/cockroachdb/gen/CockroachDBIndexGenerator.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import sqlancer.cockroachdb.CockroachDBSchema.CockroachDBColumn;
1212
import sqlancer.cockroachdb.CockroachDBSchema.CockroachDBTable;
1313

14+
15+
// https://www.cockroachlabs.com/docs/stable/create-index.html
1416
public class CockroachDBIndexGenerator {
1517

1618
public static Query create(CockroachDBGlobalState s) {
@@ -29,8 +31,16 @@ public static Query create(CockroachDBGlobalState s) {
2931
sb.append(table.getName());
3032
List<CockroachDBColumn> columns = table.getRandomNonEmptyColumnSubset();
3133
addColumns(sb, columns, true);
34+
if (s.getCockroachdbOptions().testHashIndexes && Randomly.getBoolean()) {
35+
sb.append(" USING HASH WITH BUCKET_COUNT=");
36+
sb.append(Math.min(1, Randomly.getNotCachedInteger(1, Integer.MAX_VALUE)));
37+
errors.add("null value in column");
38+
errors.add("cannot create a sharded index on a computed column");
39+
}
3240
if (Randomly.getBoolean()) {
33-
sb.append(" STORING ");
41+
sb.append(" ");
42+
sb.append(Randomly.fromOptions("STORING", "COVERING"));
43+
sb.append(" ");
3444
addColumns(sb, table.getRandomNonEmptyColumnSubset(), false);
3545
}
3646

0 commit comments

Comments
 (0)