storage: Fast approximate snapshot partitioning - #38094
Draft
peterdukelarsen wants to merge 1 commit into
Draft
Conversation
peterdukelarsen
force-pushed
the
pl/mysql-snapshot-prefix-partition
branch
2 times, most recently
from
August 6, 2026 23:31
a5d624c to
7888a17
Compare
peterdukelarsen
force-pushed
the
pl/mysql-snapshot-prefix-partition
branch
from
August 6, 2026 23:36
7888a17 to
ec66765
Compare
peterdukelarsen
force-pushed
the
pl/mysql-snapshot-prefix-partition
branch
2 times, most recently
from
August 7, 2026 14:03
a786a6f to
2b244fb
Compare
peterdukelarsen
force-pushed
the
pl/mysql-snapshot-prefix-partition
branch
2 times, most recently
from
August 7, 2026 23:04
80601fb to
b290345
Compare
peterdukelarsen
force-pushed
the
pl/mysql-snapshot-prefix-partition
branch
from
August 8, 2026 00:08
b290345 to
09d39f3
Compare
Replace the OFFSET-walking boundary discovery with the prefix-based partitioner in mz-mysql-util, so discovery costs EXPLAIN index dives instead of an O(rows) index pass. Only string primary keys are supported. Integer keys, which the OFFSET walk used to sample, now fall back to a single-worker whole-table read. Prefixes of a numeric key do not order consistently with its values, so they would need a separate numeric range splitter. Boundaries are rendered as SQL literals via the server QUOTE() and still pass the existing strict-monotonicity verification in each read transaction. The new mysql_source_snapshot_partition_min_rows dyncfg (default 50000) stops splitting below a minimum range size. Test configs set it low so the tiny tables in mysql-cdc testdrive and parallel-workload still exercise range reads.
peterdukelarsen
force-pushed
the
pl/mysql-snapshot-prefix-partition
branch
from
August 8, 2026 01:44
09d39f3 to
9c36c30
Compare
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.
Motivation
The boundary computation for parallel snapshotting was about as slow as the single-threaded snapshot in many cases, i.e.

Parallelized (~2h runtime):
Single-threaded (~1h50m runtime):

With this change we got rid of the boundary computation and were able to snapshot 1B rows in ~16m:

Follow this anchor link for full details on the specs/data: https://app.notion.com/p/materialize/MySQL-Parallel-Snapshot-Smoke-Test-3a613f48d37b806fa311d1bfe9d4ec4c?source=copy_link#3a913f48d37b80a3bbb2dd05f6bc94c2
Description
Probes the values of a single-column string primary key using
EXPLAINandSELECT LIKEqueries to compute approximate partitioning.In slightly more detail we:
EXPLAINto estimate their row countDownsides
Verification
Recreated from #37994 with an in-repo head branch so this PR can join the GitHub stack.