phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maryann...@apache.org
Subject [3/3] phoenix git commit: PHOENIX-1610 Incorrect subquery results caused by unpaired contextStack push/pop
Date Thu, 29 Jan 2015 16:55:19 GMT
PHOENIX-1610 Incorrect subquery results caused by unpaired contextStack push/pop


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

Branch: refs/heads/4.0
Commit: 338747c9724c33b6a50132f0d7d5bbcf5802e194
Parents: 9ef28f6
Author: maryannxue <wei.xue@intel.com>
Authored: Thu Jan 29 11:54:48 2015 -0500
Committer: maryannxue <wei.xue@intel.com>
Committed: Thu Jan 29 11:54:48 2015 -0500

----------------------------------------------------------------------
 .../apache/phoenix/end2end/DerivedTableIT.java  |    9 +
 .../org/apache/phoenix/end2end/HashJoinIT.java  |   52 +-
 .../org/apache/phoenix/end2end/SubqueryIT.java  |   10 +-
 .../end2end/SubqueryUsingSortMergeJoinIT.java   |   10 +-
 phoenix-core/src/main/antlr3/PhoenixSQL.g       |    6 +-
 .../apache/phoenix/compile/QueryCompiler.java   |   12 +-
 .../coprocessor/MetaDataEndpointImpl.java.orig  | 1793 ------------------
 .../apache/phoenix/execute/HashJoinPlan.java    |   63 +-
 .../phoenix/expression/InListExpression.java    |    9 +-
 .../apache/phoenix/join/HashCacheClient.java    |   58 +-
 .../apache/phoenix/optimize/QueryOptimizer.java |    2 +-
 .../java/org/apache/phoenix/parse/HintNode.java |    8 +-
 12 files changed, 120 insertions(+), 1912 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/338747c9/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
index 430e5ab..562a98e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
@@ -666,6 +666,15 @@ public class DerivedTableIT extends BaseClientManagedTimeIT {
             assertEquals(2,rs.getInt(1));
 
             assertFalse(rs.next());
+            
+            // count (subquery)
+            query = "SELECT count(*) FROM (SELECT * FROM aTable WHERE (organization_id, entity_id)
in (SELECT organization_id, entity_id FROM aTable WHERE a_byte != 8)) AS t";
+            statement = conn.prepareStatement(query);
+            rs = statement.executeQuery();
+            assertTrue (rs.next());
+            assertEquals(8,rs.getInt(1));
+
+            assertFalse(rs.next());
         } finally {
             conn.close();
         }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/338747c9/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java
index 9a95ea4..a699d48 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java
@@ -229,7 +229,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
                 "    PARALLEL INNER-JOIN TABLE 0\n" +
                 "        CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ITEM_TABLE_DISPLAY_NAME
+ "\n" +
                 "            SERVER FILTER BY FIRST KEY ONLY\n" +
-                "    DYNAMIC SERVER FILTER BY item_id BETWEEN MIN/MAX OF (I2.item_id)",
+                "    DYNAMIC SERVER FILTER BY item_id IN (I2.item_id)",
                 /*
                  * testSelfJoin()
                  *     SELECT i1.name, i2.name FROM joinItemTable i1 
@@ -241,7 +241,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
                 "CLIENT MERGE SORT\n" +
                 "    PARALLEL INNER-JOIN TABLE 0\n" +
                 "        CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ITEM_TABLE_DISPLAY_NAME
+ "\n" +
-                "    DYNAMIC SERVER FILTER BY item_id BETWEEN MIN/MAX OF (I2.supplier_id)",
+                "    DYNAMIC SERVER FILTER BY item_id IN (I2.supplier_id)",
                 /*
                  * testStarJoin()
                  *     SELECT order_id, c.name, i.name iname, quantity, o.date 
@@ -270,7 +270,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
                 "        CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME
+ "\n" +
                 "            PARALLEL INNER-JOIN TABLE 0\n" +
                 "                CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_CUSTOMER_TABLE_DISPLAY_NAME
+ "\n" +
-                "    DYNAMIC SERVER FILTER BY item_id BETWEEN MIN/MAX OF (O.item_id)",
+                "    DYNAMIC SERVER FILTER BY item_id IN (O.item_id)",
                 /*
                  * testSubJoin()
                  *     SELECT * FROM joinCustomerTable c 
@@ -415,11 +415,11 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
                 "        CLIENT PARALLEL 1-WAY FULL SCAN OVER "+ JOIN_ITEM_TABLE_DISPLAY_NAME
+ "\n" +
                 "    PARALLEL INNER-JOIN TABLE 1(DELAYED EVALUATION)\n" +
                 "        CLIENT PARALLEL 1-WAY FULL SCAN OVER "+ JOIN_ORDER_TABLE_DISPLAY_NAME
+ "\n" +
-                "    DYNAMIC SERVER FILTER BY supplier_id BETWEEN MIN/MAX OF (I.supplier_id)\n"
+
+                "    DYNAMIC SERVER FILTER BY supplier_id IN (I.supplier_id)\n" +
                 "    JOIN-SCANNER 4 ROW LIMIT",
                 /*
                  * testJoinWithKeyRangeOptimization()
-                 *     SELECT (*SKIP_SCAN_HASH_JOIN*) lhs.col0, lhs.col1, lhs.col2, rhs.col0,
rhs.col1, rhs.col2 
+                 *     SELECT lhs.col0, lhs.col1, lhs.col2, rhs.col0, rhs.col1, rhs.col2

                  *     FROM TEMP_TABLE_COMPOSITE_PK lhs 
                  *     JOIN TEMP_TABLE_COMPOSITE_PK rhs ON lhs.col1 = rhs.col2
                  */
@@ -430,7 +430,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
                 "        CLIENT MERGE SORT",
                 /*
                  * testJoinWithKeyRangeOptimization()
-                 *     SELECT (*SKIP_SCAN_HASH_JOIN*) lhs.col0, lhs.col1, lhs.col2, rhs.col0,
rhs.col1, rhs.col2 
+                 *     SELECT lhs.col0, lhs.col1, lhs.col2, rhs.col0, rhs.col1, rhs.col2

                  *     FROM TEMP_TABLE_COMPOSITE_PK lhs 
                  *     JOIN TEMP_TABLE_COMPOSITE_PK rhs ON lhs.col0 = rhs.col2
                  */
@@ -442,7 +442,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
                 "    DYNAMIC SERVER FILTER BY COL0 IN (RHS.COL2)",
                 /*
                  * testJoinWithKeyRangeOptimization()
-                 *     SELECT (*SKIP_SCAN_HASH_JOIN*) lhs.col0, lhs.col1, lhs.col2, rhs.col0,
rhs.col1, rhs.col2 
+                 *     SELECT lhs.col0, lhs.col1, lhs.col2, rhs.col0, rhs.col1, rhs.col2

                  *     FROM TEMP_TABLE_COMPOSITE_PK lhs 
                  *     JOIN TEMP_TABLE_COMPOSITE_PK rhs ON lhs.col0 = rhs.col1 AND lhs.col1
= rhs.col2
                  */
@@ -454,7 +454,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
                 "    DYNAMIC SERVER FILTER BY (COL0, COL1) IN ((RHS.COL1, RHS.COL2))",
                 /*
                  * testJoinWithKeyRangeOptimization()
-                 *     SELECT (*SKIP_SCAN_HASH_JOIN*) lhs.col0, lhs.col1, lhs.col2, rhs.col0,
rhs.col1, rhs.col2 
+                 *     SELECT lhs.col0, lhs.col1, lhs.col2, rhs.col0, rhs.col1, rhs.col2

                  *     FROM TEMP_TABLE_COMPOSITE_PK lhs 
                  *     JOIN TEMP_TABLE_COMPOSITE_PK rhs ON lhs.col0 = rhs.col1 AND lhs.col2
= rhs.col3 - 1 AND lhs.col1 = rhs.col2
                  */
@@ -592,7 +592,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
                 "    PARALLEL INNER-JOIN TABLE 0\n" +
                 "        CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_SCHEMA + ".idx_item\n"
+
                 "            SERVER FILTER BY FIRST KEY ONLY\n" +
-                "    DYNAMIC SERVER FILTER BY item_id BETWEEN MIN/MAX OF (I2.:item_id)",
+                "    DYNAMIC SERVER FILTER BY item_id IN (I2.:item_id)",
                 /*
                  * testSelfJoin()
                  *     SELECT i1.name, i2.name FROM joinItemTable i1 
@@ -782,11 +782,11 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
                 "        CLIENT PARALLEL 1-WAY FULL SCAN OVER "+ JOIN_SCHEMA + ".idx_item\n"
+
                 "    PARALLEL INNER-JOIN TABLE 1(DELAYED EVALUATION)\n" +
                 "        CLIENT PARALLEL 1-WAY FULL SCAN OVER "+ JOIN_ORDER_TABLE_DISPLAY_NAME
+ "\n" +
-                "    DYNAMIC SERVER FILTER BY supplier_id BETWEEN MIN/MAX OF (I.0:supplier_id)\n"
+
+                "    DYNAMIC SERVER FILTER BY supplier_id IN (I.0:supplier_id)\n" +
                 "    JOIN-SCANNER 4 ROW LIMIT",
                 /*
                  * testJoinWithKeyRangeOptimization()
-                 *     SELECT (*SKIP_SCAN_HASH_JOIN*) lhs.col0, lhs.col1, lhs.col2, rhs.col0,
rhs.col1, rhs.col2 
+                 *     SELECT lhs.col0, lhs.col1, lhs.col2, rhs.col0, rhs.col1, rhs.col2

                  *     FROM TEMP_TABLE_COMPOSITE_PK lhs 
                  *     JOIN TEMP_TABLE_COMPOSITE_PK rhs ON lhs.col1 = rhs.col2
                  */
@@ -797,7 +797,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
                 "        CLIENT MERGE SORT",
                 /*
                  * testJoinWithKeyRangeOptimization()
-                 *     SELECT (*SKIP_SCAN_HASH_JOIN*) lhs.col0, lhs.col1, lhs.col2, rhs.col0,
rhs.col1, rhs.col2 
+                 *     SELECT lhs.col0, lhs.col1, lhs.col2, rhs.col0, rhs.col1, rhs.col2

                  *     FROM TEMP_TABLE_COMPOSITE_PK lhs 
                  *     JOIN TEMP_TABLE_COMPOSITE_PK rhs ON lhs.col0 = rhs.col2
                  */
@@ -809,7 +809,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
                 "    DYNAMIC SERVER FILTER BY COL0 IN (RHS.COL2)",
                 /*
                  * testJoinWithKeyRangeOptimization()
-                 *     SELECT (*SKIP_SCAN_HASH_JOIN*) lhs.col0, lhs.col1, lhs.col2, rhs.col0,
rhs.col1, rhs.col2 
+                 *     SELECT lhs.col0, lhs.col1, lhs.col2, rhs.col0, rhs.col1, rhs.col2

                  *     FROM TEMP_TABLE_COMPOSITE_PK lhs 
                  *     JOIN TEMP_TABLE_COMPOSITE_PK rhs ON lhs.col0 = rhs.col1 AND lhs.col1
= rhs.col2
                  */
@@ -821,7 +821,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
                 "    DYNAMIC SERVER FILTER BY (COL0, COL1) IN ((RHS.COL1, RHS.COL2))",
                 /*
                  * testJoinWithKeyRangeOptimization()
-                 *     SELECT (*SKIP_SCAN_HASH_JOIN*) lhs.col0, lhs.col1, lhs.col2, rhs.col0,
rhs.col1, rhs.col2 
+                 *     SELECT lhs.col0, lhs.col1, lhs.col2, rhs.col0, rhs.col1, rhs.col2

                  *     FROM TEMP_TABLE_COMPOSITE_PK lhs 
                  *     JOIN TEMP_TABLE_COMPOSITE_PK rhs ON lhs.col0 = rhs.col1 AND lhs.col2
= rhs.col3 - 1 AND lhs.col1 = rhs.col2
                  */
@@ -970,7 +970,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
                 "        CLIENT PARALLEL 1-WAY RANGE SCAN OVER "+ MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX
+""+ JOIN_ITEM_TABLE_DISPLAY_NAME +" [-32768]\n"  +
                 "            SERVER FILTER BY FIRST KEY ONLY\n" +
                 "        CLIENT MERGE SORT\n" +
-                "    DYNAMIC SERVER FILTER BY item_id BETWEEN MIN/MAX OF (I2.:item_id)",
+                "    DYNAMIC SERVER FILTER BY item_id IN (I2.:item_id)",
                 /*
                  * testSelfJoin()
                  *     SELECT i1.name, i2.name FROM joinItemTable i1 
@@ -984,7 +984,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
                 "    PARALLEL INNER-JOIN TABLE 0\n" +
                 "        CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX
+""+ JOIN_ITEM_TABLE_DISPLAY_NAME +" [-32768]\n" +
                 "        CLIENT MERGE SORT\n" +
-                "    DYNAMIC SERVER FILTER BY item_id BETWEEN MIN/MAX OF (I2.0:supplier_id)",
+                "    DYNAMIC SERVER FILTER BY item_id IN (I2.0:supplier_id)",
                 /*
                  * testStarJoin()
                  *     SELECT order_id, c.name, i.name iname, quantity, o.date 
@@ -1020,7 +1020,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
                 "                CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX
+ "" + JOIN_CUSTOMER_TABLE_DISPLAY_NAME+" [-32768]\n"+
                 "                    SERVER FILTER BY FIRST KEY ONLY\n" + 
                 "                CLIENT MERGE SORT\n" +
-                "    DYNAMIC SERVER FILTER BY item_id BETWEEN MIN/MAX OF (O.item_id)",
+                "    DYNAMIC SERVER FILTER BY item_id IN (O.item_id)",
                 /*
                  * testSubJoin()
                  *     SELECT * FROM joinCustomerTable c 
@@ -1172,11 +1172,11 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
                 "        CLIENT MERGE SORT\n" +
                 "    PARALLEL INNER-JOIN TABLE 1(DELAYED EVALUATION)\n" +
                 "        CLIENT PARALLEL 1-WAY FULL SCAN OVER "+ JOIN_ORDER_TABLE_DISPLAY_NAME
+ "\n" +
-                "    DYNAMIC SERVER FILTER BY supplier_id BETWEEN MIN/MAX OF (I.0:supplier_id)\n"
+
+                "    DYNAMIC SERVER FILTER BY supplier_id IN (I.0:supplier_id)\n" +
                 "    JOIN-SCANNER 4 ROW LIMIT",
                 /*
                  * testJoinWithKeyRangeOptimization()
-                 *     SELECT (*SKIP_SCAN_HASH_JOIN*) lhs.col0, lhs.col1, lhs.col2, rhs.col0,
rhs.col1, rhs.col2 
+                 *     SELECT lhs.col0, lhs.col1, lhs.col2, rhs.col0, rhs.col1, rhs.col2

                  *     FROM TEMP_TABLE_COMPOSITE_PK lhs 
                  *     JOIN TEMP_TABLE_COMPOSITE_PK rhs ON lhs.col1 = rhs.col2
                  */
@@ -1187,7 +1187,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
                 "        CLIENT MERGE SORT",
                 /*
                  * testJoinWithKeyRangeOptimization()
-                 *     SELECT (*SKIP_SCAN_HASH_JOIN*) lhs.col0, lhs.col1, lhs.col2, rhs.col0,
rhs.col1, rhs.col2 
+                 *     SELECT lhs.col0, lhs.col1, lhs.col2, rhs.col0, rhs.col1, rhs.col2

                  *     FROM TEMP_TABLE_COMPOSITE_PK lhs 
                  *     JOIN TEMP_TABLE_COMPOSITE_PK rhs ON lhs.col0 = rhs.col2
                  */
@@ -1199,7 +1199,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
                 "    DYNAMIC SERVER FILTER BY COL0 IN (RHS.COL2)",
                 /*
                  * testJoinWithKeyRangeOptimization()
-                 *     SELECT (*SKIP_SCAN_HASH_JOIN*) lhs.col0, lhs.col1, lhs.col2, rhs.col0,
rhs.col1, rhs.col2 
+                 *     SELECT lhs.col0, lhs.col1, lhs.col2, rhs.col0, rhs.col1, rhs.col2

                  *     FROM TEMP_TABLE_COMPOSITE_PK lhs 
                  *     JOIN TEMP_TABLE_COMPOSITE_PK rhs ON lhs.col0 = rhs.col1 AND lhs.col1
= rhs.col2
                  */
@@ -1211,7 +1211,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
                 "    DYNAMIC SERVER FILTER BY (COL0, COL1) IN ((RHS.COL1, RHS.COL2))",
                 /*
                  * testJoinWithKeyRangeOptimization()
-                 *     SELECT (*SKIP_SCAN_HASH_JOIN*) lhs.col0, lhs.col1, lhs.col2, rhs.col0,
rhs.col1, rhs.col2 
+                 *     SELECT lhs.col0, lhs.col1, lhs.col2, rhs.col0, rhs.col1, rhs.col2

                  *     FROM TEMP_TABLE_COMPOSITE_PK lhs 
                  *     JOIN TEMP_TABLE_COMPOSITE_PK rhs ON lhs.col0 = rhs.col1 AND lhs.col2
= rhs.col3 - 1 AND lhs.col1 = rhs.col2
                  */
@@ -3549,7 +3549,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
             conn.commit();
             
             // No leading part of PK
-            String query = "SELECT /*+ SKIP_SCAN_HASH_JOIN*/ lhs.col0, lhs.col1, lhs.col2,
lhs.col3, rhs.col0, rhs.col1, rhs.col2, rhs.col3 FROM " 
+            String query = "SELECT lhs.col0, lhs.col1, lhs.col2, lhs.col3, rhs.col0, rhs.col1,
rhs.col2, rhs.col3 FROM " 
                     + tempTableWithCompositePK + " lhs JOIN "
                     + tempTableWithCompositePK + " rhs ON lhs.col1 = rhs.col2";
             PreparedStatement statement = conn.prepareStatement(query);
