[BugFix] fix slot id conflicts in array_map (backport #52692) #52759
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:
What I'm doing:
Before we rewrite the lambda expression, we need to find the max slot id currently used, and the slot id of new rewritten
ColumnRef
needs to be allocated from then on.In the previous implementation, max_used_slot_id only counts the slot ids used in the lambda expression.
If multiple children of the same expression contain lambda expression, such as
coalesce(element_at(array_map(x->x+any_match(array_map(x->x<10,arr_1)), arr_1), 1),element_at(array_map(x->x+any_match(array_map(x->x<10,arr_2)), arr_2),1))
, then there is a possibility of duplicate allocation of slot ids.In this PR, I made some changes to avoid this problem:
Note: This is just a temporary solution and a bit ugly. When we support expression reuse strategy of scan predicates, the slot id allocation of common expressions will be handed over to FE, which has a global perspective and will definitely ensure that there will be no duplicate allocations. This is the most elegant solution. I will support it later.
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 #52692 done by [Mergify](https://mergify.com). ## Why I'm doing:
What I'm doing:
Before we rewrite the lambda expression, we need to find the max slot id currently used, and the slot id of new rewritten
ColumnRef
needs to be allocated from then on.In the previous implementation, max_used_slot_id only counts the slot ids used in the lambda expression.
If multiple children of the same expression contain lambda expression, such as
coalesce(element_at(array_map(x->x+any_match(array_map(x->x<10,arr_1)), arr_1), 1),element_at(array_map(x->x+any_match(array_map(x->x<10,arr_2)), arr_2),1))
, then there is a possibility of duplicate allocation of slot ids.In this PR, I made some changes to avoid this problem:
Note: This is just a temporary solution and a bit ugly. When we support expression reuse strategy of scan predicates, the slot id allocation of common expressions will be handed over to FE, which has a global perspective and will definitely ensure that there will be no duplicate allocations. This is the most elegant solution. I will support it later.
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist: