phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tdsi...@apache.org
Subject [18/50] [abbrv] phoenix git commit: PHOENIX-2327 Row value constructors failed on the index, when len(table's pks) > 2 and table's 1st pk is index's last pk (Chunhui Liu, James Taylor)
Date Tue, 10 Nov 2015 01:18:33 GMT
PHOENIX-2327 Row value constructors failed on the index, when len(table's pks) > 2 and table's
1st pk is index's last pk (Chunhui Liu, James Taylor)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/c0fb0503
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/c0fb0503
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/c0fb0503

Branch: refs/heads/txn
Commit: c0fb05034a1a0131afc8f67c03655d5f0f163dba
Parents: 416c860
Author: James Taylor <jtaylor@salesforce.com>
Authored: Sat Oct 17 15:25:00 2015 -0700
Committer: James Taylor <jtaylor@salesforce.com>
Committed: Sat Oct 17 15:25:00 2015 -0700

----------------------------------------------------------------------
 .../phoenix/end2end/RowValueConstructorIT.java  | 61 ++++++++++++++++++++
 .../apache/phoenix/compile/WhereOptimizer.java  |  7 +--
 2 files changed, 64 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/c0fb0503/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowValueConstructorIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowValueConstructorIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowValueConstructorIT.java
index 749da5d..fef105c 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowValueConstructorIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowValueConstructorIT.java
@@ -1591,4 +1591,65 @@ public class RowValueConstructorIT extends BaseClientManagedTimeIT
{
         
         assertFalse(rs.next());
     }
+
+	/**
+	 * PHOENIX-2327
+	 * 
+	 * Table's pks are (pk1, pk2, ... , pkn), n >= 3
+	 * Index's pks are (pk2, ... , pkn, pk1), n >= 3
+	 * RVC is (pk2, ... , pkn, pk1), n >= 3
+	 * 
+	 * Expalin select * from t where (pk2, ... , pkn, pk1) > ('201', ..., 'n01', '101') and
pk[2-n] = '[2-n]03'
+	 * 
+	 * You will Get "DEGENERATE SCAN OVER TABLE_NAME"
+	 * 
+	 * @throws java.lang.Exception
+	 */
+	@Test
+	public void testRVCLastPkIsTable1stPkIndex() throws Exception {
+		Connection conn = nextConnection(getUrl());
+		String tableName = "t";
+		String ddl = "CREATE TABLE " + tableName 
+				+ " (k1 VARCHAR, k2 VARCHAR, k3 VARCHAR, k4 VARCHAR,"
+				+ " CONSTRAINT pk PRIMARY KEY (k1,k2,k3,k4))";
+		conn.createStatement().execute(ddl);
+
+		conn = nextConnection(getUrl());
+		ddl = "CREATE INDEX  " + tableName + "_idx"
+				+ " ON " + tableName + " (k2, k3, k4, k1)";
+		conn.createStatement().execute(ddl);
+		
+		conn = nextConnection(getUrl());
+		String upsert = "UPSERT INTO " + tableName + " VALUES(?, ?, ?, ?)";
+		PreparedStatement stmt = conn.prepareStatement(upsert);
+		for (int i = 0; i < 5; i++) {
+			stmt.setString(1, "10" + i);
+			stmt.setString(2, "20" + i);
+			stmt.setString(3, "30" + i);
+			stmt.setString(4, "40" + i);
+			stmt.execute();
+		}
+		conn.commit();
+
+		conn = nextConnection(getUrl());
+		String query = "SELECT k1, k2, k3, k4 FROM " + tableName + " WHERE k2 = '203'";
+		ResultSet rs = conn.createStatement().executeQuery(query);
+		assertTrue(rs.next());
+		assertEquals("103", rs.getString(1));
+		assertEquals("203", rs.getString(2));
+		assertEquals("303", rs.getString(3));
+		assertEquals("403", rs.getString(4));
+
+		conn = nextConnection(getUrl());
+		query = "SELECT k1, k2, k3, k4 FROM " + tableName 
+				+ " WHERE (k2, k3, k4, k1) > ('201', '301', '401', '101')"
+				+ " AND k2 = '203'";
+		rs = conn.createStatement().executeQuery(query);
+		assertTrue(rs.next());
+		assertEquals("103", rs.getString(1));
+		assertEquals("203", rs.getString(2));
+		assertEquals("303", rs.getString(3));
+		assertEquals("403", rs.getString(4));
+	}
+
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/c0fb0503/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java
index 0a71bfb..99986a2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java
@@ -541,10 +541,6 @@ public class WhereOptimizer {
                 int span = position - initialPosition;
                 return new SingleKeySlot(new RowValueConstructorKeyPart(table.getPKColumns().get(initialPosition),
rvc, span, childSlots), initialPosition, span, EVERYTHING_RANGES);
             }
-            // If we don't clear the child list, we end up passing some of
-            // the child expressions of previous matches up the tree, causing
-            // those expressions to form the scan start/stop key. PHOENIX-1753
-            childSlots.clear();
             return null;
         }
 
@@ -1118,6 +1114,9 @@ public class WhereOptimizer {
                         // If they don't intersect, we cannot have a match for the RVC, so
filter it out.
                         // Otherwise, we keep it.
                         for (KeyRange keyRange : this.getKeyRanges()) {
+                            if (keyRange == KeyRange.EVERYTHING_RANGE) {
+                                return this;
+                            }
                             assert(keyRange.isSingleKey());
                             byte[] key = keyRange.getLowerRange();
                             int position = this.getPKPosition();


Mime
View raw message