Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 89FC6200CB0 for ; Thu, 8 Jun 2017 14:33:01 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 88E10160BE5; Thu, 8 Jun 2017 12:33:01 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A1D9F160BE7 for ; Thu, 8 Jun 2017 14:32:59 +0200 (CEST) Received: (qmail 19929 invoked by uid 500); 8 Jun 2017 12:32:58 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 19511 invoked by uid 99); 8 Jun 2017 12:32:57 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Jun 2017 12:32:57 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C0690F4A51; Thu, 8 Jun 2017 12:32:54 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: akuznetsov@apache.org To: commits@ignite.apache.org Date: Thu, 08 Jun 2017 12:33:25 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [32/43] ignite git commit: master - fixes splitter push down archived-at: Thu, 08 Jun 2017 12:33:01 -0000 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/ignite-5414 Commit: 8371e3adf453803b2eefe228adebaac3b42b3c0a Parents: 86d0049 Author: Sergi Vladykin Authored: Wed Jun 7 18:20:24 2017 +0300 Committer: Sergi Vladykin 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.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 mp = new GridTreePrinter() { + /** {@inheritDoc} */ + @Override protected List 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 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); }