-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
executor: fix a bug of update with outer join #7177
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4688629
executor: fix a bug of update with outer join
lysu cf5d42f
executor: modify updateExec instead of schema.
lysu eee7bc5
executor: use new column identify.
lysu 36dabb0
executor: use new column identify.
lysu be85e6e
executor: use table alias and fix update reference column bug.
lysu 3dfef7a
executor: optimize no match mark index & address comments.
lysu ea7b387
executor: address comments.
lysu 588bd6d
executor: address comments/handle update no match fill out of updateR…
lysu 9d1e212
executor: address comments/use handle column is nil to detect filled …
lysu 9907e7d
executor: skip buildColumns2Handle if there are no join.
lysu b0782e9
executor: address comment.
lysu cae1651
executor: address comment.
lysu 7c0f2dc
executor: address comment.
lysu 17cb430
executor: address comment.
lysu b935b3b
executor: address comment.
lysu de5d250
executor: address comment.
lysu a43eed8
executor: address comment.
lysu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1236,15 +1236,76 @@ func (b *executorBuilder) buildUpdate(v *plan.Update) Executor { | |
b.err = errors.Trace(b.err) | ||
return nil | ||
} | ||
columns2Handle := buildColumns2Handle(v.Schema(), tblID2table) | ||
updateExec := &UpdateExec{ | ||
baseExecutor: newBaseExecutor(b.ctx, nil, v.ExplainID(), selExec), | ||
SelectExec: selExec, | ||
OrderedList: v.OrderedList, | ||
tblID2table: tblID2table, | ||
baseExecutor: newBaseExecutor(b.ctx, nil, v.ExplainID(), selExec), | ||
SelectExec: selExec, | ||
OrderedList: v.OrderedList, | ||
tblID2table: tblID2table, | ||
columns2Handle: columns2Handle, | ||
} | ||
return updateExec | ||
} | ||
|
||
// cols2Handle represents an mapper from column index to handle index. | ||
type cols2Handle struct { | ||
// start/end represent the ordinal range [start, end) of the consecutive columns. | ||
start, end int32 | ||
// handleOrdinal represents the ordinal of the handle column. | ||
handleOrdinal int32 | ||
} | ||
|
||
// cols2HandleSlice attaches the methods of sort.Interface to []cols2Handle sorting in increasing order. | ||
type cols2HandleSlice []cols2Handle | ||
|
||
// Len implements sort.Interface#Len. | ||
func (c cols2HandleSlice) Len() int { | ||
return len(c) | ||
} | ||
|
||
// Swap implements sort.Interface#Swap. | ||
func (c cols2HandleSlice) Swap(i, j int) { | ||
c[i], c[j] = c[j], c[i] | ||
} | ||
|
||
// Less implements sort.Interface#Less. | ||
func (c cols2HandleSlice) Less(i, j int) bool { | ||
return c[i].start < c[j].start | ||
} | ||
|
||
// findHandle finds the ordinal of the corresponding handle column. | ||
func (c cols2HandleSlice) findHandle(ordinal int32) (int32, bool) { | ||
if c == nil || len(c) == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if c == nil, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. receiver is slice(point), so it's ok |
||
return 0, false | ||
} | ||
// find the smallest index of the range that its start great than ordinal. | ||
// @see https://godoc.org/sort#Search | ||
rangeBehindOrdinal := sort.Search(len(c), func(i int) bool { return c[i].start > ordinal }) | ||
if rangeBehindOrdinal == 0 { | ||
return 0, false | ||
} | ||
return c[rangeBehindOrdinal-1].handleOrdinal, true | ||
} | ||
|
||
// buildColumns2Handle builds columns to handle mapping. | ||
func buildColumns2Handle(schema *expression.Schema, tblID2Table map[int64]table.Table) cols2HandleSlice { | ||
if len(schema.TblID2Handle) < 2 { | ||
// skip buildColumns2Handle mapping if there are only single table. | ||
return nil | ||
} | ||
var cols2Handles cols2HandleSlice | ||
for tblID, handleCols := range schema.TblID2Handle { | ||
tbl := tblID2Table[tblID] | ||
for _, handleCol := range handleCols { | ||
offset := getTableOffset(schema, handleCol) | ||
end := offset + len(tbl.WritableCols()) | ||
cols2Handles = append(cols2Handles, cols2Handle{int32(offset), int32(end), int32(handleCol.Index)}) | ||
} | ||
} | ||
sort.Sort(cols2Handles) | ||
return cols2Handles | ||
} | ||
|
||
func (b *executorBuilder) buildDelete(v *plan.Delete) Executor { | ||
tblID2table := make(map[int64]table.Table) | ||
for id := range v.SelectPlan.Schema().TblID2Handle { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.