executor: Fix a panic when using on duplicate update (#31287) #31458
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.
cherry-pick #31287 to release-5.0-20220107 (hotfix to 5.0.6)
What problem does this PR solve?
Issue Number: close #28078
Problem Summary: When using statements like
insert into a select ... from b on duplicate key update a.y = b.y
, where b.y is not selected inselect ... from b
part, sometimes it may panic and reports "slice bounds out of range".initEvalBuffer4Dup
constructs a list of column types (theevalBufferTypes
variable), which is expected to match theSchema4OnDuplicate
built in functionSchema4OnDuplicate
. It contains several parts sequentially:on duplicate key update
clause)The problem is:
evalBufferTypes
, wrong index is used to find the second part (extra columns to select) . The inner select plan contains both explicitly written columns inselect
clause (which are columns[:actualColLen]
), and the implicitly required columns in theon duplicate key update
clause (which are columns[actualColLen:]
). In functioninitEvalBuffer4Dup
, theactualColLen
is exactlye.rowLen
.evalBufferTypes
mentioned above. However wrong index is used again and it didn't count the number of extra columns to the offset.What is changed and how it works?
Fixed the above two mistakes.
Check List
Tests
Side effects
Documentation
Release note