Fix suboptimal 2i selection when clustering col is indexed

Patch by Benjamin Lerer; reviewed by Tyler Hobbs for CASSANDRA-9631
This commit is contained in:
blerer 2015-06-26 14:40:37 -05:00 committed by Tyler Hobbs
parent 5aaa5cad6e
commit f2db756abd
4 changed files with 84 additions and 13 deletions

View File

@ -1,4 +1,6 @@
2.0.17
* Fix suboptimal secondary index selection when restricted
clustering column is also indexed (CASSANDRA-9631)
* (cqlsh) Add min_threshold to DTCS option autocomplete (CASSANDRA-9385)
* Fix error message when attempting to create an index on a column
in a COMPACT STORAGE table with clustering columns (CASSANDRA-9527)

View File

@ -1606,7 +1606,7 @@ public class SelectStatement implements CQLStatement, MeasurableForPreparedCache
Boolean indexed = stmt.restrictedNames.get(clusteringColumn);
if (indexed == null)
break;
if (!indexed)
if (!indexed || !stmt.usesSecondaryIndexing)
stmt.restrictedNames.remove(clusteringColumn);
}

View File

@ -1368,38 +1368,68 @@ public class MultiColumnRelationTest
checkRow(1, results, 0, 1, 1, 0, 1);
checkRow(2, results, 0, 1, 1, 1, 2);
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE (b, c) = (1, 1) ALLOW FILTERING");
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE (b, c) = (1, 1) ALLOW FILTERING");
assertEquals(2, results.size());
checkRow(0, results, 0, 1, 1, 0, 1);
checkRow(1, results, 0, 1, 1, 1, 2);
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE (b, c) = (1, 1) AND e = 2 ALLOW FILTERING");
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE a = 0 AND (b, c) = (1, 1) AND e = 2");
assertEquals(1, results.size());
checkRow(0, results, 0, 1, 1, 1, 2);
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE (b) IN ((1)) AND e = 2 ALLOW FILTERING");
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE (b, c) = (1, 1) AND e = 2 ALLOW FILTERING");
assertEquals(1, results.size());
checkRow(0, results, 0, 1, 1, 1, 2);
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE (b) IN ((0), (1)) AND e = 2 ALLOW FILTERING");
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE a = 0 AND (b) IN ((1)) AND e = 2");
assertEquals(1, results.size());
checkRow(0, results, 0, 1, 1, 1, 2);
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE (b) IN ((1)) AND e = 2 ALLOW FILTERING");
assertEquals(1, results.size());
checkRow(0, results, 0, 1, 1, 1, 2);
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE a = 0 AND (b) IN ((0), (1)) AND e = 2");
assertEquals(2, results.size());
checkRow(0, results, 0, 0, 1, 1, 2);
checkRow(1, results, 0, 1, 1, 1, 2);
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE (b, c) IN ((0, 1)) AND e = 2 ALLOW FILTERING");
assertEquals(1, results.size());
checkRow(0, results, 0, 0, 1, 1, 2);
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE (b, c) IN ((0, 1), (1, 1)) AND e = 2 ALLOW FILTERING");
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE (b) IN ((0), (1)) AND e = 2 ALLOW FILTERING");
assertEquals(2, results.size());
checkRow(0, results, 0, 0, 1, 1, 2);
checkRow(1, results, 0, 1, 1, 1, 2);
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE (b) >= (1) AND e = 2 ALLOW FILTERING");
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE a = 0 AND (b, c) IN ((0, 1)) AND e = 2");
assertEquals(1, results.size());
checkRow(0, results, 0, 0, 1, 1, 2);
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE (b, c) IN ((0, 1)) AND e = 2 ALLOW FILTERING");
assertEquals(1, results.size());
checkRow(0, results, 0, 0, 1, 1, 2);
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE a = 0 AND (b, c) IN ((0, 1), (1, 1)) AND e = 2");
assertEquals(2, results.size());
checkRow(0, results, 0, 0, 1, 1, 2);
checkRow(1, results, 0, 1, 1, 1, 2);
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE (b, c) IN ((0, 1), (1, 1)) AND e = 2 ALLOW FILTERING");
assertEquals(2, results.size());
checkRow(0, results, 0, 0, 1, 1, 2);
checkRow(1, results, 0, 1, 1, 1, 2);
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE a = 0 AND (b) >= (1) AND e = 2");
assertEquals(1, results.size());
checkRow(0, results, 0, 1, 1, 1, 2);
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE (b, c) >= (1, 1) AND e = 2 ALLOW FILTERING");
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE (b) >= (1) AND e = 2 ALLOW FILTERING");
assertEquals(1, results.size());
checkRow(0, results, 0, 1, 1, 1, 2);
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE a = 0 AND (b, c) >= (1, 1) AND e = 2");
assertEquals(1, results.size());
checkRow(0, results, 0, 1, 1, 1, 2);
results = execute("SELECT * FROM %s.multiple_clustering_with_indices WHERE (b, c) >= (1, 1) AND e = 2 ALLOW FILTERING");
assertEquals(1, results.size());
checkRow(0, results, 0, 1, 1, 1, 2);
}
@ -1428,24 +1458,47 @@ public class MultiColumnRelationTest
checkRow(0, results, 0, 0, 1, 1, 0, 4);
checkRow(1, results, 0, 0, 1, 1, 1, 5);
results = execute("SELECT * FROM %s.partition_with_indices WHERE a = 0 AND b = 0 AND (c) IN ((1)) AND f = 5");
assertEquals(1, results.size());
checkRow(0, results, 0, 0, 1, 1, 1, 5);
results = execute("SELECT * FROM %s.partition_with_indices WHERE a = 0 AND (c) IN ((1)) AND f = 5 ALLOW FILTERING");
assertEquals(1, results.size());
checkRow(0, results, 0, 0, 1, 1, 1, 5);
results = execute("SELECT * FROM %s.partition_with_indices WHERE a = 0 AND b = 0 AND (c) IN ((1), (2)) AND f = 5");
assertEquals(2, results.size());
checkRow(0, results, 0, 0, 1, 1, 1, 5);
checkRow(1, results, 0, 0, 2, 0, 0, 5);
results = execute("SELECT * FROM %s.partition_with_indices WHERE a = 0 AND (c) IN ((1), (2)) AND f = 5 ALLOW FILTERING");
assertEquals(2, results.size());
checkRow(0, results, 0, 0, 1, 1, 1, 5);
checkRow(1, results, 0, 0, 2, 0, 0, 5);
results = execute("SELECT * FROM %s.partition_with_indices WHERE a = 0 AND b = 0 AND (c, d) IN ((1, 0)) AND f = 3");
assertEquals(1, results.size());
checkRow(0, results, 0, 0, 1, 0, 0, 3);
results = execute("SELECT * FROM %s.partition_with_indices WHERE a = 0 AND (c, d) IN ((1, 0)) AND f = 3 ALLOW FILTERING");
assertEquals(1, results.size());
checkRow(0, results, 0, 0, 1, 0, 0, 3);
results = execute("SELECT * FROM %s.partition_with_indices WHERE a = 0 AND b = 0 AND (c) >= (1) AND f = 5");
assertEquals(2, results.size());
checkRow(0, results, 0, 0, 1, 1, 1, 5);
checkRow(1, results, 0, 0, 2, 0, 0, 5);
results = execute("SELECT * FROM %s.partition_with_indices WHERE a = 0 AND (c) >= (1) AND f = 5 ALLOW FILTERING");
assertEquals(2, results.size());
checkRow(0, results, 0, 0, 1, 1, 1, 5);
checkRow(1, results, 0, 0, 2, 0, 0, 5);
results = execute("SELECT * FROM %s.partition_with_indices WHERE a = 0 AND b = 0 AND (c, d) >= (1, 1) AND f = 5");
assertEquals(2, results.size());
checkRow(0, results, 0, 0, 1, 1, 1, 5);
checkRow(1, results, 0, 0, 2, 0, 0, 5);
results = execute("SELECT * FROM %s.partition_with_indices WHERE a = 0 AND (c, d) >= (1, 1) AND f = 5 ALLOW FILTERING");
assertEquals(2, results.size());
checkRow(0, results, 0, 0, 1, 1, 1, 5);