@@ -3579,7 +3579,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
             assertEquals(plans[21], QueryUtil.getExplainPlan(rs));
             
             // Two parts of PK but only one leading part
-            query = "SELECT /*+ SKIP_SCAN_HASH_JOIN*/ lhs.col0, lhs.col1, lhs.col2, lhs.col3,
rhs.col0, rhs.col1, rhs.col2, rhs.col3 FROM " 
+            query = "SELECT lhs.col0, lhs.col1, lhs.col2, lhs.col3, rhs.col0, rhs.col1, rhs.col2,
rhs.col3 FROM " 
                     + tempTableWithCompositePK + " lhs JOIN "
                     + tempTableWithCompositePK + " rhs ON lhs.col2 = rhs.col3 AND lhs.col0
= rhs.col2";
             statement = conn.prepareStatement(query);
@@ -3600,7 +3600,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
             assertEquals(plans[22], QueryUtil.getExplainPlan(rs));
             
             // Two leading parts of PK
-            query = "SELECT /*+ SKIP_SCAN_HASH_JOIN*/ lhs.col0, lhs.col1, lhs.col2, lhs.col3,
rhs.col0, rhs.col1, rhs.col2, rhs.col3 FROM " 
+            query = "SELECT lhs.col0, lhs.col1, lhs.col2, lhs.col3, rhs.col0, rhs.col1, rhs.col2,
rhs.col3 FROM " 
                     + tempTableWithCompositePK + " lhs JOIN "
                     + tempTableWithCompositePK + " rhs ON lhs.col1 = rhs.col2 AND lhs.col0
= rhs.col1";
             statement = conn.prepareStatement(query);
@@ -3630,7 +3630,7 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
             assertEquals(plans[23], QueryUtil.getExplainPlan(rs));
             
             // All parts of PK
-            query = "SELECT /*+ SKIP_SCAN_HASH_JOIN*/ lhs.col0, lhs.col1, lhs.col2, lhs.col3,
rhs.col0, rhs.col1, rhs.col2, rhs.col3 FROM " 
+            query = "SELECT lhs.col0, lhs.col1, lhs.col2, lhs.col3, rhs.col0, rhs.col1, rhs.col2,
rhs.col3 FROM " 
                     + tempTableWithCompositePK + " lhs JOIN "
                     + tempTableWithCompositePK + " rhs ON lhs.col1 = rhs.col2 AND lhs.col2
= rhs.col3 - 1 AND lhs.col0 = rhs.col1";
             statement = conn.prepareStatement(query);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/338747c9/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java
index 066790c..85e562c 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java
@@ -139,11 +139,11 @@ public class SubqueryIT extends BaseHBaseManagedTimeIT {
                 "        CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ITEM_TABLE_DISPLAY_NAME
+ "\n" +
                 "            SERVER AGGREGATE INTO DISTINCT ROWS BY \\[item_id, NAME\\]\n"
+
                 "        CLIENT MERGE SORT\n" +
-                "            PARALLEL SEMI-JOIN TABLE 0 \\(SKIP MERGE\\)\n" +
+                "            SKIP-SCAN-JOIN TABLE 0\n" +
                 "                CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME
+ "\n" +
                 "                    SERVER AGGREGATE INTO DISTINCT ROWS BY \\[item_id\\]\n"
+
                 "                CLIENT MERGE SORT\n" +
-                "            DYNAMIC SERVER FILTER BY item_id BETWEEN MIN/MAX OF \\(\\$\\d+.\\$\\d+\\)\n"
+
+                "            DYNAMIC SERVER FILTER BY item_id IN \\(\\$\\d+.\\$\\d+\\)\n"
+
                 "    AFTER-JOIN SERVER FILTER BY \\(\\$\\d+.\\$\\d+ IS NOT NULL OR \\$\\d+.\\$\\d+
IS NOT NULL\\)",
                 
                 "CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ITEM_TABLE_DISPLAY_NAME +
