ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [1/2] ignite git commit: master - fixes splitter push down
Date Wed, 07 Jun 2017 15:21:59 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 3a2797e2d -> d2efe78e1


master - fixes splitter push down


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

Branch: refs/heads/master
Commit: 8371e3adf453803b2eefe228adebaac3b42b3c0a
Parents: 86d0049
Author: Sergi Vladykin <sergi.vladykin@gmail.com>
Authored: Wed Jun 7 18:20:24 2017 +0300
Committer: Sergi Vladykin <sergi.vladykin@gmail.com>
Committed: Wed Jun 7 18:20:24 2017 +0300

----------------------------------------------------------------------
 .../query/h2/sql/GridSqlQuerySplitter.java      | 69 +++++++++++++++++++-
 .../query/IgniteSqlSplitterSelfTest.java        | 47 +++++++++++++
 2 files changed, 114 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/8371e3ad/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
index 1b9619e..e87a032 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
@@ -43,8 +43,10 @@ import org.apache.ignite.internal.processors.query.h2.H2Utils;
 import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2Table;
+import org.apache.ignite.internal.util.lang.GridTreePrinter;
 import org.apache.ignite.internal.util.tostring.GridToStringInclude;
 import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.X;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.h2.command.Prepared;
 import org.h2.command.dml.Query;
