Repository: phoenix
Updated Branches:
  refs/heads/4.8-HBase-1.1 0c878fa01 -> e5eda96b3


PHOENIX-3439 Query using an RVC based on the base table PK is incorrectly using 
an index and doing a full scan instead of a point query


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

Branch: refs/heads/4.8-HBase-1.1
Commit: 7246898826b3fc2fa8774635368615560c4d41c9
Parents: 0c878fa
Author: James Taylor <jamestay...@apache.org>
Authored: Thu Nov 3 16:45:22 2016 -0700
Committer: James Taylor <jamestay...@apache.org>
Committed: Fri Nov 4 09:25:33 2016 -0700

----------------------------------------------------------------------
 .../main/java/org/apache/phoenix/compile/ScanRanges.java  | 10 +++++++++-
 .../org/apache/phoenix/compile/QueryOptimizerTest.java    | 10 ++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/72468988/phoenix-core/src/main/java/org/apache/phoenix/compile/ScanRanges.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/ScanRanges.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/ScanRanges.java
index 95eee60..19a4692 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/ScanRanges.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/ScanRanges.java
@@ -567,9 +567,17 @@ public class ScanRanges {
     }
 
     public int getBoundPkColumnCount() {
-        return this.useSkipScanFilter ? ScanUtil.getRowKeyPosition(slotSpan, 
ranges.size()) : getBoundPkSpan(ranges, slotSpan);
+        return this.useSkipScanFilter ? ScanUtil.getRowKeyPosition(slotSpan, 
ranges.size()) : Math.max(getBoundPkSpan(ranges, slotSpan), 
getBoundMinMaxSlotCount());
     }
 
+    public int getBoundMinMaxSlotCount() {
+        if (minMaxRange == KeyRange.EMPTY_RANGE || minMaxRange == 
KeyRange.EVERYTHING_RANGE) {
+            return 0;
+        }
+        // The minMaxRange is always a single key
+        return 1 + slotSpan[0];
+    }
+    
     public int getBoundSlotCount() {
         int count = 0;
         boolean hasUnbound = false;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/72468988/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 5f452f1..c50a932 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
@@ -637,6 +637,16 @@ public class QueryOptimizerTest extends 
BaseConnectionlessQueryTest {
         assertEquals("IDX", 
plan.getTableRef().getTable().getTableName().getString());
     }
 
+    @Test
+    public void testTableUsedWithQueryMore() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        conn.createStatement().execute("CREATE TABLE t (k1 CHAR(3) NOT NULL, 
k2 CHAR(15) NOT NULL, k3 DATE NOT NULL, k4 CHAR(15) NOT NULL, CONSTRAINT pk 
PRIMARY KEY (k1,k2,k3,k4))");
+        conn.createStatement().execute("CREATE INDEX idx ON t(k1,k3,k2,k4)");
+        PhoenixStatement stmt = 
conn.createStatement().unwrap(PhoenixStatement.class);
+        QueryPlan plan = stmt.optimizeQuery("SELECT * FROM t WHERE 
(k1,k2,k3,k4) > ('001','001xx000003DHml',to_date('2015-10-21 
09:50:55.0'),'017xx0000022FuI')");
+        assertEquals("T", 
plan.getTableRef().getTable().getTableName().getString());
+    }
+
     private void assertPlanDetails(PreparedStatement stmt, String 
expectedPkCols, String expectedPkColsDataTypes, boolean expectedHasOrderBy, int 
expectedLimit) throws SQLException {
         Connection conn = stmt.getConnection();
         QueryPlan plan = PhoenixRuntime.getOptimizedQueryPlan(stmt);

Reply via email to