Skip to content

Commit

Permalink
[BugFix] Fix incorrect execution plan when generated column rewrite i…
Browse files Browse the repository at this point in the history
…n join relation if left table and right table has the same column name (#52584)

Signed-off-by: srlch <[email protected]>
  • Loading branch information
srlch committed Nov 5, 2024
1 parent 2065515 commit 3edc14a
Show file tree
Hide file tree
Showing 7 changed files with 701 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,8 @@ public static MaterializedViewRewriteMode parse(String str) {
// regexp predicate is less efficient than like predicates.
public static final String LIKE_PREDICATE_CONSOLIDATE_MIN = "like_predicate_consolidate_min";

public static final String DISABLE_GENERATED_COLUMN_REWRITE = "disable_generated_column_rewrite";

public static final List<String> DEPRECATED_VARIABLES = ImmutableList.<String>builder()
.add(CODEGEN_LEVEL)
.add(MAX_EXECUTION_TIME)
Expand Down Expand Up @@ -1520,6 +1522,9 @@ public static MaterializedViewRewriteMode parse(String str) {
@VarAttr(name = ENABLE_HYPERSCAN_VEC)
private boolean enableHyperscanVec = true;

@VarAttr(name = DISABLE_GENERATED_COLUMN_REWRITE, flag = VariableMgr.INVISIBLE)
private boolean disableGeneratedColumnRewrite = false;

public int getCboPruneJsonSubfieldDepth() {
return cboPruneJsonSubfieldDepth;
}
Expand Down Expand Up @@ -4037,6 +4042,10 @@ public void setLikePredicateConsolidateMin(int value) {
this.likePredicateConsolidateMin = value;
}

public boolean isDisableGeneratedColumnRewrite() {
return disableGeneratedColumnRewrite;
}

// Serialize to thrift object
// used for rest api
public TQueryOptions toThrift() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public GeneratedColumnExprMappingCollector() {
}

public Void process(ParseNode node, Scope scope) {
if (session.getSessionVariable().isDisableGeneratedColumnRewrite()) {
return null;
}
return node.accept(this, scope);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ public ReplaceScalarOperatorRule(Map<ScalarOperator, ColumnRefOperator> translat

@Override
public ScalarOperator visit(ScalarOperator scalarOperator, ScalarOperatorRewriteContext context) {
for (Map.Entry<ScalarOperator, ColumnRefOperator> m : translateMap.entrySet()) {
if (ScalarOperator.isEquivalent(m.getKey(), scalarOperator)) {
return m.getValue();
}
if (translateMap.containsKey(scalarOperator)) {
return translateMap.get(scalarOperator);
}

return scalarOperator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ public void test() throws Exception {
assertContains(plan, "OUTPUT EXPRS:5: expr");
assertContains(plan, " group by: 1: v1, 2: v2");

sql = " select tmc.v1 + 1 from tmc as v,tmc2 as tmc";
sql = " select v.v1 + 1 from tmc as v,tmc2 as tmc";
plan = getFragmentPlan(sql);
assertContains(plan, "<slot 3> : 3: v3");

sql = " select tmc.v1 + 1 from tmc as v,tmc2 as tmc";
sql = " select v.v1 + 1 from tmc as v,tmc2 as tmc";
plan = getFragmentPlan(sql);
assertContains(plan, "<slot 3> : 3: v3");

Expand Down
10 changes: 10 additions & 0 deletions test/lib/sr_sql_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2540,6 +2540,16 @@ def set_first_tablet_bad_and_recover(self, table_name):
else:
break

def assert_is_identical_explain_plan(self, query1, query2):
"""
assert whether two plans from query1 and query2 are identical
"""
sql1 = "explain %s" % query1
sql2 = "explain %s" % query2
res1 = self.execute_sql(sql1, True)
res2 = self.execute_sql(sql2, True)
tools.assert_true(res1 == res2, "assert two plans are different, plan1: {}, plan2: {}".format(res1["result"], res2["result"]))

def assert_explain_contains(self, query, *expects):
"""
assert explain result contains expect string
Expand Down
Loading

0 comments on commit 3edc14a

Please sign in to comment.