Skip to content

feat: rename ordinary indexes in place - #29174

Draft
XuPeng-SH wants to merge 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-23392-rename-index
Draft

XuPeng-SH wants to merge 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-23392-rename-index

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • Feature
  • BUG

Which issue(s) this PR addresses

Part of #23392. This PR delivers ordinary secondary-index rename. FULLTEXT, vector and other plugin indexes require their own maintenance-identity migration.

What this PR does

ALTER TABLE … RENAME INDEX old TO new and RENAME KEY use the existing INPLACE ALTER transaction. The planner resolves clauses in order and the executor publishes final names in mo_indexes and the table constraint definition. The base table, hidden tables, index IDs and user data stay in place. Name swaps through a temporary alias publish only the final names.

The INPLACE catalog rewrite now retains the original creator, owner and creation time using the existing catalog-row read. DUMP with reconstructable schema emits the live index names so its CREATE SQL agrees with the manifest.

Scope and concurrency

  • Default and BTREE column indexes on permanent, nonpartitioned local tables. A unique index bound by an incoming or self-referencing foreign key is rejected. Unrelated unique indexes can be renamed.
  • Rename clauses can be combined with other rename clauses, ALGORITHM=DEFAULT|INPLACE and LOCK=DEFAULT|EXCLUSIVE.
  • Plugin and functional indexes, native Unicode unique tables, published source databases and CCPR replicas are outside this slice. Named publications coordinate through the database catalog key. Wildcard publications coordinate through the publisher’s existing catalog primary-key range. An ordered read barrier closes the snapshot gap.
  • Work consists of catalog lookups and updates plus existing INPLACE definition publication. Cost is independent of rows in the user table. The old COPY path’s data recasting and optional FK-field writes are absent.

Validation

  • Linux host 57 ran the two-CN MySQL-protocol integration under Go 1.27.1 with -race. It verifies table/index/hidden-table identities, 70 KB payload digest, ownership metadata, failed clauses and transaction rollback, uniqueness, named and wildcard publication admission, a held publication row and a disjoint publisher, and FK name reuse with unrelated or reordered columns.
  • Owning package race suites passed for the parser, plan protobuf, catalog, locks, planner, compiler, frontend and disttae. The compiler and SQL integration were rerun after the FK guard change. DUMP manifest tests passed.
  • Incremental gofmt, vet, configured golangci-lint and molint passed on the published tree. Lint reported 0 issues.
  • gpt-6.2-sol/xhigh produced the design and approved 50ace2d39b after correction rounds. GitHub CI will run on the new revision.

@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 kind/bug Something isn't working kind/feature labels Sep 20, 2026
@matrix-meow matrix-meow added the size/XXL Denotes a PR that changes 2000+ lines label Sep 20, 2026
XuPeng-SH added a commit that referenced this pull request Sep 20, 2026
## What type of PR is this?

- [x] BUG
- [x] Test and CI

## Which issue(s) this PR fixes:

Related to #29083 and #29082. Repairs the deterministic base BVT failure
exposed by #29174 after #29143; does not claim to close every
vector-index issue.

## What this PR does / why we need it:

The cosine boundary golden captured float32 subnormal squared-norm
error. After #29143 switched SQL scalar and batch paths to scaled
float64 reductions, six assertions still expected `0.05718844756484032`
rather than the correct `1 - 4/sqrt(18) = 0.05719095841793653`. The same
six failures occur in the CI of #29143 and #29174; this is not a timing
flake.

- Correct exactly six expected values; retain all 22 SQL statements, raw
scores, result shapes, and comparison rules.
- Document the independent mathematical oracle rather than regenerating
expectations from the implementation.
- Add non-endpoint cosine scale-invariance tests for float32/float64,
independently tiny operands and mixed extreme magnitudes, with negative
and zero controls.
- Exercise actual SQL const/column and materialized column/column
execution; assert batch eligibility, DOUBLE result shape, and each
path's agreement with the independent oracle at absolute tolerance
1e-14.

No production code, runtime allocations, algorithm dispatch, retries,
skips, or comparison tolerances changed. Reuses existing small fixtures.

### Validation

- Go1.26.4 darwin/arm64 CPU, matching stamped native artifacts.
- Focused new metric and SQL executor tests PASS; owning
`pkg/vectorindex/metric` and `pkg/sql/plan/function` packages PASS.
- Clean base service reproduces the original BVT 6/22 failures. Same
ready isolated service with corrected test: 22/22 PASS twice
(0.203s/0.238s); database cleanup checked between and after runs.
- Targeted go vet, incremental lint, gofmt and diff checks.
- Independent GPT-6-astra medium design and final overall review.

Local BVT is standalone; historical failure evidence is Linux multi-CN
PROXY CI. No topology/runtime change warrants another full multi-CN run
locally. New PR CI remains pending; it has not been claimed green.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
@XuPeng-SH
XuPeng-SH force-pushed the codex/issue-23392-rename-index branch from 812069c to c953188 Compare September 20, 2026 21:36

@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.

P1 blocker — REQUEST_CHANGES recommendation: preserve existing TEXT payloads during index rename.

Reviewed b2f178d..c953188.

The new RENAME INDEX route selects COPY at pkg/sql/plan/build_alter_table.go:1197–1198. For an upgraded table containing an ordinary TEXT value larger than 65,535 bytes, SET sql_mode='' followed by ALTER TABLE t RENAME INDEX old_idx TO new_idx copies that value through INSERT assignment conversion.

The rebased assignment rules retain casts for same-type TEXT (build_constraint_util.go:1350), impose the ordinary TEXT byte limit (func_cast.go:10094), and truncate successfully in non-strict mode (func_cast.go:9053–9058). COPY then replaces the original table, committing shortened data even though only an unrelated index name changed. Atomic rollback does not protect a successful conversion.

The conversion behavior originates in base-side #29121; this new public entry point must still satisfy the approved row-preservation invariant. Preserve unchanged column payloads, or reject lossy reconstruction atomically regardless of session SQL mode. Add an upgrade-state regression covering strict/non-strict modes and byte-for-byte preservation or atomic rejection.

Design approval, parser/planner, metadata handoff, FK/catalog, COPY lifecycle, and changed tests/results were reviewed. Exact-head required CI passes; the three changed BVTs ran successfully (61/61, 49/49, 24/24). They do not exercise this legacy-data boundary. This finding is source-proven; no upgrade reproduction was executed during this read-only review. Coverage was not used as a gate.

Independent review completed with GPT-6 Astra, medium.

@fengttt fengttt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No, you will not copy the index just to rename it. This is not acceptable.

@iamlinjunhong iamlinjunhong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the exact head c953188 against base b2f178d. The 28 exact-head checks are complete and successful.

P1 — RENAME INDEX can silently truncate existing ordinary TEXT data.

Trigger: an upgraded/legacy table has a width-zero ordinary TEXT column containing more than 65,535 bytes; the session uses the empty/non-strict sql_mode; then it runs ALTER TABLE t RENAME INDEX old_idx TO new_idx.

Evidence:

  • pkg/sql/plan/build_alter_table.go:1197-1198 routes RENAME INDEX through COPY.
  • pkg/sql/plan/build_alter_table.go:628-630 copies every column with INSERT ... SELECT.
  • pkg/sql/plan/build_constraint_util.go:1350-1354 and 1393-1401 force an assignment cast even when the source and target TEXT types compare equal.
  • pkg/sql/plan/function/func_cast.go:10088-10103 gives width-zero TEXT the 65,535-byte limit (pkg/container/types/bytes.go:40), while 9053-9058 truncates over-limit values in non-strict mode.

The copy therefore succeeds and pkg/sql/compile/alter.go:1520-1522 publishes the replacement with shortened bytes; no rollback occurs because the conversion returned success. An unrelated index rename must preserve row bytes, or reject the reconstruction atomically. Please fix the copy path and add strict/non-strict regression coverage for legacy data.

P2 — RENAME INDEX is incompatible with legacy/partially upgraded tenant FK catalogs.

pkg/sql/compile/alter.go:1520-1522 unconditionally executes the SQL generated at pkg/sql/compile/alter_copy_index.go:61-66, which references referenced_index_name even when the table has no FK rows. However, pkg/sql/plan/build_dml_util.go:5674-5692 explicitly supports legacy/partial mo_foreign_keys layouts, and pkg/bootstrap/versions/v4_0_6/tenant_upgrade_list.go:33-35 adds this column asynchronously. If an existing session runs RENAME INDEX before that tenant upgrade has added the column, the statement reaches this SQL and fails with an unknown-column error. Make this catalog update layout-aware (or safely skip it when the column is absent) and add a legacy/partial-layout regression.

@XuPeng-SH
XuPeng-SH marked this pull request as draft September 21, 2026 02:08

This branch was previously deployed

1 inactive deployment
ci — 50ace2d3 Deployed Nov 22, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/wip kind/bug Something isn't working kind/feature size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants