Composite key pagination support for ghostferry#420
Draft
jameszhu-shopify wants to merge 2 commits intomainfrom
Draft
Composite key pagination support for ghostferry#420jameszhu-shopify wants to merge 2 commits intomainfrom
jameszhu-shopify wants to merge 2 commits intomainfrom
Conversation
grodowski
reviewed
Dec 16, 2025
| } | ||
|
|
||
| func (t *TableSchema) paginationKeyColumn(cascadingPaginationColumnConfig *CascadingPaginationColumnConfig) (*schema.TableColumn, int, error) { | ||
| func (t *TableSchema) getPaginationKeyColumns(cascadingPaginationColumnConfig *CascadingPaginationColumnConfig) ([]*schema.TableColumn, []int, error) { |
Member
There was a problem hiding this comment.
Not sure if that's the right place, though all composite columns should be checked for *_bin collation (#422 does this for non-integer PKs in the parent PR)
| @@ -91,6 +92,7 @@ func (c *Cursor) Each(f func(*RowBatch) error) error { | |||
| "tag": "cursor", | |||
| }) | |||
| c.paginationKeyColumn = c.Table.GetPaginationColumn() | |||
Member
There was a problem hiding this comment.
Let's check if this field can be removed 👀
| return t.PaginationKeyColumns | ||
| } | ||
|
|
||
| // Deprecated: Use GetPaginationKeyIndexes |
Member
There was a problem hiding this comment.
Can we remove the fns that got marked as deprecated?
| } | ||
| } else if cascadingPaginationColumnConfig != nil { | ||
| // Fallback | ||
| if fallbackColumnName, ok := cascadingPaginationColumnConfig.FallbackPaginationColumnName(); ok { |
Member
There was a problem hiding this comment.
I think in case fallback columns are specified that are not the primary key, ghostferry must fail unless there exists a unique index that spans them (in the right order)
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
This PR adds support for tables with composite primary keys (multi-column PKs) in Ghostferry's data migration process. Previously, Ghostferry only supported tables with single-column numeric primary keys. This PR is developed on top of another PR - Pagination beyond uint64
This is a large PR so please let me know if I should break it down to smaller ones.
Key Changes
Core Pagination Key Types (
pagination_key.go)CompositeKeytype: A slice ofPaginationKeyobjects for multi-column keysMinPaginationKey/MaxPaginationKeyfunctions that handle both single and composite keysTable Schema Detection (
table_schema_cache.go)GetPaginationColumns()returns all PK columns (replaces single-columnGetPaginationColumn())Cursor & Data Iteration (
cursor.go,data_iterator.go)(col1, col2) > (?, ?)ORDER BY col1, col2State Management (
state_tracker.go)CompositeKey.NumericPosition()uses first column as heuristic).Verifiers (
iterative_verifier.go,inline_verifier.go,compression_verifier.go)WHERE (k1, k2) IN ((?, ?), ...)Sorter (
data_iterator_sorter.go)MaxPaginationKeySorterhandles mixed key types without panickingTest
✅
dev testpass (unit tests and integration tests)✅ New integration tests are added for composite key support (with 2 columns, 3 columns).
Backward Compatibility