You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ty...@apache.org on 2015/06/26 21:44:45 UTC

cassandra git commit: Fix suboptimal 2i selection when clustering col is indexed

Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.0 5aaa5cad6 -> f2db756ab


Fix suboptimal 2i selection when clustering col is indexed

Patch by Benjamin Lerer; reviewed by Tyler Hobbs for CASSANDRA-9631


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/f2db756a
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/f2db756a
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/f2db756a

Branch: refs/heads/cassandra-2.0
Commit: f2db756abd135cc6ca4cf657d29fb2601764d50f
Parents: 5aaa5ca
Author: blerer <be...@datastax.com>
Authored: Fri Jun 26 14:40:37 2015 -0500
Committer: Tyler Hobbs <ty...@gmail.com>
Committed: Fri Jun 26 14:40:37 2015 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 +
 .../cql3/statements/SelectStatement.java        |  2 +-
 .../cassandra/cql3/MultiColumnRelationTest.java | 69 +++++++++++++++++---
 .../cql3/SingleColumnRelationTest.java          | 18 ++++-
 4 files changed, 81 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f2db756a/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 68a9bf4..32f0873 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -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)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f2db756a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
index 1c19760..341ce81 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -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);
             }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f2db756a/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java b/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
index 30b7f0f..65ff3e7 100644
--- a/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/MultiColumnRelationTest.java
@@ -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");
+        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 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), (1, 1)) AND e = 2 ALLOW FILTERING");
+        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 (b) >= (1) AND e = 2 ALLOW FILTERING");
+        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);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f2db756a/test/unit/org/apache/cassandra/cql3/SingleColumnRelationTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/SingleColumnRelationTest.java b/test/unit/org/apache/cassandra/cql3/SingleColumnRelationTest.java
index 34d3bf1..c8c67aa 100644
--- a/test/unit/org/apache/cassandra/cql3/SingleColumnRelationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/SingleColumnRelationTest.java
@@ -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);