Skip to content

MySQL Parallel Snapshot#37642

Draft
peterdukelarsen wants to merge 3 commits into
MaterializeInc:mainfrom
peterdukelarsen:pl/parallel-mysql
Draft

MySQL Parallel Snapshot#37642
peterdukelarsen wants to merge 3 commits into
MaterializeInc:mainfrom
peterdukelarsen:pl/parallel-mysql

Conversation

@peterdukelarsen

Copy link
Copy Markdown
Contributor

Motivation

Description

What does this PR actually do? Focus on the approach and any non-obvious
decisions. The diff shows the code --- use this space to explain what the
diff can't tell a reviewer.

Verification

How do you know this change is correct? Describe new or existing automated
tests, or manual steps you took.

def- and others added 3 commits July 8, 2026 07:52
Partition each table's primary-key range across timely workers so they
read disjoint PK ranges of the initial snapshot concurrently, reducing
initial-load time for large tables with a single-column integer primary
key. A snapshot leader establishes the consistent point and broadcasts
SnapshotInfo to all workers over a timely feedback loop; each worker then
reads its range under a CONSISTENT SNAPSHOT transaction. Tables without a
suitable PK fall back to single-worker-per-table mode. Also adds a
MySqlInitialLoadMultiWorker feature benchmark.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Generalize PK-range snapshot partitioning beyond single-column integer
primary keys to also cover non-integer (char/varchar/text) and composite
PKs, so large tables keyed by strings (e.g. ULIDs) or multi-column keys
also load their initial snapshot in parallel across workers instead of
falling back to a single worker.

Single-column integer PKs keep the cheap MIN/MAX split. Other supported PKs
sample partition boundaries by keyset pagination over the primary-key index
(one forward pass), reading each boundary key back already rendered as a SQL
literal (QUOTE() for text, CAST(.. AS CHAR) for numeric) so range predicates
compare under each column's own collation, matching the ORDER BY used to
pick them. Composite keys use row-value comparisons. Every boundary is found
with a strict `pk > prev`, so boundaries strictly increase and the resulting
half-open ranges are disjoint and cover the entire key domain: each row is
read by exactly one worker regardless of data distribution.

Boundary computation runs before LOCK TABLES so the O(rows) sampling scan for
non-integer PKs does not extend the table-lock window; correctness does not
depend on boundaries matching the exact snapshot point.

Also fix a snapshot duplication bug: when a partitioned table has fewer
partitions than the cluster has workers, the worker responsible for the table
could fall through to the `responsible_for` path and read the whole table in
addition to the range-owning workers, duplicating every row. A read plan now
distinguishes range-owning workers, the single responsible worker of an
unpartitioned table, and a responsible worker that owns no range (which reads
nothing but still emits the table's rewind request).

Adds char and composite PK correctness cases to mysql-cdc.td and a
test/mysql-pk-benchmark composition that demonstrates the speedup under a
bandwidth-limited MySQL link (the regime where parallel range reads help).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants