Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] Fix incorrect execution plan when generated column rewrite in join relation if left table and right table has the same column name (backport #52584) #52639

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/qe/SessionVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,20 @@ 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";

<<<<<<< HEAD
=======
public static final String CONNECTOR_REMOTE_FILE_ASYNC_QUEUE_SIZE = "connector_remote_file_async_queue_size";
public static final String CONNECTOR_REMOTE_FILE_ASYNC_TASK_SIZE = "connector_remote_file_async_task_size";
public static final String ENABLE_CONNECTOR_INCREMENTAL_SCAN_RANGES = "enable_connector_incremental_scan_ranges";
public static final String CONNECTOR_INCREMENTAL_SCAN_RANGE_SIZE = "connector_incremental_scan_ranges_size";

public static final String ENABLE_PLAN_ANALYZER = "enable_plan_analyzer";

public static final String ENABLE_PLAN_ADVISOR = "enable_plan_advisor";

public static final String DISABLE_GENERATED_COLUMN_REWRITE = "disable_generated_column_rewrite";

>>>>>>> af20339fc0 ([BugFix] Fix incorrect execution plan when generated column rewrite in join relation if left table and right table has the same column name (#52584))
public static final List<String> DEPRECATED_VARIABLES = ImmutableList.<String>builder()
.add(CODEGEN_LEVEL)
.add(MAX_EXECUTION_TIME)
Expand Down Expand Up @@ -1344,6 +1358,55 @@ public static MaterializedViewRewriteMode parse(String str) {
@VarAttr(name = ENABLE_HYPERSCAN_VEC)
private boolean enableHyperscanVec = true;

<<<<<<< HEAD
=======
@VarAttr(name = ENABLE_PLAN_ANALYZER, flag = VariableMgr.INVISIBLE)
private boolean enablePlanAnalyzer = false;

@VarAttr(name = ENABLE_PLAN_ADVISOR)
private boolean enablePlanAdvisor = true;

@VarAttr(name = COUNT_DISTINCT_IMPLEMENTATION)
private String countDistinctImplementation = "default";

// By default, we always use the created mv's bitmap/hll to rewrite count distinct, but result is not
// exactly matched with the original result.
// If we want to get the exactly matched result, we can disable this.
@VarAttr(name = ENABLE_COUNT_DISTINCT_REWRITE_BY_HLL_BITMAP)
private boolean enableCountDistinctRewriteByHllBitmap = true;

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

public int getCboPruneJsonSubfieldDepth() {
return cboPruneJsonSubfieldDepth;
}

public void setCboPruneJsonSubfieldDepth(int cboPruneJsonSubfieldDepth) {
this.cboPruneJsonSubfieldDepth = cboPruneJsonSubfieldDepth;
}

public boolean isEnableExecutionOnly() {
return enableExecutionOnly;
}

public boolean isCboPruneJsonSubfield() {
return cboPruneJsonSubfield;
}

public void setCboPruneJsonSubfield(boolean cboPruneJsonSubfield) {
this.cboPruneJsonSubfield = cboPruneJsonSubfield;
}

public void setEnableArrayLowCardinalityOptimize(boolean enableArrayLowCardinalityOptimize) {
this.enableArrayLowCardinalityOptimize = enableArrayLowCardinalityOptimize;
}

public boolean isEnableArrayLowCardinalityOptimize() {
return enableArrayLowCardinalityOptimize;
}

>>>>>>> af20339fc0 ([BugFix] Fix incorrect execution plan when generated column rewrite in join relation if left table and right table has the same column name (#52584))
@VarAttr(name = ENABLE_REWRITE_BITMAP_UNION_TO_BITMAP_AGG)
private boolean enableRewriteBitmapUnionToBitmapAgg = true;

Expand Down Expand Up @@ -3530,8 +3593,77 @@ public void setLikePredicateConsolidateMin(int value) {
this.likePredicateConsolidateMin = value;
}

<<<<<<< HEAD
public void setEnableConnectorSplitIoTasks(boolean v) {
enableConnectorSplitIoTasks = v;
=======
public String getCustomQueryId() {
return customQueryId;
}

public void setCustomQueryId(String customQueryId) {
this.customQueryId = customQueryId;
}

public int getConnectorRemoteFileAsyncQueueSize() {
return connectorRemoteFileAsyncQueueSize;
}

public int getConnectorRemoteFileAsyncTaskSize() {
return connectorRemoteFileAsyncTaskSize;
}

public boolean isEnablePlanAnalyzer() {
return enablePlanAnalyzer;
}

public void setEnablePlanAnalyzer(boolean enablePlanAnalyzer) {
this.enablePlanAnalyzer = enablePlanAnalyzer;
}

public boolean isEnablePlanAdvisor() {
return enablePlanAdvisor;
}

public void setEnablePlanAdvisor(boolean enablePlanAdvisor) {
this.enablePlanAdvisor = enablePlanAdvisor;
}

public void setCountDistinctImplementation(String countDistinctImplementation) {
this.countDistinctImplementation = countDistinctImplementation;
}

public SessionVariableConstants.CountDistinctImplMode getCountDistinctImplementation() {
return SessionVariableConstants.CountDistinctImplMode.parse(countDistinctImplementation);
}

public boolean isEnableCountDistinctRewriteByHllBitmap() {
return enableCountDistinctRewriteByHllBitmap;
}

public void setEnableCountDistinctRewriteByHllBitmap(boolean enableCountDistinctRewriteByHllBitmap) {
this.enableCountDistinctRewriteByHllBitmap = enableCountDistinctRewriteByHllBitmap;
}

public boolean isDisableGeneratedColumnRewrite() {
return disableGeneratedColumnRewrite;
}

public int getConnectorIncrementalScanRangeNumber() {
return connectorIncrementalScanRangeSize;
}

public void setConnectorIncrementalScanRangeNumber(int v) {
connectorIncrementalScanRangeSize = v;
}

public boolean isEnableConnectorIncrementalScanRanges() {
return enableConnectorIncrementalScanRanges;
}

public void setEnableConnectorIncrementalScanRanges(boolean v) {
enableConnectorIncrementalScanRanges = v;
>>>>>>> af20339fc0 ([BugFix] Fix incorrect execution plan when generated column rewrite in join relation if left table and right table has the same column name (#52584))
}

// Serialize to thrift object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,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 @@ -2537,6 +2537,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
Loading