[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) #52638
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why I'm doing:
This problem is introduced by pr #50398. In this pr, we introduce some new rule for generated column rewriting. The basic idea is following:
SELECT
scope in query. (Expr
->SlotRef
)ScalarOperator
->ColumnRefOperator
ReplaceScalarOperatorRule
, use this new rule to replace theScalarOperator
byColumnRefOperator
when generating the logical plan in optimizer.This problem is that,
ReplaceScalarOperatorRule
useScalarOperator.isEquivalent
to check if aScalarOperator
hit the rule instead of usingScalarOperator.equals
.ScalarOperator.isEquivalent
does not check the operator id but this id will be used to identify the column with the same column name but come from different table in JOIN relation. (e.g column xx inTABLE A
and column xx inTABLE B
has same name but different id, in this case,ScalarOperator.isEquivalent
return true butScalarOperator.equals
return false). So in this case, we will get the wrong mapping and generated a incorrect plan for generated column rewrite.What I'm doing:
ScalarOperator.equals
insteadFixes #issue
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check:
This is an automatic backport of pull request #52584 done by [Mergify](https://mergify.com). ## Why I'm doing: This problem is introduced by pr #50398. In this pr, we introduce some new rule for generated column rewriting. The basic idea is following: 1. Collect the rewriting relation in every `SELECT` scope in query. (`Expr` -> `SlotRef`) 2. Translate the expression relation into Operator mapping: `ScalarOperator` -> `ColumnRefOperator` 3. Introduce new rule says `ReplaceScalarOperatorRule`, use this new rule to replace the `ScalarOperator` by `ColumnRefOperator` when generating the logical plan in optimizer.
This problem is that,
ReplaceScalarOperatorRule
useScalarOperator.isEquivalent
to check if aScalarOperator
hit the rule instead of usingScalarOperator.equals
.ScalarOperator.isEquivalent
does not check the operator id but this id will be used to identify the column with the same column name but come from different table in JOIN relation. (e.g column xx inTABLE A
and column xx inTABLE B
has same name but different id, in this case,ScalarOperator.isEquivalent
return true butScalarOperator.equals
return false). So in this case, we will get the wrong mapping and generated a incorrect plan for generated column rewrite.What I'm doing:
ScalarOperator.equals
insteadFixes #issue
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist: