fix(vdiff): preserve PK definition order in getSourcePKCols - #905
Open
pedroalb wants to merge 1 commit into
Open
fix(vdiff): preserve PK definition order in getSourcePKCols#905pedroalb wants to merge 1 commit into
pedroalb wants to merge 1 commit into
Conversation
The getSourcePKCols function put PrimaryKeyColumns into a map (losing order) then iterated td.table.Columns in ORDINAL_POSITION order. This produced sourcePkCols in column ordinal order rather than PK definition order (SEQ_IN_INDEX). On VDiff resume, VStreamRows receives the wrongly-ordered lastpk values and the row streamer pairs them positionally with its own pkColumns (which ARE in correct SEQ_IN_INDEX order). This corrupts the WHERE clause and generates false ExtraRowsSource/ExtraRowsTarget reports. Fix: build a column-name-to-index map and iterate PrimaryKeyColumns in definition order, preserving SEQ_IN_INDEX ordering. Upstream PR: vitessio#20603 Related issue: vitessio#20601 Signed-off-by: Pedro Albuquerque <pedroalb@gmail.com> Signed-off-by: Pedro Albuquerque <pedro.albuquerque@slack-corp.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
getSourcePKColsto preserve PK definition order (SEQ_IN_INDEX) instead of column ordinal positionRoot Cause
getSourcePKColsputPrimaryKeyColumnsinto amap[string]struct{}(losing order), then iteratedtd.table.ColumnsinORDINAL_POSITIONorder. On VDiff resume,VStreamRowsreceives the wrongly-orderedlastpkvalues and the row streamer pairs them positionally with its ownpkColumns(which ARE in correct SEQ_IN_INDEX order fromBaseShowPrimary). This corrupts the WHERE clause.Fix
Replace the map+ordinal-scan with a column index lookup that preserves PK definition order.
Impact
Only affects tables where PK column order differs from column ordinal position AND VDiff resumes (via
max-diff-durationtimeout, auto-retry, or manual resume). Single uninterrupted VDiff passes are unaffected.Test Plan
TestSourcePKColsOrderingregression test with 4 casesReferences