Skip to content

[4.2-dev] fix: align ENUM/SET secondary-index key encoding - #33152

Merged
XuPeng-SH merged 16 commits into
matrixorigin:4.2-devfrom
XuPeng-SH:codex/33080-delete-single-encoding
Nov 25, 2026
Merged

XuPeng-SH merged 16 commits into
matrixorigin:4.2-devfrom
XuPeng-SH:codex/33080-delete-single-encoding

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Documentation

Which issue(s) this PR fixes

Fixes #33080.

What this PR does

Generated ENUM/SET index backfills and DML old-row projections use stored ENUM ordinals and SET bitmaps. This aligns backfill with regular writes and preserves different SET values that share display text. Public serial and serial_full retain their existing display semantics. Index lookups compare the full owner when the physical key does not uniquely identify the owner, including primary-key prefixes.

Unique-index backfill checks each key part using typed SQL grouping. The internal source binding exposes ENUM ordinals, and each other key part keeps its SQL equality semantics. SET backfill continues to use stored bitmaps for supported indexes. Equal floating-point zeros now reject a unique-index build with error 1062. Prefix and NULL handling share the same index-part expressions used by backfill.

The regular DELETE path uses the canonical physical key. The interim stale-key assertion and its private error and rollback plumbing have been removed. The assertion had added a second equality to the composite UNIQUE join, which prevented a physical-key runtime filter and caused a full hidden-index scan for a point DELETE on a freshly created table. Legacy recovery checks now belong to the offline rollout procedure.

UPDATE also matches the full old primary key when an index key can identify multiple owners. For example, two rows with the same primary-key prefix and SET value can share a hidden index key. The old-key lookup in both UPDATE planners now removes only the targeted owner's entry, including when UPDATE changes the primary key. Runtime filtering still prunes on the physical key.

4.2 compatibility and offline rollout

  • Inventory every tenant and physical partition leaf before traffic is allowed on the upgraded binary. Rebuild affected regular and UNIQUE indexes from base rows while fenced. Compare the full multiset of physical keys and owners with a clean reference. Apply the same verification after restoring or cloning an affected snapshot. A rebuild that was interrupted or could not be verified remains fenced.
  • Positive ENUM/SET prefixes are rejected for new definitions. Native restore or clone of a retained definition can be rejected even if the live index was dropped. Rehearse each required snapshot and PITR point with its original scope. Extract base rows from the retained source or restore with the matching release in isolation. Replacement definitions that change uniqueness require the constraint owner's agreement. Keep the source backup while the recovery obligation remains.
  • The upgrade guide covers the verified shadow-copy path for RANGE and two-leaf HASH partition layouts. A complete inventory without affected keys or definitions requires no migration. An incomplete result requires further verification.

The 4.2 release owner accepted the offline repair and historical recovery exceptions. Release disposition · Upgrade guide.

Validation

  • The signed-zero regression reproduced on fa8278b2c896. After the fix, ADD UNIQUE returns 1062 and leaves no index, followed by successful CREATE UNIQUE INDEX after correcting the duplicate. The same fixture checks distinct ENUM ordinals with identical public display, ordinary prefixes, NULL and public serial. Review finding
  • The rebased implementation passed the full compiler and planner race suites, the focused embedded DML and partition offline-copy race tests, and incremental SCA.

