Repository: phoenix Updated Branches: refs/heads/master 3acedb726 -> 13742ae1f
PHOENIX-1298 Queries on fixed width type columns that have an index declared on them don't use that index (Samarth Jain) Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/13742ae1 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/13742ae1 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/13742ae1 Branch: refs/heads/master Commit: 13742ae1f6a6d90774285d6cf51eb5a934688d50 Parents: 3acedb7 Author: James Taylor <jtay...@salesforce.com> Authored: Fri Sep 26 21:18:42 2014 -0700 Committer: James Taylor <jtay...@salesforce.com> Committed: Fri Sep 26 21:19:41 2014 -0700 ---------------------------------------------------------------------- .../java/org/apache/phoenix/compile/WhereOptimizer.java | 6 +----- .../org/apache/phoenix/compile/QueryOptimizerTest.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/13742ae1/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java index 2b529cb..22594c9 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java @@ -476,11 +476,7 @@ public class WhereOptimizer { for (int i = 0; i < childSlots.size(); i++) { KeySlots slots = childSlots.get(i); KeySlot keySlot = slots.iterator().next(); - List<Expression> childExtractNodes = keySlot.getKeyPart().getExtractNodes(); - // If columns are not in PK order, then stop iteration - if (childExtractNodes.size() != 1 || childExtractNodes.get(0) != rvc.getChildren().get(i)) { - break; - } + // Continue while we have consecutive pk columns if (position == -1) { position = initialPosition = keySlot.getPKPosition(); } else if (keySlot.getPKPosition() != position) { http://git-wip-us.apache.org/repos/asf/phoenix/blob/13742ae1/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java index 3a92d73..45a61a7 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java @@ -41,6 +41,17 @@ public class QueryOptimizerTest extends BaseConnectionlessQueryTest { } @Test + public void testRVCUsingPkColsReturnedByPlanShouldUseIndex() throws Exception { + Connection conn = DriverManager.getConnection(getUrl()); + conn.createStatement().execute("CREATE TABLE T (k VARCHAR NOT NULL PRIMARY KEY, v1 CHAR(15), v2 VARCHAR)"); + conn.createStatement().execute("CREATE INDEX IDX ON T(v1, v2)"); + PhoenixStatement stmt = conn.createStatement().unwrap(PhoenixStatement.class); + String query = "select * from t where (v1, v2, k) > ('1', '2', '3')"; + QueryPlan plan = stmt.optimizeQuery(query); + assertEquals("IDX", plan.getTableRef().getTable().getTableName().getString()); + } + + @Test public void testOrderByOptimizedOut() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); conn.createStatement().execute("CREATE TABLE foo (k VARCHAR NOT NULL PRIMARY KEY, v VARCHAR) IMMUTABLE_ROWS=true");