You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by am...@apache.org on 2022/01/11 12:36:42 UTC
[ignite] 02/02: Fix the bug.
This is an automated email from the ASF dual-hosted git repository.
amashenkov pushed a commit to branch ignite-16261
in repository https://gitbox.apache.org/repos/asf/ignite.git
commit 770557048ddf4208cfc4df1ef2941450f440fac7
Author: Andrew Mashenkov <an...@gmail.com>
AuthorDate: Tue Jan 11 15:35:04 2022 +0300
Fix the bug.
---
.../processors/cache/query/GridCacheSqlQuery.java | 18 +++++++++++-------
.../processors/cache/query/GridCacheTwoStepQuery.java | 1 +
.../processors/query/h2/sql/GridSqlQuerySplitter.java | 6 ++++--
.../processors/query/h2/sql/SqlAstTraverser.java | 15 +++++++++++++++
4 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlQuery.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlQuery.java
index 9a837bb..4c1d8c2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlQuery.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlQuery.java
@@ -82,7 +82,7 @@ public class GridCacheSqlQuery implements Message {
/** Flag indicating that the query contains an OUTER JOIN from REPLICATED to PARTITIONED. */
@GridToStringInclude
@GridDirectTransient
- private transient boolean hasOuterJoinReplicatedPartitioned;
+ private transient boolean treatPartitionedAsReplicated;
/**
* For {@link Message}.
@@ -375,19 +375,23 @@ public class GridCacheSqlQuery implements Message {
}
/**
- * @return {@code true} if the query contains an OUTER JOIN from REPLICATED to PARTITIONED.
+ * @return {@code true} if the query contains an OUTER JOIN from REPLICATED to PARTITIONED, or
+ * outer query over REPLICATED cache has a subquery over PARTIITIONED.
*/
- public boolean hasOuterJoinReplicatedPartitioned() {
- return hasOuterJoinReplicatedPartitioned;
+ public boolean treatReplicatedAsPartitioned() {
+ return treatPartitionedAsReplicated;
}
/**
- * @param hasOuterJoinReplicatedPartitioned Flag indicating that the query contains an OUTER JOIN from REPLICATED to PARTITIONED.
+ * Set flag to {@code true} when query contains an OUTER JOIN from REPLICATED to PARTITIONED, or
+ * outer query over REPLICATED cache has a subquery over PARTIITIONED.
*
+ * @param trearPartitionedAsReplicated Flag indicating that the replicated cache in outer query must be treat
+ * as partitioned.
* @return {@code this}.
*/
- public GridCacheSqlQuery hasOuterJoinReplicatedPartitioned(boolean hasOuterJoinReplicatedPartitioned) {
- this.hasOuterJoinReplicatedPartitioned = hasOuterJoinReplicatedPartitioned;
+ public GridCacheSqlQuery treatReplicatedAsPartitioned(boolean trearPartitionedAsReplicated) {
+ this.treatPartitionedAsReplicated = trearPartitionedAsReplicated;
return this;
}
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java
index 85a50b4..ab97678 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java
@@ -86,6 +86,7 @@ public class GridCacheTwoStepQuery {
* @param cacheIds Cache ids.
* @param mvccEnabled Mvcc flag.
* @param locSplit Local split flag.
+ * @param treatReplicatedAsPartitioned Treat replicated as partitioned flag.
*/
public GridCacheTwoStepQuery(
String originalSql,
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 f0e3f14..5f253ab 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
@@ -320,7 +320,7 @@ public class GridSqlQuerySplitter {
List<Integer> cacheIds = H2Utils.collectCacheIds(idx, null, splitter.tbls);
boolean mvccEnabled = H2Utils.collectMvccEnabled(idx, cacheIds);
boolean replicatedOnly = splitter.mapSqlQrys.stream().noneMatch(GridCacheSqlQuery::isPartitioned);
- boolean treatReplicatedAsPartitioned = splitter.mapSqlQrys.stream().anyMatch(GridCacheSqlQuery::hasOuterJoinReplicatedPartitioned);
+ boolean treatReplicatedAsPartitioned = splitter.mapSqlQrys.stream().anyMatch(GridCacheSqlQuery::treatReplicatedAsPartitioned);
H2Utils.checkQuery(idx, cacheIds, splitter.tbls);
@@ -1280,7 +1280,9 @@ public class GridSqlQuerySplitter {
map.sortColumns(mapQry.sort());
map.partitioned(traverser.hasPartitionedTables());
map.hasSubQueries(traverser.hasSubQueries());
- map.hasOuterJoinReplicatedPartitioned(traverser.hasOuterJoinReplicatedPartitioned());
+ map.treatReplicatedAsPartitioned(
+ traverser.hasOuterJoinReplicatedPartitioned() || traverser.hasReplicatedWithPartitionedAndSubQuery()
+ );
if (map.isPartitioned() && canExtractPartitions)
map.derivedPartitions(extractor.extract(mapQry));
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/SqlAstTraverser.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/SqlAstTraverser.java
index 08feecd..f854c3f 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/SqlAstTraverser.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/SqlAstTraverser.java
@@ -44,6 +44,9 @@ class SqlAstTraverser {
/** Whether query has joins between replicated and partitioned tables. */
private boolean hasOuterJoinReplicatedPartitioned;
+ /** Whether top-level table is replicated. */
+ private boolean isRootTableReplicated;
+
/** */
SqlAstTraverser(GridSqlAst root, boolean distributedJoins, IgniteLogger log) {
this.root = root;
@@ -53,6 +56,13 @@ class SqlAstTraverser {
/** */
public void traverse() {
+ if (root instanceof GridSqlSelect) {
+ GridSqlTable table = getTable(((GridSqlSelect)root).from().child());
+
+ if (table != null && !table.dataTable().isPartitioned())
+ isRootTableReplicated = true;
+ }
+
lookForPartitionedJoin(root, null);
}
@@ -71,6 +81,11 @@ class SqlAstTraverser {
return hasOuterJoinReplicatedPartitioned;
}
+ /** */
+ public boolean hasReplicatedWithPartitionedAndSubQuery() {
+ return (isRootTableReplicated && hasSubQueries && hasPartitionedTables);
+ }
+
/**
* Traverse AST while join operation isn't found. Check it if found.
*