This is an automated email from the ASF dual-hosted git repository. stoty pushed a commit to branch 5.1 in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/5.1 by this push: new 2d86b6f1ad PHOENIX-6986 Add property to disable server merges for hinted uncovered indexes 2d86b6f1ad is described below commit 2d86b6f1ad75ed7028a3a42ad4ab9a11979c6e1d Author: Abhishek Kothalikar <kabhis...@cloudera.com> AuthorDate: Fri Jul 14 12:39:50 2023 +0530 PHOENIX-6986 Add property to disable server merges for hinted uncovered indexes --- .../apache/phoenix/optimize/QueryOptimizer.java | 7 +++- .../org/apache/phoenix/query/QueryServices.java | 5 +++ .../apache/phoenix/query/QueryServicesOptions.java | 7 +++- .../apache/phoenix/compile/QueryCompilerTest.java | 38 ++++++++++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) 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 68d70e0cb3..0b2028ed56 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 @@ -338,10 +338,15 @@ public class QueryOptimizer { Map<TableRef, QueryPlan> dataPlans = Collections.singletonMap(indexTableRef, dataPlan); PTable indexTable = indexTableRef.getTable(); PIndexState indexState = indexTable.getIndexState(); + boolean isServerMergeForUncoveredIndexEnabled = statement.getConnection() + .getQueryServices().getProps().getBoolean( + QueryServices.SERVER_MERGE_FOR_UNCOVERED_INDEX, + QueryServicesOptions.DEFAULT_SERVER_MERGE_FOR_UNCOVERED_INDEX); if (indexState == PIndexState.ACTIVE || indexState == PIndexState.PENDING_ACTIVE || (indexState == PIndexState.PENDING_DISABLE && isUnderPendingDisableThreshold(indexTableRef.getCurrentTime(), indexTable.getIndexDisableTimestamp()))) { try { - if (select.getHint().hasHint(HintNode.Hint.NO_INDEX_SERVER_MERGE)) { + if (!isServerMergeForUncoveredIndexEnabled + || select.getHint().hasHint(HintNode.Hint.NO_INDEX_SERVER_MERGE)) { String schemaNameStr = index.getSchemaName() == null ? null : index.getSchemaName().getString(); String tableNameStr = index.getTableName() == null ? null diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java index d875ac223a..59c5c37530 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java @@ -392,6 +392,11 @@ public interface QueryServices extends SQLCloseable { String MAX_REGION_LOCATIONS_SIZE_EXPLAIN_PLAN = "phoenix.max.region.locations.size.explain.plan"; + /** + * Parameter to disable the server merges for hinted uncovered indexes + */ + String SERVER_MERGE_FOR_UNCOVERED_INDEX = "phoenix.query.global.server.merge.enable"; + /** * Get executor service used for parallel scans */ diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java index 7d49c760e1..f91425e825 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java @@ -78,6 +78,7 @@ import static org.apache.phoenix.query.QueryServices.SCAN_CACHE_SIZE_ATTRIB; import static org.apache.phoenix.query.QueryServices.SCAN_RESULT_CHUNK_SIZE; import static org.apache.phoenix.query.QueryServices.SEQUENCE_CACHE_SIZE_ATTRIB; import static org.apache.phoenix.query.QueryServices.SEQUENCE_SALT_BUCKETS_ATTRIB; +import static org.apache.phoenix.query.QueryServices.SERVER_MERGE_FOR_UNCOVERED_INDEX; import static org.apache.phoenix.query.QueryServices.SERVER_SPOOL_THRESHOLD_BYTES_ATTRIB; import static org.apache.phoenix.query.QueryServices.SKIP_SYSTEM_TABLES_EXISTENCE_CHECK; import static org.apache.phoenix.query.QueryServices.SPOOL_DIRECTORY; @@ -382,6 +383,7 @@ public class QueryServicesOptions { public static final boolean DEFAULT_SKIP_SYSTEM_TABLES_EXISTENCE_CHECK = false; public static final boolean DEFAULT_APPLY_TIME_ZONE_DISPLACMENT = false; public static final int DEFAULT_MAX_REGION_LOCATIONS_SIZE_EXPLAIN_PLAN = 5; + public static final boolean DEFAULT_SERVER_MERGE_FOR_UNCOVERED_INDEX = true; private final Configuration config; @@ -472,7 +474,10 @@ public class QueryServicesOptions { .setIfUnset(SKIP_SYSTEM_TABLES_EXISTENCE_CHECK, DEFAULT_SKIP_SYSTEM_TABLES_EXISTENCE_CHECK) .setIfUnset(MAX_REGION_LOCATIONS_SIZE_EXPLAIN_PLAN, - DEFAULT_MAX_REGION_LOCATIONS_SIZE_EXPLAIN_PLAN); + DEFAULT_MAX_REGION_LOCATIONS_SIZE_EXPLAIN_PLAN) + .setIfUnset(SERVER_MERGE_FOR_UNCOVERED_INDEX, + DEFAULT_SERVER_MERGE_FOR_UNCOVERED_INDEX); + // HBase sets this to 1, so we reset it to something more appropriate. // Hopefully HBase will change this, because we can't know if a user set // it to 1, so we'll change it. diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java index 29dc819270..8f5f7e3304 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java @@ -7058,4 +7058,42 @@ public class QueryCompilerTest extends BaseConnectionlessQueryTest { } } + @Test + public void testUncoveredPhoenix6986() throws Exception { + Properties props = new Properties(); + props.setProperty(QueryServices.SERVER_MERGE_FOR_UNCOVERED_INDEX, + Boolean.toString(false)); + try (Connection conn = DriverManager.getConnection(getUrl(), props); + Statement stmt = conn.createStatement()) { + stmt.execute("CREATE TABLE TAB_PHOENIX_6986 (\n" + "K1 CHAR(6) NOT NULL,\n" + + "K2 VARCHAR(22) NOT NULL,\n" + + "K3 CHAR(2) NOT NULL,\n" + + "K4 VARCHAR(36) NOT NULL,\n" + + "V1 TIMESTAMP,\n" + + "V2 TIMESTAMP,\n" + + "CONSTRAINT PK_PHOENIX_6986 PRIMARY KEY (K1,K2,K3,K4))"); + + stmt.execute("CREATE INDEX IDX_PHOENIX_6986 ON TAB_PHOENIX_6986(K2, K1, K3, K4)"); + String query = + "SELECT /*+ INDEX(TAB_PHOENIX_6986 IDX_PHOENIX_6986) */ * " + + "FROM TAB_PHOENIX_6986 " + + "WHERE K2 = 'XXX' AND " + + "V2 >= TIMESTAMP '2023-05-31 23:59:59.000' AND " + + "V1 <= TIMESTAMP '2023-04-01 00:00:00.000' " + + "ORDER BY V2 asc"; + ResultSet rs = stmt.executeQuery("EXPLAIN " + query); + String explainPlan = QueryUtil.getExplainPlan(rs); + assertEquals("CLIENT PARALLEL 1-WAY FULL SCAN OVER TAB_PHOENIX_6986\n" + + " SERVER FILTER BY (V2 >= TIMESTAMP '2023-05-31 23:59:59.000'" + + " AND V1 <= TIMESTAMP '2023-04-01 00:00:00.000')\n" + + " SERVER SORTED BY [TAB_PHOENIX_6986.V2]\n" + + "CLIENT MERGE SORT\n" + + " SKIP-SCAN-JOIN TABLE 0\n" + + " CLIENT PARALLEL 1-WAY RANGE SCAN OVER IDX_PHOENIX_6986 ['XXX']\n" + + " SERVER FILTER BY FIRST KEY ONLY\n" + + " DYNAMIC SERVER FILTER BY (\"TAB_PHOENIX_6986.K1\", \"TAB_PHOENIX_6986.K2\", \"TAB_PHOENIX_6986.K3\", \"TAB_PHOENIX_6986.K4\")" + + " IN (($2.$4, $2.$5, $2.$6, $2.$7))", + explainPlan); + } + } }