Earlier validation for this PR

  • Race tests passed for pkg/common/moerr, pkg/frontend, pkg/sql/plan, pkg/sql/plan/function, and pkg/tests/dml. The focused partition offline-copy race test passed. The affected mo-tester BVT passed all 66 statements.
  • Persisted data written by official v4.2.9 reopened on the candidate. Both the original table and a native snapshot clone carried the released key. Physical readback distinguished stale keys and wrong owners from the rebuilt reference. After rebuild and restart, duplicate insertion failed and single-target and multi-target DELETE removed the expected base rows and index entries. NULL UNIQUE keys were intentionally absent.
  • On a fresh single-CN fixture with one million rows per table, the DELETE median for a composite UNIQUE ENUM index improved from 8.48 ms to 0.50 ms for one row and from 10.42 ms to 2.76 ms for 1,000 rows. Point DELETE scanned one hidden index block and one row, down from 130 blocks and one million rows. Two runs per build, 70 timed statements per case, same data, every DELETE checked affected rows and rolled back. Nonunique and integer controls retained their previous scan counts.
  • Incremental gofmt, vet and golangci-lint passed. Molint reported only baseline diagnostics.
  • The UPDATE regression reproduced sibling index loss or duplicate new entries in all four combinations of single-target and multi-target UPDATE with SET-only changes or primary-key reassignment. The fixed candidate checked affected rows, exact base rows, and old and new hidden key/owner pairs in each case. On a fresh million-row table, both UPDATE planner paths retained the physical-key runtime filter and scanned one hidden block with two colliding rows. The owner join selected one index entry.

@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 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 04b807d3e98ca2eb6010dde0fb1bf2a39c89eb59

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: 04b807d3e98ca2eb6010dde0fb1bf2a39c89eb59

Assessment: request_changes

The DELETE change correctly reuses stored ENUM ordinals and SET bitmaps for index maintenance. The backfill fix also changes released behavior for public SQL, and the documented partitioned-index rebuild can leave stale keys after a successful DELETE. Scope stored-value serialization to internal index DDL and verify a partition-aware rebuild before requiring it for upgrades.

Model: gpt-6.2-sol / xhigh

Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3

  • P1 pkg/sql/plan/base_binder.go:2826: An existing query passes an ENUM or SET column directly to public SQL serial or serial_full.
    Impact: The same query returns different bytes after upgrading. A query that extracts the serialized label as VARCHAR now fails with a type mismatch. Rebuilding indexes leaves this SQL regression in place.
    Evidence: On the official v4.2.9 binary, serial_extract(serial(e),0 AS varchar(8)) and its SET counterpart returned b and a. Against the same persisted rows, the candidate produced ordinal and bitmap encodings and raised error 20101 during extraction. The shared AST binder applies the rewrite to public calls as well as generated SQL. Use the existing raw-value binding mechanism at the generated index backfill and duplicate-check boundary. See released-clean.stdout and candidate-upgrade.stdout.

  • P1 docs/cn/enum_set_index_upgrade_42.md:17: An operator follows the required DROP and CREATE procedure for an ENUM secondary index on a partitioned table from v4.2.9.
    Impact: A separately added index can be missed during inventory and cannot be dropped by the prescribed command. For an inline index, both rebuild statements can succeed while removing the index from the parent definition. A subsequent DELETE reports success and leaves the deleted row's key in the child index.
    Evidence: partition-release-readback.stdout shows the separately added index only on partition leaves. In partition-candidate.stdout, DROP rejects that index, while the inline index disappears from SHOW CREATE TABLE after both rebuild statements succeed. After restart, partition-post-delete.stdout shows a child index entry for deleted PK 1 in both fixtures. pkg/sql/compile/ddl.go:2663 explains the leaf-only CREATE path. Provide a supported partition-aware procedure that preserves definitions and verify that committed DELETE removes the corresponding child key.

Validation:

  • Verified the frozen head, merge base, patch ID and whitespace. The private /tmp and loopback preflight, native prerequisites and candidate service build passed.

  • Six focused planner and compiler tests passed on retry. Embedded SQL also passed the ordered ENUM DELETE and legacy multi-target DELETE controls. See focused-retry.jsonl and sql-probe.jsonl.

  • Reopened data from the official v4.2.9 binary on the candidate. The unpartitioned composite ENUM, single-column SET secondary and single-column ENUM UNIQUE rebuild controls passed. The public serialization and partitioned rebuild probes reproduced the findings. Commands, exits and logs are mapped in review-validation.md. v4.2.9 release

Limitations:

  • Local upgrade execution used an isolated single-CN deployment. The customer hotfix named in issue #33080 was verified as published. Its binary, multi-CN behavior and the full distributed suite remain outside the executed coverage. v4.2.8 hotfix