View File

@ -96,17 +96,33 @@ public class SingleColumnRelationTest
execute("INSERT INTO %s.partition_with_indices (a, b, c, d, e, f) VALUES (0, 0, 2, 0, 0, 5)");
UntypedResultSet results = execute("SELECT * FROM %s.partition_with_indices WHERE a = 0 AND c = 1 ALLOW FILTERING");
UntypedResultSet results = execute("SELECT * FROM %s.partition_with_indices WHERE a = 0 AND b = 0 AND c = 1");
assertEquals(3, results.size());
checkRow(0, results, 0, 0, 1, 0, 0, 3);
checkRow(1, results, 0, 0, 1, 1, 0, 4);
checkRow(2, results, 0, 0, 1, 1, 1, 5);
results = execute("SELECT * FROM %s.partition_with_indices WHERE a = 0 AND c = 1 ALLOW FILTERING");
assertEquals(3, results.size());
checkRow(0, results, 0, 0, 1, 0, 0, 3);
checkRow(1, results, 0, 0, 1, 1, 0, 4);
checkRow(2, results, 0, 0, 1, 1, 1, 5);
results = execute("SELECT * FROM %s.partition_with_indices WHERE a = 0 AND b = 0 AND c = 1 AND d = 1");
assertEquals(2, results.size());
checkRow(0, results, 0, 0, 1, 1, 0, 4);
checkRow(1, results, 0, 0, 1, 1, 1, 5);
results = execute("SELECT * FROM %s.partition_with_indices WHERE a = 0 AND c = 1 AND d = 1 ALLOW FILTERING");
assertEquals(2, results.size());
checkRow(0, results, 0, 0, 1, 1, 0, 4);
checkRow(1, results, 0, 0, 1, 1, 1, 5);
results = execute("SELECT * FROM %s.partition_with_indices WHERE a = 0 AND b = 0 AND c >= 1 AND f = 5");
assertEquals(2, results.size());
checkRow(0, results, 0, 0, 1, 1, 1, 5);
checkRow(1, results, 0, 0, 2, 0, 0, 5);
results = execute("SELECT * FROM %s.partition_with_indices WHERE a = 0 AND c >= 1 AND f = 5 ALLOW FILTERING");
assertEquals(2, results.size());
checkRow(0, results, 0, 0, 1, 1, 1, 5);