Skip to content

fix(ddl): preserve current indexes when adding partitions - #33619

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/33393-partition-indexes
Dec 1, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/33393-partition-indexes

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #33393.

What this PR does / why we need it:

ADD PARTITION used 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

  • Exercised ordinary and UNIQUE indexes across old and new partitions after DROP/ADD, including changing a same-name key prefix. Checked forced reads, UPDATE, DELETE, and duplicate rejection. A two-session SQL regression holds ADD PARTITION open while an index DDL waits and verifies the latter covers the new partition.
  • Used two CNs to run both DDL commit orders, check RANGE and LIST reads after restart, and verify CHECK, generated columns, and defaults. A forced failure creating the second child rolled back the first child and its hidden tables. Restarted on data produced by upstream to verify missing slots, stale indexes and incompatible prefixes are rejected. Rebuilding verified-empty affected partitions restored indexed access.
  • Verified MASTER, FULLTEXT, and IVFFLAT queries and their physical components. IVFFLAT had the same four components on both partitions. Synchronous INSERT for these three algorithms still hits a separate existing write-routing error on upstream even before any partition is added. [Bug]: INSERT into a partitioned table with a FULLTEXT index panics in disttae Write #28311 tracks the FULLTEXT case.
  • On the rebased head, the partition SQL suites passed 175/175 statements. The focused run with JDBC result metadata enabled passed 25/25. Four deliberately held cross-CN DDL orderings and 24 concurrent DDL pairs produced matching index layouts and correct new-partition writes.
  • All six affected Go package suites passed, along with focused race tests across four packages. Local incremental SCA selected 237 of 509 packages and reported zero issues.

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.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify mergify Bot added the kind/bug Something isn't working label Dec 1, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Dec 1, 2026
@mergify

mergify Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: 5c3d494abef0bf1736920fb585b85f8a1ce89d6b

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@XuPeng-SH
XuPeng-SH merged commit 16b9b15 into matrixorigin:main Dec 1, 2026
18 of 23 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/33393-partition-indexes branch December 1, 2026 18:16

This branch was successfully deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ALTER ADD PARTITION breaks indexes added after CREATE TABLE

2 participants