You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by la...@apache.org on 2019/01/28 02:46:26 UTC
[phoenix] branch master updated: PHOENIX-5109;
2nd addendum, test fixes.
This is an automated email from the ASF dual-hosted git repository.
larsh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/master by this push:
new 573ec9f PHOENIX-5109; 2nd addendum, test fixes.
573ec9f is described below
commit 573ec9f73a86d236a6e69a2bac23f177a29f3c44
Author: Lars Hofhansl <la...@apache.org>
AuthorDate: Sun Jan 27 18:46:44 2019 -0800
PHOENIX-5109; 2nd addendum, test fixes.
---
.../apache/phoenix/end2end/index/LocalIndexIT.java | 29 ++++++++++++++++++++++
.../phoenix/end2end/index/MutableIndexIT.java | 7 +++---
.../apache/phoenix/optimize/QueryOptimizer.java | 9 +++++--
3 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
index c43ebfb..574322e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalIndexIT.java
@@ -158,6 +158,35 @@ public class LocalIndexIT extends BaseLocalIndexIT {
}
@Test
+ public void testUseUncoveredLocalIndexWithSplitPrefix() throws Exception {
+ String tableName = schemaName + "." + generateUniqueName();
+ String indexName = "IDX_" + generateUniqueName();
+ TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped);
+ String indexPhysicalTableName = physicalTableName.getNameAsString();
+
+ Connection conn = getConnection();
+ conn.setAutoCommit(true);
+ if (isNamespaceMapped) {
+ conn.createStatement().execute("CREATE SCHEMA IF NOT EXISTS " + schemaName);
+ }
+
+ conn.createStatement().execute("CREATE TABLE " + tableName
+ + " (pk1 INTEGER NOT NULL, pk2 INTEGER NOT NULL, pk3 INTEGER NOT NULL, v1 FLOAT, v2 FLOAT, V3 INTEGER CONSTRAINT pk PRIMARY KEY(pk1,pk2,pk3)) SALT_BUCKETS=16");
+// + " (pk1 INTEGER NOT NULL, pk2 INTEGER NOT NULL, pk3 INTEGER NOT NULL, v1 FLOAT, v2 FLOAT, V3 INTEGER CONSTRAINT pk PRIMARY KEY(pk1,pk2,pk3))");
+ conn.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(pk1,pk3)");
+
+ // 1. Still use the index
+ ResultSet rs = conn.createStatement().executeQuery("EXPLAIN SELECT pk1, pk2, pk3, v1 FROM " + tableName + " WHERE pk1 = 2 AND pk3 = 3");
+ assertEquals(
+ "CLIENT PARALLEL 16-WAY RANGE SCAN OVER "
+ + indexPhysicalTableName + " [1,2,3]\n"
+ + " SERVER FILTER BY FIRST KEY ONLY\n"
+ + "CLIENT MERGE SORT",
+ QueryUtil.getExplainPlan(rs));
+ rs.close();
+ }
+
+ @Test
public void testUseUncoveredLocalIndex() throws Exception {
String tableName = schemaName + "." + generateUniqueName();
String indexName = "IDX_" + generateUniqueName();
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
index 9ab168c..2fefc02 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
@@ -197,11 +197,10 @@ public class MutableIndexIT extends ParallelStatsDisabledIT {
assertEquals(5L, rs.getLong(3));
assertFalse(rs.next());
if(localIndex) {
- query = "SELECT b.* from " + fullTableName + " where int_col1 = 4";
+ query = "SELECT b.* from " + fullTableName + " where int_col1 = 4 AND char_col1 = 'chara'";
rs = conn.createStatement().executeQuery("EXPLAIN " + query);
- // this should *not* use an index, since neither int_col1, nor all of the b.* columns are in the index
- assertEquals("CLIENT PARALLEL 1-WAY FULL SCAN OVER " + fullTableName +"\n" +
- " SERVER FILTER BY A.INT_COL1 = 4", QueryUtil.getExplainPlan(rs));
+ assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + fullTableName +" [1,'chara',4]\n" +
+ "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals("varchar_b", rs.getString(1));
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java b/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
index 0f64994..4e5ace8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
@@ -513,8 +513,13 @@ public class QueryOptimizer {
// For shared indexes (i.e. indexes on views and local indexes),
// a) add back any view constants as these won't be in the index, and
// b) ignore the viewIndexId which will be part of the row key columns.
- int c = (boundCount2 + (table2.getViewIndexId() == null ? 0 : (boundRanges - 1))) -
- (boundCount1 + (table1.getViewIndexId() == null ? 0 : (boundRanges - 1)));
+ boundCount1 += table1.getViewIndexId() == null ? 0 : (boundRanges - 1);
+ boundCount2 += table2.getViewIndexId() == null ? 0 : (boundRanges - 1);
+ // Adjust for salting. Salting adds a bound range for each salt bucket.
+ // (but the sum of buckets cover the entire table)
+ boundCount1 -= table1.getBucketNum() == null ? 0 : 1;
+ boundCount2 -= table2.getBucketNum() == null ? 0 : 1;
+ int c = boundCount2 - boundCount1;
if (c != 0) return c;
if (plan1.getGroupBy() != null && plan2.getGroupBy() != null) {
if (plan1.getGroupBy().isOrderPreserving() != plan2.getGroupBy().isOrderPreserving()) {