"\n" +
@@ -165,7 +165,7 @@ public class SubqueryIT extends BaseHBaseManagedTimeIT {
                 "                CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME
+ "\n" +
                 "                    SERVER AGGREGATE INTO DISTINCT ROWS BY \\[item_id\\]\n"
+
                 "                CLIENT MERGE SORT\n" +
-                "            DYNAMIC SERVER FILTER BY item_id BETWEEN MIN/MAX OF \\(O.item_id\\)\n"
+
+                "            DYNAMIC SERVER FILTER BY item_id IN \\(O.item_id\\)\n" +
                 "            AFTER-JOIN SERVER FILTER BY \\(I.NAME = 'T2' OR O.QUANTITY >
\\$\\d+.\\$\\d+\\)\n" +
                 "    DYNAMIC SERVER FILTER BY customer_id IN \\(\\$\\d+.\\$\\d+\\)"
                 }});
@@ -289,7 +289,7 @@ public class SubqueryIT extends BaseHBaseManagedTimeIT {
                 "                CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME
+ "\n" +
                 "                    SERVER AGGREGATE INTO DISTINCT ROWS BY \\[item_id\\]\n"
+
                 "                CLIENT MERGE SORT\n" +
-                "            DYNAMIC SERVER FILTER BY item_id BETWEEN MIN/MAX OF \\(\\$\\d+.\\$\\d+\\)\n"
+
+                "            DYNAMIC SERVER FILTER BY item_id IN \\(\\$\\d+.\\$\\d+\\)\n"
+
                 "    AFTER-JOIN SERVER FILTER BY \\(\\$\\d+.\\$\\d+ IS NOT NULL OR \\$\\d+.\\$\\d+
IS NOT NULL\\)",
                 
                 "CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + MetaDataUtil.LOCAL_INDEX_TABLE_PREFIX
+ JOIN_ITEM_TABLE_DISPLAY_NAME + " [-32768]\n" +
@@ -314,7 +314,7 @@ public class SubqueryIT extends BaseHBaseManagedTimeIT {
                 "                CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME
+ "\n" +
                 "                    SERVER AGGREGATE INTO DISTINCT ROWS BY \\[item_id\\]\n"
+
                 "                CLIENT MERGE SORT\n" +
-                "            DYNAMIC SERVER FILTER BY item_id BETWEEN MIN/MAX OF \\(O.item_id\\)\n"
+
+                "            DYNAMIC SERVER FILTER BY item_id IN \\(O.item_id\\)\n" +
                 "            AFTER-JOIN SERVER FILTER BY \\(I.0:NAME = 'T2' OR O.QUANTITY
> \\$\\d+.\\$\\d+\\)\n" +
                 "    DYNAMIC SERVER FILTER BY customer_id IN \\(\\$\\d+.\\$\\d+\\)"
                 }});

http://git-wip-us.apache.org/repos/asf/phoenix/blob/338747c9/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryUsingSortMergeJoinIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryUsingSortMergeJoinIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryUsingSortMergeJoinIT.java
index bbb84ba..82b1c68 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryUsingSortMergeJoinIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryUsingSortMergeJoinIT.java
@@ -143,11 +143,11 @@ public class SubqueryUsingSortMergeJoinIT extends BaseHBaseManagedTimeIT
{
                 "        SERVER AGGREGATE INTO DISTINCT ROWS BY \\[item_id, NAME\\]\n" +
                 "    CLIENT MERGE SORT\n" +
                 "    CLIENT SORTED BY \\[item_id, NAME\\]\n" +
-                "        PARALLEL SEMI-JOIN TABLE 0 \\(SKIP MERGE\\)\n" +
+                "        SKIP-SCAN-JOIN TABLE 0\n" +
                 "            CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME
+ "\n" +
                 "                SERVER AGGREGATE INTO DISTINCT ROWS BY \\[item_id\\]\n"
+
                 "            CLIENT MERGE SORT\n" +
-                "        DYNAMIC SERVER FILTER BY item_id BETWEEN MIN/MAX OF \\(\\$\\d+.\\$\\d+\\)\n"
+
+                "        DYNAMIC SERVER FILTER BY item_id IN \\(\\$\\d+.\\$\\d+\\)\n" +
                 "CLIENT FILTER BY \\(\\$\\d+.\\$\\d+ IS NOT NULL OR \\$\\d+.\\$\\d+ IS NOT
NULL\\)",            
 
                 "SORT-MERGE-JOIN \\(SEMI\\) TABLES\n" +
