phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject [1/2] phoenix git commit: 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
Date Thu, 03 Nov 2016 23:49:49 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.1 15659904b -> 899858771


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

Branch: refs/heads/4.x-HBase-1.1
Commit: 89985877105dc02b359d2e29bad377350a513586
Parents: 16e1379
Author: James Taylor <jamestaylor@apache.org>
Authored: Thu Nov 3 16:45:22 2016 -0700
Committer: James Taylor <jamestaylor@apache.org>
Committed: Thu Nov 3 16:48:53 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/89985877/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/89985877/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 b3a845c..e81d68a 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);


Mime
View raw message