This is an automated email from the ASF dual-hosted git repository. stoty 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 551aed7f4e PHOENIX-6984 Fix fallback to skip-join-merge for hinted global indexes 551aed7f4e is described below commit 551aed7f4e8dfaf3cb01936056810423dcd00a12 Author: Istvan Toth <st...@apache.org> AuthorDate: Mon Jun 19 18:08:02 2023 +0200 PHOENIX-6984 Fix fallback to skip-join-merge for hinted global indexes --- .../apache/phoenix/optimize/QueryOptimizer.java | 8 ++++-- .../apache/phoenix/compile/QueryCompilerTest.java | 30 ++++++++++++++++++++++ 2 files changed, 36 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 c0a516e053..8f11a1bd1a 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 @@ -340,8 +340,8 @@ public class QueryOptimizer { || (indexState == PIndexState.PENDING_DISABLE && isUnderPendingDisableThreshold(indexTableRef.getCurrentTime(), indexTable.getIndexDisableTimestamp()))) { try { // translate nodes that match expressions that are indexed to the associated column parse node - indexSelect = ParseNodeRewriter.rewrite(indexSelect, new IndexExpressionParseNodeRewriter(index, null, statement.getConnection(), indexSelect.getUdfParseNodes())); - QueryCompiler compiler = new QueryCompiler(statement, indexSelect, resolver, targetColumns, parallelIteratorFactory, dataPlan.getContext().getSequenceManager(), isProjected, true, dataPlans); + SelectStatement rewrittenIndexSelect = ParseNodeRewriter.rewrite(indexSelect, new IndexExpressionParseNodeRewriter(index, null, statement.getConnection(), indexSelect.getUdfParseNodes())); + QueryCompiler compiler = new QueryCompiler(statement, rewrittenIndexSelect, resolver, targetColumns, parallelIteratorFactory, dataPlan.getContext().getSequenceManager(), isProjected, true, dataPlans); QueryPlan plan = compiler.compile(); if (indexTable.getIndexType() == IndexType.UNCOVERED_GLOBAL) { @@ -391,6 +391,10 @@ public class QueryOptimizer { * otherwise we just don't use this index (as opposed to trying to join back from * the index table to the data table. */ + // Reset the state changes from the attempt above + indexTableRef.setHinted(false); + dataPlan.getContext().setUncoveredIndex(false); + SelectStatement dataSelect = (SelectStatement)dataPlan.getStatement(); ParseNode where = dataSelect.getWhere(); if (isHinted && where != null) { 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 886f0ddac5..96f1af9745 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 @@ -7008,4 +7008,34 @@ public class QueryCompilerTest extends BaseConnectionlessQueryTest { } } + @Ignore //The fallback does not happen on 5.2. + @Test + // If/when we add a hint to didable server merges, this can be used for testing that + public void testUncoveredPhoenix6984() throws Exception { + try (Connection conn = DriverManager.getConnection(getUrl()); + Statement stmt = conn.createStatement()) { + stmt.execute("CREATE TABLE D (\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_BILLING_ORDER PRIMARY KEY (K1,K2,K3,K4))"); + + stmt.execute("CREATE INDEX I ON D(K2, K1, K3, K4)"); + String query = + "SELECT /*+ INDEX(D I) */ * " + "FROM D " + "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 D\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 [D.V2]\n" + "CLIENT MERGE SORT\n" + + " SKIP-SCAN-JOIN TABLE 0\n" + + " CLIENT PARALLEL 1-WAY RANGE SCAN OVER I ['XXX']\n" + + " SERVER FILTER BY FIRST KEY ONLY\n" + + " DYNAMIC SERVER FILTER BY (\"D.K1\", \"D.K2\", \"D.K3\", \"D.K4\")" + + " IN (($3.$5, $3.$6, $3.$7, $3.$8))", + explainPlan); + } + } }