You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ma...@apache.org on 2014/02/22 01:25:05 UTC

[1/2] git commit: PHOENIX-68 Add Option "FAVOR_STAR_JOIN" to indicate if star join optimization is preferred for multi inner join queries

Repository: incubator-phoenix
Updated Branches:
  refs/heads/master 0e2b62e7a -> 67c961516


PHOENIX-68 Add Option "FAVOR_STAR_JOIN" to indicate if star join optimization is preferred for multi inner join queries


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

Branch: refs/heads/master
Commit: 8fe0dd9a04e5acdccdba8a412b35899bd50bbcf6
Parents: 0e2b62e
Author: maryannxue <ma...@apache.org>
Authored: Fri Feb 21 17:32:09 2014 -0500
Committer: maryannxue <ma...@apache.org>
Committed: Fri Feb 21 17:32:09 2014 -0500

----------------------------------------------------------------------
 .../apache/phoenix/compile/JoinCompiler.java    |  83 +++++-----
 .../apache/phoenix/compile/QueryCompiler.java   |   2 +-
 .../java/org/apache/phoenix/parse/HintNode.java |   4 +
 .../apache/phoenix/end2end/HashJoinTest.java    | 154 ++++++++++++++-----
 4 files changed, 167 insertions(+), 76 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8fe0dd9a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index 5439574..43b45c1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -53,6 +53,8 @@ import org.apache.phoenix.parse.ConcreteTableNode;
 import org.apache.phoenix.parse.DerivedTableNode;
 import org.apache.phoenix.parse.EqualParseNode;
 import org.apache.phoenix.parse.FunctionParseNode;
+import org.apache.phoenix.parse.HintNode;
+import org.apache.phoenix.parse.HintNode.Hint;
 import org.apache.phoenix.parse.InListParseNode;
 import org.apache.phoenix.parse.IsNullParseNode;
 import org.apache.phoenix.parse.JoinTableNode;
