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 87ba634412 PHOENIX-6969 Projection bug in hinted uncovered index query 
with order by
87ba634412 is described below

commit 87ba6344126befe0b68a37ee2676c6ec636282c1
Author: Istvan Toth <st...@apache.org>
AuthorDate: Fri Jun 2 12:22:25 2023 +0200

    PHOENIX-6969 Projection bug in hinted uncovered index query with order by
---
 .../apache/phoenix/schema/IndexDataColumnRef.java  |  8 ++-----
 .../apache/phoenix/compile/QueryCompilerTest.java  | 27 ++++++++++++++++++++++
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/schema/IndexDataColumnRef.java 
b/phoenix-core/src/main/java/org/apache/phoenix/schema/IndexDataColumnRef.java
index 3e55b937e1..6b8c0e2952 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/schema/IndexDataColumnRef.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/schema/IndexDataColumnRef.java
@@ -23,7 +23,6 @@ import java.util.Set;
 import org.apache.phoenix.compile.FromCompiler;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.expression.ColumnExpression;
-import org.apache.phoenix.expression.IsNullExpression;
 import org.apache.phoenix.expression.ProjectedColumnExpression;
 import org.apache.phoenix.parse.ParseNodeFactory;
 import org.apache.phoenix.parse.TableName;
@@ -36,6 +35,7 @@ import org.apache.phoenix.util.IndexUtil;
  */
 public class IndexDataColumnRef extends ColumnRef {
     final private int position;
+    // Despite the final keyword, columns IS mutable, and must not be used for 
equality/hashCode
     final private Set<PColumn> columns;
     private static final ParseNodeFactory FACTORY = new ParseNodeFactory();
 
@@ -76,7 +76,6 @@ public class IndexDataColumnRef extends ColumnRef {
         final int prime = 31;
         int result = super.hashCode();
         result = prime * result + position;
-        result = prime * result + ((columns == null) ? 0 : columns.hashCode());
         return result;
     }
 
@@ -86,9 +85,6 @@ public class IndexDataColumnRef extends ColumnRef {
             return false;
         }
         IndexDataColumnRef that = (IndexDataColumnRef) o;
-        if (position != that.position) {
-            return false;
-        }
-        return columns.equals(that.columns);
+        return position == that.position;
     }
 }
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 1c30618c7e..886f0ddac5 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
@@ -6981,4 +6981,31 @@ public class QueryCompilerTest extends 
BaseConnectionlessQueryTest {
             assertEquals(explainExpected, explainPlan);
         }
     }
+
+    @Test
+    public void testUncoveredPhoenix6969() throws Exception {
+
+        try (Connection conn = DriverManager.getConnection(getUrl());
+                Statement stmt = conn.createStatement()) {
+
+            stmt.execute(
+                "create table dd (k1 integer not null, k2 integer not null, k3 
integer not null,"
+                + " k4 integer not null, v1 integer, v2 integer, v3 integer, 
v4 integer"
+                + " constraint pk primary key (k1,k2,k3,k4))");
+            stmt.execute("create index ii on dd (k4, k1, k2, k3)");
+            String query =
+                    "select /*+ index(dd ii) */ k1, k2, k3, k4, v1, v2, v3, v4 
from dd"
+                    + " where k4=1 and k2=1 order by k1 asc, v1 asc limit  1";
+            ResultSet rs = stmt.executeQuery("EXPLAIN " + query);
+            String explainPlan = QueryUtil.getExplainPlan(rs);
+            //We are more interested in the query compiling than the exact 
result
+            assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER II [1]\n"
+                    + "    SERVER MERGE [0.V1, 0.V2, 0.V3, 0.V4]\n"
+                    + "    SERVER FILTER BY FIRST KEY ONLY AND \"K2\" = 1\n"
+                    + "    SERVER TOP 1 ROW SORTED BY [\"K1\", \"V1\"]\n"
+                    + "CLIENT MERGE SORT\n"
+                    + "CLIENT LIMIT 1", explainPlan);
+        }
+    }
+
 }

Reply via email to