@@ -163,7 +163,7 @@ public class SubqueryUsingSortMergeJoinIT extends BaseHBaseManagedTimeIT
{
                 "            CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME
+ "\n" +
                 "                SERVER AGGREGATE INTO DISTINCT ROWS BY \\[item_id\\]\n"
+
                 "            CLIENT MERGE SORT\n" +
-                "        DYNAMIC SERVER FILTER BY item_id BETWEEN MIN/MAX OF \\(O.item_id\\)\n"
+
+                "        DYNAMIC SERVER FILTER BY item_id IN \\(O.item_id\\)\n" +
                 "        AFTER-JOIN SERVER FILTER BY \\(I.NAME = 'T2' OR O.QUANTITY >
\\$\\d+.\\$\\d+\\)",
                 }});
         testCases.add(new String[][] {
@@ -285,7 +285,7 @@ public class SubqueryUsingSortMergeJoinIT extends BaseHBaseManagedTimeIT
{
                 "            CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME
+ "\n" +
                 "                SERVER AGGREGATE INTO DISTINCT ROWS BY \\[item_id\\]\n"
+
                 "            CLIENT MERGE SORT\n" +
-                "        DYNAMIC SERVER FILTER BY item_id BETWEEN MIN/MAX OF \\(\\$\\d+.\\$\\d+\\)\n"
+
+                "        DYNAMIC SERVER FILTER BY item_id IN \\(\\$\\d+.\\$\\d+\\)\n" +
                 "CLIENT FILTER BY \\(\\$\\d+.\\$\\d+ IS NOT NULL OR \\$\\d+.\\$\\d+ IS NOT
NULL\\)",
                 
                 "SORT-MERGE-JOIN \\(SEMI\\) TABLES\n" +
@@ -305,7 +305,7 @@ public class SubqueryUsingSortMergeJoinIT extends BaseHBaseManagedTimeIT
{
                 "            CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME
+ "\n" +
                 "                SERVER AGGREGATE INTO DISTINCT ROWS BY \\[item_id\\]\n"
+
                 "            CLIENT MERGE SORT\n" +
-                "        DYNAMIC SERVER FILTER BY item_id BETWEEN MIN/MAX OF \\(O.item_id\\)\n"
+
+                "        DYNAMIC SERVER FILTER BY item_id IN \\(O.item_id\\)\n" +
                 "        AFTER-JOIN SERVER FILTER BY \\(I.0:NAME = 'T2' OR O.QUANTITY >
\\$\\d+.\\$\\d+\\)",
                 }});
         return testCases;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/338747c9/phoenix-core/src/main/antlr3/PhoenixSQL.g
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/antlr3/PhoenixSQL.g b/phoenix-core/src/main/antlr3/PhoenixSQL.g
index 0a4ea7a..bcf26be 100644
--- a/phoenix-core/src/main/antlr3/PhoenixSQL.g
+++ b/phoenix-core/src/main/antlr3/PhoenixSQL.g
@@ -362,8 +362,9 @@ non_select_node returns [BindableStatement ret]
     |	s=create_sequence_node
     |	s=drop_sequence_node
     |   s=update_statistics_node
-    |   s=explain_node) { contextStack.pop();  $ret = s; }
+    |   s=explain_node) { $ret = s; }
     ;
+finally{ contextStack.pop(); }
     
 explain_node returns [BindableStatement ret]
     :   EXPLAIN q=oneStatement {$ret=factory.explain(q);}
@@ -567,8 +568,9 @@ select_node returns [SelectStatement ret]
         (HAVING having=expression)?
         (ORDER BY order=order_by)?
         (LIMIT l=limit)?
-        { ParseContext context = contextStack.pop(); $ret = factory.select(from, null, d!=null,
sel, where, group, having, order, l, getBindCount(), context.isAggregate(), context.hasSequences());
}
+        { ParseContext context = contextStack.peek(); $ret = factory.select(from, null, d!=null,
sel, where, group, having, order, l, getBindCount(), context.isAggregate(), context.hasSequences());
}
     ;
+finally{ contextStack.pop(); }
 
 // Parse a full select expression structure.
 hinted_select_node returns [SelectStatement ret]

