Repository navigation
fix(ddl): preserve current indexes when adding partitions - #33619
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
This pull request is merged. |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 5c3d494abef0bf1736920fb585b85f8a1ce89d6b
Assessment: approve
The change reuses the existing CREATE LIKE planner and parent definition lock to preserve the live index layout when adding partitions. Slot validation and snapshot-aware metadata caching address the affected read, write, and concurrent DDL paths. No actionable regression was found.
Model: gpt-6.1-terra / max
Session: 01a22aff-bb68-7e31-ae71-ee4ab48ad9d0 · slot 0 · generation 45
Validation:
-
Preflight and five focused Go tests passed. Receipts: checks/1796144660075406972-5.json and checks/1796144985543019687-3.json; log: focused-tests.log.
-
Public SQL probes verified ordinary and UNIQUE index access, functional-index reconstruction, native Unicode uniqueness, and CHECK enforcement on added partitions. Receipt: checks/1796145267981301030-3.json; log: public-probe.log.
-
FULLTEXT, MASTER, and IVFFLAT queries returned the existing row before and after ADD PARTITION; the IVFFLAT case also exercised mixed index-component ordering. Receipt: checks/1796145789436011560-3.json; log: plugin-probe.log.
-
A two-CN probe observed lock waits in both DDL orders, then verified successful DDL, writes, and indexed reads across both partitions. Receipt: checks/1796145611410880669-3.json; log: concurrent-probe.log.
-
An older-layout overlay and current-layout control both encountered the separately tracked FULLTEXT partition-write failure; the probe did not establish a regression from this PR. Receipt: checks/1796145684386086336-3.json; log: legacy-probe-enabled.log.
Limitations:
-
A stopped 4.2-to-main binary upgrade and an independent performance campaign were not run. Broader test and benchmark results in the PR description are author-reported.
-
The first public-probe invocation stopped before compilation because the local Go toolchain was too old; the retry with automatic toolchain selection succeeded. The failed setup receipt and captured diagnostic are retained.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #33393.
What this PR does / why we need it:
ADD PARTITIONused the original CREATE text to build its physical table. An index added or replaced later could be missing, or a different index could occupy the expected slot. Both indexed reads and writes route through those slots. CREATE also groups indexes by type, while ALTER appends them in statement order.Build the physical child from the live parent in the DDL transaction using the existing LIKE planner. Match the generated hidden tables to the parent order by index name and component role. Both routing paths now validate the requested slot. A previously created partition with a missing or incompatible slot returns a diagnostic identifying the partition. Writes open and cache only the hidden relations their plan needs.
Concurrent index DDL already holds the parent definition lock when it enumerates partitions. ADD PARTITION now participates in that lock, and the transaction reuses cached partition membership only at the snapshot that supplied it. With the lock alone, an index DDL that waited could still omit the partition that just committed.
Validation
Performance
Compared the exact upstream and PR binaries on the same host in two alternating runs, with 40 measured samples per side for each workload. With no secondary index, ADD PARTITION P50 went from 11.64 to 14.68 ms. With a regular and a UNIQUE index, it went from 13.02 to 15.02 ms. This DDL now acquires the parent definition lock and constructs its child using the current schema. It can also wait for conflicting work on the same table.
Eight autocommit indexed reads took 11.19 vs 11.26 ms at P50. A 64-row cross-partition INSERT took 7.07 vs 7.09 ms at P50 and 9.49 vs 10.31 ms at P90. These are local measurements.