@@ -187,6 +189,8 @@ public class GridSqlQuerySplitter {
 
         String originalSql = qry.getSQL();
 
+//        debug("ORIGINAL", originalSql);
+
         final boolean explain = qry.explain();
 
         qry.explain(false);
@@ -197,6 +201,8 @@ public class GridSqlQuerySplitter {
         // Also it will collect all tables and schemas from the query.
         splitter.normalizeQuery(qry);
 
+//        debug("NORMALIZED", qry.getSQL());
+
         Connection conn = stmt.getConnection();
 
         // Here we will have correct normalized AST with optimized join order.
@@ -270,13 +276,19 @@ public class GridSqlQuerySplitter {
         // Setup the needed information for split.
         analyzeQueryModel(qrym);
 
+//        debug("ANALYZED", printQueryModel(qrym));
+
         // If we have child queries to split, then go hard way.
         if (qrym.needSplitChild) {
             // All the siblings to selects we are going to split must be also wrapped into
subqueries.
             pushDownQueryModel(qrym);
 
+//            debug("PUSHED_DOWN", printQueryModel(qrym));
+
             // Need to make all the joined subqueries to be ordered by join conditions.
             setupMergeJoinSorting(qrym);
+
+//            debug("SETUP_MERGE_JOIN", printQueryModel(qrym));
         }
         else if (!qrym.needSplit)  // Just split the top level query.
             setNeedSplit(qrym);
@@ -317,6 +329,20 @@ public class GridSqlQuerySplitter {
     }
 
     /**
+     * @param label Label.
+     * @param info Info.
+     * @deprecated Must be commented out.
+     */
+    @Deprecated
+    @SuppressWarnings("unused")
+    private static void debug(String label, String info) {
+        X.println();
+        X.println("  ==" + label + "== ");
+        X.println(info);
+        X.println("  ======== ");
+    }
+
+    /**
      * @param qrym Query model for the SELECT.
      */
     private void pushDownQueryModelSelect(QueryModel qrym) {
@@ -546,6 +572,8 @@ public class GridSqlQuerySplitter {
             // and mark that subquery as splittable.
             doPushDownQueryModelRange(qrym, begin, end, true);
         }
+
+//        debug("PUSH_DOWN_PARTIAL", printQueryModel(qrym));
     }
 
     /**
@@ -645,6 +673,9 @@ public class GridSqlQuerySplitter {
         int end,
         GridSqlAlias wrapAlias
     ) {
+        // Get the original SELECT.
+        GridSqlSelect select = qrym.ast();
+
         GridSqlSelect wrapSelect = GridSqlAlias.<GridSqlSubquery>unwrap(wrapAlias).subquery();
 
         final int last = qrym.size() - 1;
@@ -716,6 +747,7 @@ public class GridSqlQuerySplitter {
             wrapSelect.from(endJoin);
             afterBeginJoin.leftTable(beginJoin.rightTable());
             beginJoin.rightTable(wrapAlias);
+            select.from(beginJoin);
         }
         else if (begin == 0) {
             //  From the first model to some middle one.
@@ -780,8 +812,6 @@ public class GridSqlQuerySplitter {
             beginJoin.rightTable(wrapAlias);
         }
 
-        // Get the original SELECT.
-        GridSqlSelect select = qrym.ast();
         GridSqlAst from = select.from();
 
         // Push down related ON conditions for all the related joins.
@@ -2177,6 +2207,41 @@ public class GridSqlQuerySplitter {
     }
 
     /**
+     * @param root Root model.
+     * @return Tree as a string.
+     */
+    @SuppressWarnings("unused")
+    private String printQueryModel(QueryModel root) {
+        GridTreePrinter<QueryModel> mp = new GridTreePrinter<QueryModel>() {
+            /** {@inheritDoc} */
+            @Override protected List<QueryModel> getChildren(QueryModel m) {
+                return m;
+            }
+
+            /** {@inheritDoc} */
+            @Override protected String formatTreeNode(QueryModel m) {
+                return "[ " +(m.uniqueAlias == null ? "+" : m.uniqueAlias.alias()) +
+                    " -> " + m.type +
+                    " ns:" + m.needSplit + " nsch:" + m.needSplitChild +
+                    " ast: " + ast(m) +" ]";
+            }
+
+            private String ast(QueryModel m) {
+                if (m.prnt == null)
+                    return "-+-+-";
+
+                String ast = m.ast().getSQL().replace('\n', ' ');
+
+                int maxLen = 2000;
+
+                return ast.length() <= maxLen ? ast : ast.substring(0, maxLen);
+            }
+        };
+
+        return mp.print(root);
+    }
+
+    /**
      * Ensures all given queries have non-empty derived partitions and merges them.
      *
      * @param queries Collection of queries.

http://git-wip-us.apache.org/repos/asf/ignite/blob/8371e3ad/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
index d8f71a3..8b743bf 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
@@ -50,6 +50,7 @@ import org.apache.ignite.internal.processors.query.h2.twostep.GridMergeIndex;
 import org.apache.ignite.internal.util.GridRandom;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.X;
+import org.apache.ignite.internal.util.typedef.internal.SB;
 import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
@@ -164,6 +165,52 @@ public class IgniteSqlSplitterSelfTest extends GridCommonAbstractTest
{
 
     /**
      */
+    public void testPushDown() {
+        IgniteCache<Integer, Person> c = ignite(0).getOrCreateCache(cacheConfig("ps",
true,
+            Integer.class, Person.class));
+
+        try {
+            String subqry = "(select max(p.id) as id, p.depId from Person p group by p.depId)";
+
+            for (int i = 0; i < 5; i++) {
+                SB qry = new SB("select * from ");
+
+                for (int j = 0; j < 5; j++) {
+                    if (j != 0)
+                        qry.a(", ");
+
+                    if (j == i)
+                        qry.a(subqry);
+                    else
+                        qry.a("Person");
+
+                    qry.a(" p").a(j);
+                }
+
+                qry.a(" where");
+
+                for (int j = 1; j < 5; j++) {
+                    if (j != 1)
+                        qry.a(" and");
+
+                    qry.a(" p").a(j - 1).a(".id").a(" = ").a("p").a(j).a(".depId");
+                }
+
+                c.query(new SqlFieldsQuery(qry.toString())
+                    .setEnforceJoinOrder(true)).getAll();
+
+                X.println("\nPlan:\n" +
+                    c.query(new SqlFieldsQuery("explain " + qry.toString())
+                        .setEnforceJoinOrder(true)).getAll());
+            }
+        }
+        finally {
+            c.destroy();
+        }
+    }
+
+    /**
+     */
     public void testReplicatedTablesUsingPartitionedCache() {
         doTestReplicatedTablesUsingPartitionedCache(1, false, false);
     }


Mime
View raw message