@@ -107,6 +109,7 @@ public class JoinCompiler {
         private List<ParseNode> preFilters;
         private List<ParseNode> postFilters;
         private List<JoinTable> joinTables;
+        private boolean useStarJoin;
         private Map<TableRef, JoinTable> tableRefToJoinTableMap;
         private Map<ColumnRef, ColumnRefType> columnRefs;
         
@@ -114,6 +117,7 @@ public class JoinCompiler {
             this.origResolver = resolver;
             List<AliasedNode> selectList = statement.getSelect();
             List<TableNode> tableNodes = statement.getFrom();
+            HintNode hint = statement.getHint();
             assert (tableNodes.size() > 1);
             Iterator<TableNode> iter = tableNodes.iterator();
             Iterator<TableRef> tableRefIter = resolver.getTables().iterator();
@@ -123,6 +127,7 @@ public class JoinCompiler {
             this.joinTables = new ArrayList<JoinTable>(tableNodes.size() - 1);
             this.preFilters = new ArrayList<ParseNode>();
             this.postFilters = new ArrayList<ParseNode>();
+            this.useStarJoin = !hint.hasHint(Hint.NO_STAR_JOIN);
             this.tableRefToJoinTableMap = new HashMap<TableRef, JoinTable>();
             ColumnParseNodeVisitor generalRefVisitor = new ColumnParseNodeVisitor(resolver);
             ColumnParseNodeVisitor joinLocalRefVisitor = new ColumnParseNodeVisitor(resolver);
@@ -135,7 +140,7 @@ public class JoinCompiler {
                 if (!(tableNode instanceof JoinTableNode))
                     throw new SQLFeatureNotSupportedException("Implicit joins not supported.");
                 JoinTableNode joinTableNode = (JoinTableNode) tableNode;
-                JoinTable joinTable = new JoinTable(joinTableNode, tableRefIter.next(), selectList, resolver);
+                JoinTable joinTable = new JoinTable(joinTableNode, tableRefIter.next(), selectList, hint, resolver);
                 for (ParseNode condition : joinTable.conditions) {
                     ComparisonParseNode comparisonNode = (ComparisonParseNode) condition;
                     comparisonNode.getLHS().accept(generalRefVisitor);
@@ -206,7 +211,7 @@ public class JoinCompiler {
         }
         
         private JoinSpec(ColumnResolver resolver, TableNode tableNode, TableRef table, List<AliasedNode> select, List<ParseNode> preFilters, 
-                List<ParseNode> postFilters, List<JoinTable> joinTables, Map<TableRef, JoinTable> tableRefToJoinTableMap, Map<ColumnRef, ColumnRefType> columnRefs) {
+                List<ParseNode> postFilters, List<JoinTable> joinTables, boolean useStarJoin, Map<TableRef, JoinTable> tableRefToJoinTableMap, Map<ColumnRef, ColumnRefType> columnRefs) {
             this.origResolver = resolver;
             this.mainTableNode = tableNode;
             this.mainTable = table;
@@ -214,6 +219,7 @@ public class JoinCompiler {
             this.preFilters = preFilters;
             this.postFilters = postFilters;
             this.joinTables = joinTables;
+            this.useStarJoin = useStarJoin;
             this.tableRefToJoinTableMap = tableRefToJoinTableMap;
             this.columnRefs = columnRefs;
         }
@@ -274,6 +280,41 @@ public class JoinCompiler {
             return AndExpression.create(expressions);
         }
         
+        /**
+         * Returns a boolean vector indicating whether the evaluation of join expressions
+         * can be evaluated at an early stage if the input JoinSpec can be taken as a
+         * star join. Otherwise returns null.  
+         * @param join the JoinSpec
+         * @return a boolean vector for a star join; or null for non star join.
+         */
+        public boolean[] getStarJoinVector() {
+            assert(!joinTables.isEmpty());
+            
+            int count = joinTables.size();
+            if (!useStarJoin 
+                    && count > 1 
+                    && joinTables.get(count - 1).getType() != JoinType.Left)
+                return null;
+
+            boolean[] vector = new boolean[count];
+            for (int i = 0; i < count; i++) {
+                JoinTable joinTable = joinTables.get(i);
+                if (joinTable.getType() != JoinType.Left 
+                        && joinTable.getType() != JoinType.Inner)
+                    return null;
+                vector[i] = true;
+                Iterator<TableRef> iter = joinTable.getLeftTableRefs().iterator();
+                while (vector[i] == true && iter.hasNext()) {
+                    TableRef tableRef = iter.next();
+                    if (!tableRef.equals(mainTable)) {
+                        vector[i] = false;
+                    }
+                }
+            }
+            
+            return vector;
+        }
+        
         protected boolean isWildCardSelect(TableRef table) {
             List<AliasedNode> selectList = table.equals(mainTable) ? this.select : tableRefToJoinTableMap.get(table).getSelect();
             return (selectList.size() == 1 && selectList.get(0).getNode() instanceof TableWildcardParseNode);
@@ -491,7 +532,7 @@ public class JoinCompiler {
     
     public static JoinSpec getSubJoinSpecWithoutPostFilters(JoinSpec join) {
         return new JoinSpec(join.origResolver, join.mainTableNode, join.mainTable, join.select, join.preFilters, new ArrayList<ParseNode>(), 
-                join.joinTables.subList(0, join.joinTables.size() - 1), join.tableRefToJoinTableMap, join.columnRefs);
+                join.joinTables.subList(0, join.joinTables.size() - 1), join.useStarJoin, join.tableRefToJoinTableMap, join.columnRefs);
     }
     
     public static class JoinTable {
@@ -499,13 +540,14 @@ public class JoinCompiler {
         private TableNode tableNode; // original table node
         private TableRef table;
         private List<AliasedNode> select; // all basic nodes related to this table, no aggregation.
+        private HintNode hint;
         private List<ParseNode> preFilters;
         private List<ParseNode> conditions;
         private SelectStatement subquery;
         
         private Set<TableRef> leftTableRefs;
         
-        public JoinTable(JoinTableNode node, TableRef tableRef, List<AliasedNode> select, ColumnResolver resolver) throws SQLException {
+        public JoinTable(JoinTableNode node, TableRef tableRef, List<AliasedNode> select, HintNode hint, ColumnResolver resolver) throws SQLException {
             if (!(node.getTable() instanceof ConcreteTableNode))
                 throw new SQLFeatureNotSupportedException("Subqueries not supported.");
             
@@ -513,6 +555,7 @@ public class JoinCompiler {
             this.tableNode = node.getTable();
             this.table = tableRef;
             this.select = extractFromSelect(select,tableRef,resolver);
+            this.hint = hint;
             this.preFilters = new ArrayList<ParseNode>();
             this.conditions = new ArrayList<ParseNode>();
             this.leftTableRefs = new HashSet<TableRef>();
@@ -567,7 +610,7 @@ public class JoinCompiler {
             
             List<TableNode> from = new ArrayList<TableNode>(1);
             from.add(tableNode);
-            return NODE_FACTORY.select(from, null, false, select, getPreFiltersCombined(), null, null, null, null, 0, false);
+            return NODE_FACTORY.select(from, hint, false, select, getPreFiltersCombined(), null, null, null, null, 0, false);
         }
         
         public Pair<List<Expression>, List<Expression>> compileJoinConditions(StatementContext context, ColumnResolver leftResolver, ColumnResolver rightResolver) throws SQLException {
@@ -1056,36 +1099,6 @@ public class JoinCompiler {
         return NODE_FACTORY.select(from, select.getHint(), false, selectList, where, groupBy, null, orderBy, null, 0, false);
     }
     
-    /**
-     * Returns a boolean vector indicating whether the evaluation of join expressions
-     * can be evaluated at an early stage if the input JoinSpec can be taken as a
-     * star join. Otherwise returns null.  
-     * @param join the JoinSpec
-     * @return a boolean vector for a star join; or null for non star join.
-     */
-    public static boolean[] getStarJoinVector(JoinSpec join) {
-        assert(!join.getJoinTables().isEmpty());
-        
-        int count = join.getJoinTables().size();
-        boolean[] vector = new boolean[count];
-        for (int i = 0; i < count; i++) {
-        	JoinTable joinTable = join.getJoinTables().get(i);
-            if (joinTable.getType() != JoinType.Left 
-                    && joinTable.getType() != JoinType.Inner)
-                return null;
-            vector[i] = true;
-            Iterator<TableRef> iter = joinTable.getLeftTableRefs().iterator();
-            while (vector[i] == true && iter.hasNext()) {
-            	TableRef tableRef = iter.next();
-                if (!tableRef.equals(join.getMainTable())) {
-                    vector[i] = false;
-                }
-            }
-        }
-        
-        return vector;
-    }
-    
     public static SelectStatement getSubqueryWithoutJoin(SelectStatement statement, JoinSpec join) {
         return NODE_FACTORY.select(statement.getFrom().subList(0, 1), statement.getHint(), statement.isDistinct(), statement.getSelect(), join.getPreFiltersCombined(), statement.getGroupBy(), statement.getHaving(), statement.getOrderBy(), statement.getLimit(), statement.getBindCount(), statement.isAggregate());
     }

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8fe0dd9a/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 1b6545d..2638403 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
@@ -142,7 +142,7 @@ public class QueryCompiler {
             return compileSingleQuery(context, select, binds, null);
         }
         
-        boolean[] starJoinVector = JoinCompiler.getStarJoinVector(join);
+        boolean[] starJoinVector = join.getStarJoinVector();
         if (starJoinVector != null) {
             ProjectedPTableWrapper initialProjectedTable = join.createProjectedTable(join.getMainTable(), !asSubquery);
             PTableWrapper projectedTable = initialProjectedTable;

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8fe0dd9a/phoenix-core/src/main/java/org/apache/phoenix/parse/HintNode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/HintNode.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/HintNode.java
index 3432b4e..3519501 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/HintNode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/HintNode.java
@@ -77,6 +77,10 @@ public class HintNode {
         * Avoid caching any HBase blocks loaded by this query.
         */
        NO_CACHE,
+       /**
+        * Avoid using star-join optimization.
+        */
+       NO_STAR_JOIN,
     };
 
     private final Map<Hint,String> hints;

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8fe0dd9a/phoenix-core/src/test/java/org/apache/phoenix/end2end/HashJoinTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/HashJoinTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/HashJoinTest.java
index 6de282f..1593c52 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/HashJoinTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/end2end/HashJoinTest.java
@@ -18,6 +18,7 @@
 package org.apache.phoenix.end2end;
 
 import static org.apache.phoenix.util.TestUtil.JOIN_CUSTOMER_TABLE_FULL_NAME;
+import static org.apache.phoenix.util.TestUtil.JOIN_CUSTOMER_TABLE_DISPLAY_NAME;
 import static org.apache.phoenix.util.TestUtil.JOIN_ITEM_TABLE_FULL_NAME;
 import static org.apache.phoenix.util.TestUtil.JOIN_ITEM_TABLE_DISPLAY_NAME;
 import static org.apache.phoenix.util.TestUtil.JOIN_ORDER_TABLE_FULL_NAME;
@@ -248,6 +249,37 @@ public class HashJoinTest extends BaseHBaseManagedTimeTest {
                 "    PARALLEL EQUI-JOIN 1 HASH TABLES:\n" +
                 "    BUILD HASH TABLE 0\n" +
                 "        CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ITEM_TABLE_DISPLAY_NAME,
+                /*
+                 * testStarJoin
+                 * SELECT order_id, c.name, i.name iname, quantity, o.date 
+                 * FROM joinOrderTable o 
+                 * JOIN joinCustomerTable c ON o.customer_id = c.customer_id 
+                 * JOIN joinItemTable i ON o.item_id = i.item_id 
+                 * ORDER BY order_id
+                 */
+                "CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" +
+                "    PARALLEL EQUI-JOIN 2 HASH TABLES:\n" +
+                "    BUILD HASH TABLE 0\n" +
+                "        CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_CUSTOMER_TABLE_DISPLAY_NAME + "\n" +
+                "    BUILD HASH TABLE 1\n" +
+                "        CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ITEM_TABLE_DISPLAY_NAME,
+                /*
+                 * testStarJoin
+                 * SELECT (*NO_STAR_JOIN*) order_id, c.name, i.name iname, quantity, o.date 
+                 * FROM joinOrderTable o 
+                 * JOIN joinCustomerTable c ON o.customer_id = c.customer_id 
+                 * JOIN joinItemTable i ON o.item_id = i.item_id 
+                 * ORDER BY order_id
+                 */
+                "CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ITEM_TABLE_DISPLAY_NAME + "\n" +
+                "    SERVER SORTED BY [O.order_id]\n" +
+                "CLIENT MERGE SORT\n" +
+                "    PARALLEL EQUI-JOIN 1 HASH TABLES:\n" +
+                "    BUILD HASH TABLE 0\n" +
+                "        CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" +
+                "            PARALLEL EQUI-JOIN 1 HASH TABLES:\n" +
+                "            BUILD HASH TABLE 0\n" +
+                "                CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_CUSTOMER_TABLE_DISPLAY_NAME,
                 }});
         testCases.add(new String[][] {
                 {
@@ -396,6 +428,39 @@ public class HashJoinTest extends BaseHBaseManagedTimeTest {
                 "    PARALLEL EQUI-JOIN 1 HASH TABLES:\n" +
                 "    BUILD HASH TABLE 0\n" +
                 "        CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_SCHEMA + ".idx_item",
+                /*
+                 * testStarJoin
+                 * SELECT order_id, c.name, i.name iname, quantity, o.date 
+                 * FROM joinOrderTable o 
+                 * JOIN joinCustomerTable c ON o.customer_id = c.customer_id 
+                 * JOIN joinItemTable i ON o.item_id = i.item_id 
+                 * ORDER BY order_id
+                 */
+                "CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" +
+                "    PARALLEL EQUI-JOIN 2 HASH TABLES:\n" +
+                "    BUILD HASH TABLE 0\n" +
+                "        CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_SCHEMA + ".idx_customer\n" +
+                "    BUILD HASH TABLE 1\n" +
+                "        CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_SCHEMA + ".idx_item\n" +
+                "            SERVER FILTER BY FIRST KEY ONLY",
+                /*
+                 * testStarJoin
+                 * SELECT (*NO_STAR_JOIN*) order_id, c.name, i.name iname, quantity, o.date 
+                 * FROM joinOrderTable o 
+                 * JOIN joinCustomerTable c ON o.customer_id = c.customer_id 
+                 * JOIN joinItemTable i ON o.item_id = i.item_id 
+                 * ORDER BY order_id
+                 */
+                "CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_SCHEMA + ".idx_item\n" +
+                "    SERVER FILTER BY FIRST KEY ONLY\n" +
+                "    SERVER SORTED BY [O.order_id]\n" +
+                "CLIENT MERGE SORT\n" +
+                "    PARALLEL EQUI-JOIN 1 HASH TABLES:\n" +
+                "    BUILD HASH TABLE 0\n" +
+                "        CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_ORDER_TABLE_DISPLAY_NAME + "\n" +
+                "            PARALLEL EQUI-JOIN 1 HASH TABLES:\n" +
+                "            BUILD HASH TABLE 0\n" +
+                "                CLIENT PARALLEL 1-WAY FULL SCAN OVER " + JOIN_SCHEMA + ".idx_customer",
                 }});
         return testCases;
     }
@@ -1030,50 +1095,59 @@ public class HashJoinTest extends BaseHBaseManagedTimeTest {
     
     @Test
     public void testStarJoin() throws Exception {
-        String query = "SELECT \"order_id\", c.name, i.name iname, quantity, o.date FROM " + JOIN_ORDER_TABLE_FULL_NAME + " o LEFT JOIN " 
-            + JOIN_CUSTOMER_TABLE_FULL_NAME + " c ON o.\"customer_id\" = c.\"customer_id\" LEFT JOIN " 
-            + JOIN_ITEM_TABLE_FULL_NAME + " i ON o.\"item_id\" = i.\"item_id\"";
+        String[] query = new String[2];
+        query[0] = "SELECT \"order_id\", c.name, i.name iname, quantity, o.date FROM " + JOIN_ORDER_TABLE_FULL_NAME + " o JOIN " 
+            + JOIN_CUSTOMER_TABLE_FULL_NAME + " c ON o.\"customer_id\" = c.\"customer_id\" JOIN " 
+            + JOIN_ITEM_TABLE_FULL_NAME + " i ON o.\"item_id\" = i.\"item_id\" ORDER BY \"order_id\"";
+        query[1] = "SELECT /*+ NO_STAR_JOIN*/ \"order_id\", c.name, i.name iname, quantity, o.date FROM " + JOIN_ORDER_TABLE_FULL_NAME + " o JOIN " 
+                + JOIN_CUSTOMER_TABLE_FULL_NAME + " c ON o.\"customer_id\" = c.\"customer_id\" JOIN " 
+                + JOIN_ITEM_TABLE_FULL_NAME + " i ON o.\"item_id\" = i.\"item_id\" ORDER BY \"order_id\"";
         Properties props = new Properties(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
         try {
-            PreparedStatement statement = conn.prepareStatement(query);
-            ResultSet rs = statement.executeQuery();
-            assertTrue (rs.next());
-            assertEquals(rs.getString(1), "000000000000001");
-            assertEquals(rs.getString("\"order_id\""), "000000000000001");
-            assertEquals(rs.getString(2), "C4");
-            assertEquals(rs.getString("C.name"), "C4");
-            assertEquals(rs.getString(3), "T1");
-            assertEquals(rs.getString("iName"), "T1");
-            assertEquals(rs.getInt(4), 1000);
-            assertEquals(rs.getInt("Quantity"), 1000);
-            assertNotNull(rs.getDate(5));
-            assertTrue (rs.next());
-            assertEquals(rs.getString(1), "000000000000002");
-            assertEquals(rs.getString(2), "C3");
-            assertEquals(rs.getString(3), "T6");
-            assertEquals(rs.getInt(4), 2000);
-            assertNotNull(rs.getDate(5));
-            assertTrue (rs.next());
-            assertEquals(rs.getString(1), "000000000000003");
-            assertEquals(rs.getString(2), "C2");
-            assertEquals(rs.getString(3), "T2");
-            assertEquals(rs.getInt(4), 3000);
-            assertNotNull(rs.getDate(5));
-            assertTrue (rs.next());
-            assertEquals(rs.getString(1), "000000000000004");
-            assertEquals(rs.getString(2), "C4");
-            assertEquals(rs.getString(3), "T6");
-            assertEquals(rs.getInt(4), 4000);
-            assertNotNull(rs.getDate(5));
-            assertTrue (rs.next());
-            assertEquals(rs.getString(1), "000000000000005");
-            assertEquals(rs.getString(2), "C5");
-            assertEquals(rs.getString(3), "T3");
-            assertEquals(rs.getInt(4), 5000);
-            assertNotNull(rs.getDate(5));
+            for (int i = 0; i < query.length; i++) {
+                PreparedStatement statement = conn.prepareStatement(query[i]);
+                ResultSet rs = statement.executeQuery();
+                assertTrue (rs.next());
+                assertEquals(rs.getString(1), "000000000000001");
+                assertEquals(rs.getString("\"order_id\""), "000000000000001");
+                assertEquals(rs.getString(2), "C4");
+                assertEquals(rs.getString("C.name"), "C4");
+                assertEquals(rs.getString(3), "T1");
+                assertEquals(rs.getString("iName"), "T1");
+                assertEquals(rs.getInt(4), 1000);
+                assertEquals(rs.getInt("Quantity"), 1000);
+                assertNotNull(rs.getDate(5));
+                assertTrue (rs.next());
+                assertEquals(rs.getString(1), "000000000000002");
+                assertEquals(rs.getString(2), "C3");
+                assertEquals(rs.getString(3), "T6");
+                assertEquals(rs.getInt(4), 2000);
+                assertNotNull(rs.getDate(5));
+                assertTrue (rs.next());
+                assertEquals(rs.getString(1), "000000000000003");
+                assertEquals(rs.getString(2), "C2");
+                assertEquals(rs.getString(3), "T2");
+                assertEquals(rs.getInt(4), 3000);
+                assertNotNull(rs.getDate(5));
+                assertTrue (rs.next());
+                assertEquals(rs.getString(1), "000000000000004");
+                assertEquals(rs.getString(2), "C4");
+                assertEquals(rs.getString(3), "T6");
+                assertEquals(rs.getInt(4), 4000);
+                assertNotNull(rs.getDate(5));
+                assertTrue (rs.next());
+                assertEquals(rs.getString(1), "000000000000005");
+                assertEquals(rs.getString(2), "C5");
+                assertEquals(rs.getString(3), "T3");
+                assertEquals(rs.getInt(4), 5000);
+                assertNotNull(rs.getDate(5));
 
-            assertFalse(rs.next());
+                assertFalse(rs.next());
+                
+                rs = conn.createStatement().executeQuery("EXPLAIN " + query[i]);
+                assertEquals(plans[11 + i], QueryUtil.getExplainPlan(rs));
+            }
         } finally {
             conn.close();
         }


[2/2] git commit: PHOENIX-68 Add Option "FAVOR_STAR_JOIN" to indicate if star join optimization is preferred for multi inner join queries

Posted by ma...@apache.org.
PHOENIX-68 Add Option "FAVOR_STAR_JOIN" to indicate if star join optimization is preferred for multi inner join queries


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

Branch: refs/heads/master
Commit: 67c9615161420e14ee92ce1acf570a0f92d2d70b
Parents: 8fe0dd9
Author: maryannxue <ma...@apache.org>
Authored: Fri Feb 21 19:23:59 2014 -0500
Committer: maryannxue <ma...@apache.org>
Committed: Fri Feb 21 19:23:59 2014 -0500

----------------------------------------------------------------------
 .../java/org/apache/phoenix/compile/JoinCompiler.java    | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/67c96151/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index 43b45c1..ef2b92e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -117,7 +117,6 @@ public class JoinCompiler {
             this.origResolver = resolver;
             List<AliasedNode> selectList = statement.getSelect();
             List<TableNode> tableNodes = statement.getFrom();
-            HintNode hint = statement.getHint();
             assert (tableNodes.size() > 1);
             Iterator<TableNode> iter = tableNodes.iterator();
             Iterator<TableRef> tableRefIter = resolver.getTables().iterator();
@@ -127,7 +126,7 @@ public class JoinCompiler {
             this.joinTables = new ArrayList<JoinTable>(tableNodes.size() - 1);
             this.preFilters = new ArrayList<ParseNode>();
             this.postFilters = new ArrayList<ParseNode>();
-            this.useStarJoin = !hint.hasHint(Hint.NO_STAR_JOIN);
+            this.useStarJoin = !statement.getHint().hasHint(Hint.NO_STAR_JOIN);
             this.tableRefToJoinTableMap = new HashMap<TableRef, JoinTable>();
             ColumnParseNodeVisitor generalRefVisitor = new ColumnParseNodeVisitor(resolver);
             ColumnParseNodeVisitor joinLocalRefVisitor = new ColumnParseNodeVisitor(resolver);
@@ -140,7 +139,7 @@ public class JoinCompiler {
                 if (!(tableNode instanceof JoinTableNode))
                     throw new SQLFeatureNotSupportedException("Implicit joins not supported.");
                 JoinTableNode joinTableNode = (JoinTableNode) tableNode;
-                JoinTable joinTable = new JoinTable(joinTableNode, tableRefIter.next(), selectList, hint, resolver);
+                JoinTable joinTable = new JoinTable(joinTableNode, tableRefIter.next(), statement, resolver);
                 for (ParseNode condition : joinTable.conditions) {
                     ComparisonParseNode comparisonNode = (ComparisonParseNode) condition;
                     comparisonNode.getLHS().accept(generalRefVisitor);
@@ -547,15 +546,15 @@ public class JoinCompiler {
         
         private Set<TableRef> leftTableRefs;
         
-        public JoinTable(JoinTableNode node, TableRef tableRef, List<AliasedNode> select, HintNode hint, ColumnResolver resolver) throws SQLException {
+        public JoinTable(JoinTableNode node, TableRef tableRef, SelectStatement statement, ColumnResolver resolver) throws SQLException {
             if (!(node.getTable() instanceof ConcreteTableNode))
                 throw new SQLFeatureNotSupportedException("Subqueries not supported.");
             
             this.type = node.getType();
             this.tableNode = node.getTable();
             this.table = tableRef;
-            this.select = extractFromSelect(select,tableRef,resolver);
-            this.hint = hint;
+            this.select = extractFromSelect(statement.getSelect(),tableRef,resolver);
+            this.hint = statement.getHint();
             this.preFilters = new ArrayList<ParseNode>();
             this.conditions = new ArrayList<ParseNode>();
             this.leftTableRefs = new HashSet<TableRef>();