Repository: phoenix
Updated Branches:
  refs/heads/4.0 4edfed646 -> 61fc6a6c0


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/61fc6a6c
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/61fc6a6c
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/61fc6a6c

Branch: refs/heads/4.0
Commit: 61fc6a6c042295efc3819c1af18d7d4c3e502014
Parents: 4edfed6
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:18:42 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/61fc6a6c/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/61fc6a6c/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");

Reply via email to