Skip to content

Commit

Permalink
IGNITE-13019 Fix incorrect JOIN when querying a single-node cluster (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
timoninmaxim committed Aug 16, 2021
1 parent 0ab70da commit 8088d99
Show file tree
Hide file tree
Showing 5 changed files with 850 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ public class GridSqlQuerySplitter {
/** Whether partition extraction is possible. */
private final boolean canExtractPartitions;

/** Distributed joins flag. */
private final boolean distributedJoins;

/** Ignite logger. */
private final IgniteLogger log;

/** */
private final IdentityHashMap<GridSqlAst, GridSqlAlias> uniqueFromAliases = new IdentityHashMap<>();

Expand All @@ -144,11 +150,14 @@ public GridSqlQuerySplitter(
boolean collocatedGrpBy,
boolean distributedJoins,
boolean locSplit,
PartitionExtractor extractor
PartitionExtractor extractor,
IgniteLogger log
) {
this.paramsCnt = paramsCnt;
this.collocatedGrpBy = collocatedGrpBy;
this.extractor = extractor;
this.distributedJoins = distributedJoins;
this.log = log;

// Partitions *CANNOT* be extracted if:
// 1) Distributed joins are enabled (https://issues.apache.org/jira/browse/IGNITE-10971)
Expand Down Expand Up @@ -263,7 +272,8 @@ private static GridCacheTwoStepQuery split0(
collocatedGrpBy,
distributedJoins,
locSplit,
idx.partitionExtractor()
idx.partitionExtractor(),
log
);

// Normalization will generate unique aliases for all the table filters in FROM.
Expand Down Expand Up @@ -1263,11 +1273,14 @@ private void splitSelect(GridSqlAst parent, int childIdx) throws IgniteCheckedEx

setupParameters(map, mapQry, paramsCnt);

SqlAstTraverser traverser = new SqlAstTraverser(mapQry, distributedJoins, log);
traverser.traverse();

map.columns(collectColumns(mapExps));
map.sortColumns(mapQry.sort());
map.partitioned(SplitterUtils.hasPartitionedTables(mapQry));
map.hasSubQueries(SplitterUtils.hasSubQueries(mapQry));
map.hasOuterJoinReplicatedPartitioned(SplitterUtils.hasOuterJoinReplicatedPartitioned(mapQry.from()));
map.partitioned(traverser.hasPartitionedTables());
map.hasSubQueries(traverser.hasSubQueries());
map.hasOuterJoinReplicatedPartitioned(traverser.hasOuterJoinReplicatedPartitioned());

if (map.isPartitioned() && canExtractPartitions)
map.derivedPartitions(extractor.extract(mapQry));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,35 +164,6 @@ public static boolean hasLeftJoin(GridSqlAst from) {
return false;
}

/**
* Checks whether the expression has an OUTER JOIN from replicated to partitioned.
*
* This is used to infer the `treatReplicatedAsPartitioned` flag
* to eventually pass it to {@link org.apache.ignite.spi.indexing.IndexingQueryFilterImpl}.
*
* @param from FROM expression.
* @return {@code true} if the expression has an OUTER JOIN from replicated to partitioned.
*/
public static boolean hasOuterJoinReplicatedPartitioned(GridSqlAst from) {
boolean isRightPartitioned = false;
while (from instanceof GridSqlJoin) {
GridSqlJoin join = (GridSqlJoin)from;

assert !(join.rightTable() instanceof GridSqlJoin);

isRightPartitioned = isRightPartitioned || hasPartitionedTables(join.rightTable());

if (join.isLeftOuter()) {
boolean isLeftPartitioned = hasPartitionedTables(join.leftTable());
return !isLeftPartitioned && isRightPartitioned;
}

from = join.leftTable();
}

return false;
}

/**
* @param ast Reduce query AST.
* @param rdcQry Reduce query string.
Expand Down

0 comments on commit 8088d99

Please sign in to comment.