http://git-wip-us.apache.org/repos/asf/phoenix/blob/338747c9/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java
index cbed675..f1730ba 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java
@@ -101,6 +101,7 @@ public class QueryCompiler {
     private final ParallelIteratorFactory parallelIteratorFactory;
     private final SequenceManager sequenceManager;
     private final boolean useSortMergeJoin;
+    private final boolean noChildParentJoinOptimization;
     
     public QueryCompiler(PhoenixStatement statement, SelectStatement select, ColumnResolver
resolver) throws SQLException {
         this(statement, select, resolver, Collections.<PDatum>emptyList(), null, new
SequenceManager(statement));
@@ -115,6 +116,7 @@ public class QueryCompiler {
         this.parallelIteratorFactory = parallelIteratorFactory;
         this.sequenceManager = sequenceManager;
         this.useSortMergeJoin = select.getHint().hasHint(Hint.USE_SORT_MERGE_JOIN);
+        this.noChildParentJoinOptimization = select.getHint().hasHint(Hint.NO_CHILD_PARENT_JOIN_OPTIMIZATION);
         if (statement.getConnection().getQueryServices().getLowestClusterHBaseVersion() >=
PhoenixDatabaseMetaData.ESSENTIAL_FAMILY_VERSION_THRESHOLD) {
             this.scan.setAttribute(LOAD_COLUMN_FAMILIES_ON_DEMAND_ATTR, QueryConstants.TRUE);
         }
@@ -259,16 +261,14 @@ public class QueryCompiler {
                 joinExpressions[i] = joinConditions.getFirst();
                 List<Expression> hashExpressions = joinConditions.getSecond();
                 Pair<Expression, Expression> keyRangeExpressions = new Pair<Expression,
Expression>(null, null);
-                boolean complete = getKeyExpressionCombinations(keyRangeExpressions, context,
joinTable.getStatement(), tableRef, joinSpec.getType(), joinExpressions[i], hashExpressions);
+                boolean optimized = getKeyExpressionCombinations(keyRangeExpressions, context,
joinTable.getStatement(), tableRef, joinSpec.getType(), joinExpressions[i], hashExpressions);
                 Expression keyRangeLhsExpression = keyRangeExpressions.getFirst();
                 Expression keyRangeRhsExpression = keyRangeExpressions.getSecond();
-                boolean hasFilters = joinSpec.getJoinTable().hasFilters();
-                boolean optimized = complete && hasFilters;
                 joinTypes[i] = joinSpec.getType();
                 if (i < count - 1) {
                     fieldPositions[i + 1] = fieldPositions[i] + (tables[i] == null ? 0 :
(tables[i].getColumns().size() - tables[i].getPKColumns().size()));
                 }
-                subPlans[i] = new HashSubPlan(i, joinPlan, optimized ? null : hashExpressions,
joinSpec.isSingleValueOnly(), keyRangeLhsExpression, keyRangeRhsExpression, hasFilters);
+                subPlans[i] = new HashSubPlan(i, joinPlan, optimized ? null : hashExpressions,
joinSpec.isSingleValueOnly(), keyRangeLhsExpression, keyRangeRhsExpression);
             }
             if (needsProject) {
                 TupleProjector.serializeProjectorIntoScan(context.getScan(), initialProjectedTable.createTupleProjector());
@@ -339,7 +339,7 @@ public class QueryCompiler {
             HashJoinInfo joinInfo = new HashJoinInfo(projectedTable.getTable(), joinIds,
new List[] {joinExpressions}, new JoinType[] {type == JoinType.Right ? JoinType.Left : type},
new boolean[] {true}, new PTable[] {lhsTable}, new int[] {fieldPosition}, postJoinFilterExpression,
limit, forceProjection);
             Pair<Expression, Expression> keyRangeExpressions = new Pair<Expression,
Expression>(null, null);
             getKeyExpressionCombinations(keyRangeExpressions, context, joinTable.getStatement(),
rhsTableRef, type, joinExpressions, hashExpressions);
-            return HashJoinPlan.create(joinTable.getStatement(), rhsPlan, joinInfo, new HashSubPlan[]
{new HashSubPlan(0, lhsPlan, hashExpressions, false, keyRangeExpressions.getFirst(), keyRangeExpressions.getSecond(),
lhsJoin.hasFilters())});
+            return HashJoinPlan.create(joinTable.getStatement(), rhsPlan, joinInfo, new HashSubPlan[]
{new HashSubPlan(0, lhsPlan, hashExpressions, false, keyRangeExpressions.getFirst(), keyRangeExpressions.getSecond())});
         }
         
         JoinTable lhsJoin = joinTable.getSubJoinTableWithoutPostFilters();
@@ -395,7 +395,7 @@ public class QueryCompiler {
     }
     
     private boolean getKeyExpressionCombinations(Pair<Expression, Expression> combination,
StatementContext context, SelectStatement select, TableRef table, JoinType type, final List<Expression>
joinExpressions, final List<Expression> hashExpressions) throws SQLException {
-        if (type != JoinType.Inner && type != JoinType.Semi)
+        if ((type != JoinType.Inner && type != JoinType.Semi) || this.noChildParentJoinOptimization)
             return false;
         
         Scan scanCopy = ScanUtil.newScan(context.getScan());


Mime
View raw message