Skip to content

Commit

Permalink
Revert changes in CollocationModel
Browse files Browse the repository at this point in the history
  • Loading branch information
timoninmaxim committed Apr 9, 2021
1 parent 09197ea commit 7e41ae0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,6 @@ public GridCacheSqlQuery hasOuterJoinReplicatedPartitioned(boolean hasOuterJoinR
return this;
}

/**
* @return {@code true} if the query contains JOIN.
*/
public boolean hasJoin() {
return hasJoin;
}

/***
* @return {@code this}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,18 @@ private TableFilter filter() {

/** {@inheritDoc} */
@Override public String toString() {
return "";
calculate();

SB b = new SB();

for (int lvl = 0; lvl < 20; lvl++) {
if (!toString(b, lvl))
break;

b.a('\n');
}

return b.toString();
}

/**
Expand Down Expand Up @@ -415,21 +426,13 @@ private CollocationModelAffinity joinedWithCollocated(int f) {

if (t.isPartitioned() && t.isCollocated() && isAffinityColumn(prevJoin, expCol, validate))
return CollocationModelAffinity.COLLOCATED_JOIN;
else {
if (validate && !SplitterContext.get().distributedJoins())
throw new CacheException("Failed to prepare join query: " +
"join is not collocated [joinedCache=" + tbl.cacheName() +
", plan=" + tf.getSelect().getPlanSQL() + ']');
}
}
}
}
}
}
}

// TODO: check query like A join B on A.v > B.v?

return affKeyCondFound ? CollocationModelAffinity.HAS_AFFINITY_CONDITION : CollocationModelAffinity.NONE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,34 +293,29 @@ private static GridCacheTwoStepQuery split0(
assert !F.isEmpty(splitter.mapSqlQrys) : "map"; // We must have at least one map query.
assert splitter.rdcSqlQry != null : "rdc"; // We must have a reduce query.

boolean allCollocated = true;
// If we have distributed joins, then we have to optimize all MAP side queries
// to have a correct join order with respect to batched joins and check if we need
// distributed joins at all.
if (distributedJoins) {
boolean allCollocated = true;

for (GridCacheSqlQuery mapSqlQry : splitter.mapSqlQrys) {
if (distributedJoins || mapSqlQry.hasJoin()) {
for (GridCacheSqlQuery mapSqlQry : splitter.mapSqlQrys) {
Prepared prepared0 = prepare(
conn,
H2Utils.context(conn),
mapSqlQry.query(),
true,
enforceJoinOrder);

// TODO: Check isCollocated for non-distributed join queries too.
// But before that check whether query contains join expression.
// There is no chances to find bad join before that. As in preparing query we calculate cost
// that runs with disabled validation.
allCollocated &= isCollocated((Query)prepared0);

// If we have distributed joins, then we have to optimize all MAP side queries
// to have a correct join order with respect to batched joins and check if we need
// distributed joins at all.
if (distributedJoins)
mapSqlQry.query(GridSqlQueryParser.parseQuery(prepared0, true, log).getSQL());
mapSqlQry.query(GridSqlQueryParser.parseQuery(prepared0, true, log).getSQL());
}
}

// We do not need distributed joins if all MAP queries are collocated.
if (allCollocated)
distributedJoins = false;
// We do not need distributed joins if all MAP queries are collocated.
if (allCollocated)
distributedJoins = false;
}

List<Integer> cacheIds = H2Utils.collectCacheIds(idx, null, splitter.tbls);
boolean mvccEnabled = H2Utils.collectMvccEnabled(idx, cacheIds);
Expand Down

0 comments on commit 7e41ae0

Please sign in to comment.