@mergify mergify Bot added kind/bug Something isn't working kind/documentation Improvements or additions to documentation labels Nov 24, 2026
@matrix-meow matrix-meow added size/XL Denotes a PR that changes [1000, 1999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Nov 24, 2026
@XuPeng-SH

XuPeng-SH commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 93aa3fbad0a0d1300760fd10448d55d262e524a4

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: 93aa3fbad0a0d1300760fd10448d55d262e524a4

Assessment: request_changes

The candidate resolves the prior public serialization regression by limiting stored-value binding to generated index statements with a verified source table. The new shadow-table procedure addresses the earlier rebuild problem for eligible RANGE tables. Two compatibility issues remain for released data.

Model: gpt-6.2-sol / xhigh

Session: 01a1ee80-0d82-7030-a965-b51f496c3054 · slot 2 · generation 1

  • P1 pkg/sql/plan/build_index_util.go:209: Restore a v4.2.9 snapshot containing a table with a positive ENUM index prefix such as KEY ix(e(1)).
    Impact: The new prefix guard rejects the restored definition and aborts recovery. Removing the prefix index from the live table before upgrading leaves older snapshots subject to the same failure.
    Evidence: The pinned v4.2.9 source allowed this definition. Snapshot restore uses CREATE TABLE CLONE, which reconstructs the stored prefix through build_show_util.go:435 and sends it through the new CREATE guard. Preserve or explicitly migrate the legacy definition during restore while keeping the guard for new indexes. Verify with a snapshot captured before upgrade.

  • P2 docs/cn/enum_set_index_upgrade_42.md:40: Upgrade a v4.2.9 cluster containing a HASH-partitioned table with an ENUM secondary index installed on its leaves by standalone CREATE INDEX.
    Impact: The upgrade requires affected indexes to be rebuilt before traffic resumes, but the documented procedure leaves this known released layout without a verified recovery path.
    Evidence: The retained official v4.2.9 readback shows the index on both HASH leaves and absent from the parent. The previous candidate rejected the parent DROP, and the current patch leaves that routing intact. Validate the shadow-table procedure for this released HASH fixture, including physical child-index keys and a committed DELETE, or provide another supported rebuild path.

Validation:

  • Verified the frozen patch, clean checkout, whitespace, formatting, and native artifact provenance. Receipts 1795528560148293356-3.json and 1795529659761232915-3.json.

  • Reconciled the retained v4.2.9 HASH fixture and traced stored-prefix replay from the published source to the candidate guard. Receipts 1795529422452456007-3.json and 1795529510907435809-3.json.

Limitations:

  • The restore finding is based on source tracing. Fresh release SQL probes stopped at cluster readiness, and the candidate Go checks reached their outer deadlines before test execution. The reported hotfix and three-CN migration runs were not independently reproduced.

@XuPeng-SH

XuPeng-SH commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: fa8278b2c896e8bd271557c9e4f6036709065147

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: fa8278b2c896e8bd271557c9e4f6036709065147

Assessment: request_changes

Two previously reported compatibility defects remain for released indexes and retained snapshots. The offline procedure mitigates them when completed, and a later review approved based on the author's accepted exception. The supplied evidence does not establish a policy-owner waiver of the pinned requirements for reading released indexes and restoring older backups. The scoped binding and full-owner matching otherwise reuse existing mechanisms to address fresh-index correctness.

Model: gpt-6.1-terra / max

Session: 01a21136-dc54-7ba1-aace-4039c02570be · slot 2 · generation 3

  • P1 pkg/sql/plan/bind_delete.go:303: After a shutdown upgrade or restore, delete a row whose composite ENUM or SET index was backfilled by v4.2.9 and has not yet been manually rebuilt.
    Impact: The normalized lookup uses an ordinal or bitmap while the released index can contain a display-encoded key. A non-unique index join can silently skip the target row; a unique-index join can delete the base row while leaving an orphaned index entry.
    Evidence: The v4.2.9 backfill and binder at commit 6c05e42 serialize display-bound values. The current lookup selects INNER or LEFT joins at bind_delete.go:460-475, and multi_update/delete.go:43-53 skips a null index row ID. The guide acknowledges both outcomes and requires an operator-run rebuild, while the pinned upgrade policy requires released index data to be readable directly or through a bootstrap upgrade. Preserve access to released keys or provide a recovery-safe migration for live and restored indexes.

  • P1 pkg/sql/plan/build_index_util.go:209: Restore or clone a retained v4.2.9 snapshot or PITR point containing an ENUM index prefix such as KEY ix(e(1)), including a snapshot taken before that index was dropped from the live table.
    Impact: Native recovery rejects the historical table definition. The documented replacement-table procedure can change a unique-prefix constraint and does not preserve normal recovery of the retained artifact.
    Evidence: The released planner allowed the definition. Restore constructs CREATE TABLE CLONE in pkg/frontend/snapshot.go:71, reconstruction emits stored prefix lengths in pkg/sql/plan/build_show_util.go:435, and pkg/sql/plan/build_table_clone.go:151 sends the definition through this new guard. The pinned upgrade policy requires older backups to restore on the newer binary. Preserve or safely migrate historical definitions on restore while retaining the restriction for new definitions.

Validation:

  • The private /tmp and loopback preflight passed; receipt checks/1795602670612750788-2.json and preflight.stdout.log.

  • The review audit verified the frozen head, clean checkout, patch equivalence apart from its terminal newline, whitespace, and coverage of all 28 discussion keys; receipt checks/1795603110192204717-2.json and review-audit-final.stdout.log.

  • Reviewed the supplied discussion, linked issues, released-source writer, current planner and recovery paths. The captured release and target upgrade CI jobs were skipped.

Limitations:

  • The focused planner test timed out during dependency downloads before executing tests; receipt checks/1795602859768541245-2.json and planner-focused.stderr.log.

  • No release binary or native snapshot/PITR restore was independently executed in this review. The release commit mapping and earlier fixture results are from supplied discussion evidence.

  • The prior approval reported focused tests on the preceding head, but its retained staging symlink could not independently establish the historical test inputs; the current merge also changes upstream planner dependencies.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Authorized 4.2 release disposition for head fa8278b2c896e8bd271557c9e4f6036709065147

The offline compatibility exception is accepted for this PR by XuPeng-SH, who has admin permission on matrixorigin/matrixone. This is the release/policy-owner disposition, not only a report that no current application uses the workflow.

The accepted exceptions are: released ENUM/SET index keys are handled by the documented offline fencing, rebuild and physical key/owner verification; historical ENUM/SET prefix-index snapshots use the documented matching-source-release recovery and offline rebuild procedure. Online conversion and native restore of those affected artifacts are not required for this release.

Please assess concrete defects in those offline procedures, the UPDATE owner-collision fix and any independent code paths. Do not request online compatibility solely for the two accepted exceptions.

@XuPeng-SH

XuPeng-SH commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: fa8278b2c896e8bd271557c9e4f6036709065147

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: fa8278b2c896e8bd271557c9e4f6036709065147

Assessment: request_changes

The accepted offline compatibility exceptions are not findings. An independent regression can silently create a UNIQUE index over SQL-equal rows. The scoped raw-value binding and full-owner matching otherwise reuse existing mechanisms, and the focused UPDATE and offline partition checks passed.

Model: gpt-6.1-terra / max

Session: 01a21244-6c6c-7240-bf19-37c0cdedc87d · slot 1 · generation 15

  • P1 pkg/sql/compile/ddl_index_algo.go:89: Create a UNIQUE index on an ENUM and a DOUBLE column when two existing rows have the same ENUM value and contain positive and negative floating-point zero.
    Impact: The new precheck groups the entire key by serialized bytes. Although SQL considers the two zeros equal, their serialized bytes differ, so ALTER TABLE ADD UNIQUE KEY succeeds over duplicate SQL keys. The table is left with data that violates its declared uniqueness constraint.
    Evidence: On the assigned head, TestReviewEnumFloatUniqueBackfill observed SQL equality=1 and one duplicate GROUP BY group, but ADD UNIQUE returned no error; unique-float.log and checks/1795606112399522811-2.json retain the failing assertion and exit 1. The same test passed with duplicate error 1062 when the exact merge-base ddl_index_algo.go was overlaid onto the head checkout; unique-float-baseline.log and checks/1795606358313489299-2.json retain that control and exit 0. The current generated GROUP BY serial(e,f) query is recorded in unique-generated-sql.log and checks/1795606382981487697-2.json. Preserve SQL equality for the other key parts while retaining the required stored ENUM distinctions, and add a regression test for signed zero.

Validation:

  • Private /tmp and loopback preflight passed.

  • The focused embedded backfill, public serialization, UPDATE owner-collision and ENUM/SET ordered DELETE tests passed.

  • Focused planner and compiler tests passed, as did TestPartitionIndexOfflineCopy.

  • All 31 discussion entries were accounted for; review-evidence-audit.log reconciles the claimed checks with their receipts and retained logs.

Limitations:

  • The parent control overlaid only the merge-base ddl_index_algo.go onto the head checkout; it was not a full merge-base or released-binary run.

  • The partition test exercised the documented candidate-side fixture. Released-version upgrade and historical snapshot/PITR recovery were not independently replayed.

  • Logs and receipts are under /home/xupeng/.local/state/mo-bot-55/jobs/58fe6ce36d77a8648562cd3a/attempt-1.

@XuPeng-SH

XuPeng-SH commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 16fd99fadd48f0912732b81681acf7b66b93c4a8

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: 16fd99fadd48f0912732b81681acf7b66b93c4a8

Assessment: approve

The generated backfill now uses stored ENUM/SET values without changing public serialization, and both DML planners match the full owner where a physical index key can collide. The prior signed-zero UNIQUE-index finding is addressed by grouping individual typed key parts; the focused embedded regression passed. The release/policy owner explicitly accepted the documented offline rebuild and historical-recovery exceptions, so the previous compatibility objections are not reopened. The solution reuses existing serializers and index maintenance, with targeted source binding and owner checks justified by their correctness boundaries.

Model: gpt-6.1-terra / max

Session: 01a211d7-e427-70e2-a993-c62f1960cb9e · slot 3 · generation 3

Validation:

  • Frozen-head diff and source review, linked issues, pinned upgrade/testing contracts, and all 33 discussion items; discussion-check.log and checks/1795611396264835746-3.json.

  • Private /tmp and loopback preflight passed (preflight.log; checks/1795610703876737541-3.json). Source-matched native input trees and library hashes were verified (native-trees.log, native-verify.log; checks/1795610917927958895-3.json and checks/1795610710114824697-3.json).

  • Selected planner and compiler tests and TestIndexBackfillPreservesPublicSerial passed with the assigned isolated executor, including signed-zero rejection, distinct ENUM ordinals, public serial, prefix guards and UPDATE owner collisions (focused-tests.log; checks/1795611337484966789-3.json).

  • Prior same-PR review 6056876362 reported and retained a passing three-CN TestPartitionIndexOfflineCopy on fa8278b (partition-offline.log; prior checks/1795606252041460011-2.json); the fixture and ordinary-index migration behavior were unchanged by the subsequent signed-zero fix.

  • git diff --check passed (diff-check.log; checks/1795610703853217294-3.json).

Limitations:

  • The approved compatibility exception requires operators to fence traffic, inventory affected indexes and retained recovery points, rebuild and verify physical keys and owners. Native restore of affected historical prefix definitions is explicitly not guaranteed.

  • No current-head official v4.2.9 or hotfix binary shutdown upgrade, retained-snapshot/PITR recovery, full BVT suite or performance benchmark was independently rerun. The supplied discussion reports release fixtures and prior benchmark evidence.

This branch was previously deployed

1 inactive deployment
ci — 16fd99fa Deployed Nov 25, 2026 by XuPeng-SH
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 kind/documentation Improvements or additions to documentation size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants