Repository navigation
fix: preserve index visibility in clone - #27143
Conversation
eea02e4 to
439315b
Compare
439315b to
2d74a85
Compare
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? |
aptend
left a comment
There was a problem hiding this comment.
Deep re-review of exact head 9cbdaed63d4d26560cc284d84a4b94a0cbb93c0b, including the complete current diff and all prior visibility comments. The original raw-proto3-bool issue is partially addressed, but the new state model is not closed across rolling upgrades or all DDL reconstruction consumers.
[P1] Do not treat IndexOption.Visibility presence as proof that it is authoritative. A new CN can persist VISIBILITY_VISIBLE; an old CN can then execute ALTER INDEX ... INVISIBLE, updating IndexDef.Visible and mo_indexes.is_visible while preserving the unknown nested option field during protobuf round-trip. reconcileIndexVisibility returns immediately at lines 169-170 when all markers are present and skips marked definitions at lines 223-225, so the stale VISIBLE marker wins over the catalog and CLONE/ALTER COPY reconstructs the index incorrectly. The marker needs a version/ownership protocol or authoritative catalog reconciliation that also detects and repairs stale marked values.
[P1] Reconcile legacy visibility at every production reconstruction boundary. ConstructCreateTableSQL currently makes createTableIndexVisible return true for every unset definition. SHOW CREATE calls it directly with table/snapshot context, while publication, CDC, get_ddl, and table-dump paths also call the context-free serializer. A pre-upgrade explicitly invisible index has Visible=false, no marker, and mo_indexes.is_visible=0; these paths therefore emit a visible index and may recreate or publish the wrong schema. LIKE/CLONE-only reconciliation does not close those consumers.
The exact head also fails its owning tests under the required CGo setup. TestGenInsertMOIndexesSqlPersistsInvisibleIndex emits is_visible=1 while the test requires 0. A full ./pkg/sql/plan run additionally fails TestRenameChangeColumnStillUsesCopyAlter, TestCaseOnlyChangeColumnUsesCopyAlterAndUpdatesForeignKeyCatalog, TestAlterTableCopyDropsEveryAdjacentIndexForDroppedColumn, and TestDropReferencedPrimaryKeyIsRejected because the new reconciliation returns missing visibility metadata. pkg/catalog passes. git diff --check is clean.
Requesting changes because rolling-upgrade and legacy-schema correctness remain unsafe and the affected owning test suites are red.
|
@XuPeng-SH @aptend I re-checked the rolling-upgrade review against
Fixed. Reconciliation now queries
SHOW CREATE now supplies its compiler context and source table ID to the shared
Fixed. The compiler fixture now uses SetIndexVisibility(false) and asserts the |
aptend
left a comment
There was a problem hiding this comment.
Re-reviewed the incremental fix and complete diff at exact head 5a48b7009b34479d832d4fe57a9a1afdaf8f95b1. The new commit fixes stale-marker reconciliation for planner paths, makes SHOW CREATE reconcile when a compiler context is available, repairs the affected fixtures, and the exact focused compile tests plus full pkg/catalog and pkg/sql/plan packages now pass under the required CGo environment. One P1 closure gap remains.
[P1] Preserve pre-upgrade invisible indexes in the context-free DDL consumers. createTableIndexVisible still maps every unset legacy definition to visible. That is necessary for a legacy default-visible index, but it regresses the equally reachable legacy explicitly-invisible state (Visible=false, no new marker, mo_indexes.is_visible=0). Publication (pkg/publication/ddl.go), CDC (pkg/cdc/sinker_v2.go), get_ddl (pkg/frontend/get_ddl.go), and table-dump reconstruction call ConstructCreateTableSQL(nil, ...), so the new reconciliation branch cannot run and these paths emit/recreate the legacy invisible index as visible. Before this PR those paths rendered the raw false state as INVISIBLE; the fallback now flips it. The serializer cannot distinguish the two legacy states without authoritative metadata, so each consumer needs a resolved visibility overlay/context (or a shared boundary that supplies one) before serialization. Please add a regression through at least one context-free public consumer using a pre-marker invisible definition and authoritative mo_indexes=0.
Requesting changes because upgrade compatibility is still incorrect outside the planner/SHOW/CLONE paths.
|
@aptend This re-review targets
|
|
@aptend I checked the claimed context-free regression against the PR base
This is not true on the base. Base The broader inability to distinguish a pre-marker explicitly invisible index in context-free consumers is real, but it is pre-existing and cannot be solved correctly in the serializer: those APIs lack the source transaction/snapshot/catalog query ownership needed to read For this PR, normal persisted source tables—including stale marker-bearing ones—are now resolved from authoritative |
5a48b70 to
dfb9357
Compare
aptend
left a comment
There was a problem hiding this comment.
Re-reviewed exact head dfb93576e6327eb6f7d2ddf52c9fbabbb4fdce73 after the rebase and latest response. APPROVED.
The author is correct that my previous context-free-consumer blocker was based on an incorrect base comparison: the pre-PR public ConstructCreateTableSQL passed indexVisibilityKnown=false, so marker-less proto3 Visible=false already used the historical default-visible rendering in nil-context consumers. This PR preserves that behavior and does not introduce the claimed regression. Resolving that pre-existing ambiguity in CDC/publication/dump/get_ddl requires authoritative catalog context outside #27078's CLONE/LIKE scope.
Within scope, this head reconciles normal persisted indexes—including stale marker-bearing definitions—from authoritative mo_indexes at the source snapshot/tenant, propagates resolved visibility through CLONE/LIKE, ALTER COPY, and context-backed SHOW CREATE, handles fixed-visible bootstrap indexes, and persists explicit visibility for new/altered definitions. The rebase range-diff preserves the reviewed commits; its only substantive conflict adaptation uses the upstream SQL quoting helper for index options.
Validation on this exact head: full ./pkg/catalog, ./pkg/sql/plan, and ./pkg/sql/compile pass with the required CGo/thirdparties setup; git diff --check is clean.
Merge Queue Status
This pull request spent 59 minutes 47 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonPull request #27143 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
Failing checks:
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Tick the box to put this pull request back in the merge queue (same as
|
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep re-review completed on exact head f42e4790a7f7aa5a817bf6974b711c5e1302f484.
The latest scoping commit closes the remaining ownership and mutation boundaries:
- local LIKE/CLONE, ALTER COPY, and context-backed SHOW CREATE reconcile every persisted index from authoritative
mo_indexesin the same transaction/snapshot and tenant, so both pre-marker definitions and stale rolling-upgrade markers are handled; - resolved table definitions are deep-copied before reconciliation/rewrite, avoiding mutation of compiler/engine cache state;
- subscription definitions are not queried against the subscriber's unrelated catalog and retain publisher-provided metadata;
- fixed bootstrap/system-schema indexes use the explicit fixed-visible path where
mo_indexesrows are intentionally absent; - normal/unique/spatial/fulltext/plugin CREATE paths and ALTER visibility paths all persist the tri-state marker, while catalog insertion keeps the legacy default-visible fallback;
- reconciliation validates completeness/duplicate consistency and applies updates only after the full result has been validated.
I also checked temporary-table/index metadata, multi-row plugin indexes, snapshot table IDs, and the public/context-free formatter boundary. The context-free legacy ambiguity is unchanged from the pre-PR behavior and remains outside #27078; this PR does not regress it.
Validation on this exact head:
git diff --check- full
./pkg/catalog ./pkg/sql/plan ./pkg/sql/compilewith the required CGo/link environment - current GitHub UT, SCA, coverage, and BVT checks are green
No blocking findings remain.
LeftHandCold
left a comment
There was a problem hiding this comment.
Deep re-review completed on exact head f42e4790a7f7aa5a817bf6974b711c5e1302f484. APPROVED.
The latest scope fix closes the remaining practical regressions: local LIKE/CLONE and SHOW CREATE operate on private copies, subscription definitions no longer query the subscriber catalog, and fixed-visible system-schema indexes avoid invalid mo_indexes lookups. Normal persisted user indexes—including stale marker-bearing definitions during rolling upgrades—are still reconciled from authoritative mo_indexes.is_visible using the source snapshot and tenant, with missing/contradictory metadata failing before DDL emission.
I traced the production reconstruction callers, new index creation/ALTER persistence paths, protobuf compatibility, and catalog insertion. The context-free legacy ambiguity is pre-existing and remains explicitly outside this PR; this change does not regress its historical default-visible behavior. Current-head UT/SCA/coverage and selected BVT checks are green; diff/format/package-list checks are clean. No actionable blocker found.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #27078
What this PR does / why we need it:
Table/database CLONE and
CREATE TABLE ... LIKE ...rebuild source schemas throughSHOW CREATE-style DDL. The serializer omitted
INVISIBLEand catalog insertionalways wrote
is_visible = 1, so rebuilding a secondary index could alteroptimizer-visible schema state.
Historic proto3
IndexDef.Visible=falseis ambiguous: it can be a pre-upgradedefault-visible index whose field was omitted or an explicitly invisible index.
mo_indexes.is_visibleis authoritative for a planner-resolved, persisted localsource table.
Changes
IndexOption.Visibility, a durable tri-state marker at protobuf wirefield 4. New regular/spatial, unique, fulltext, plugin, and ALTER-add indexes
write it while synchronizing the legacy boolean.
IndexDefreserved field 14is untouched.
mo_indexesat thesource table ID, snapshot, and tenant before LIKE/CLONE or ALTER COPY rebuilds
DDL, even when a marker is present. This prevents an old CN preserving a
stale unknown marker after
ALTER INDEXchanges catalog visibility.ConstructCreateTableSQLa pure formatter: it has callers that do notown a source catalog snapshot. Local
SHOW CREATE TABLEnow reconciles afterresolving its source table; subscription SHOW/LIKE sources retain the
publisher-provided definition instead of querying the subscriber catalog.
mo_task, as visible bootstrapmetadata. They intentionally have no
mo_indexesrows. Missing orcontradictory metadata for normal user tables still fails before emitting a
rebuilt schema.
ALTER visibility updates, and
mo_indexesinsertion. Visibility-only optionsstill emit SQL
NULLfor the unrelated options column.Issue-to-test proof
clone_index_visibilitycreates visible and invisiblesecondary indexes, then asserts SHOW INDEX and SHOW CREATE for the source,
table CLONE, CREATE TABLE LIKE, and database CLONE. It checks cloned rows
through predicates and verifies an
INVISIBLE COMMENTindex remains hidden.catalog-visible and catalog-invisible output for LIKE and table CLONE. A
marker-bearing visible source with catalog-invisible metadata proves the
catalog result overrides a stale marker.
snapshot/tenant lookup, incomplete and contradictory metadata, no partial
mutation on incomplete metadata, formatter-only callers with a table ID, and
fixed-visible bootstrap/system schemas including
mo_task.insertion, explicit invisible insertion with an exact visibility tuple, and
visibility-only option SQL.
Validation
TestBuildShowCreateTableReconcilesLegacyIndexVisibility,TestReconcileIndexVisibilityUsesFixedVisibleSystemDatabase, and thelegacy/stale/missing-metadata LIKE/CLONE controls.
./pkg/sql/planpackage.git diff --check.clone_index_visibilitycase passed (25/25), while unrelated existingsystem and subscription cases exposed the missing-catalog ownership boundary
corrected by this update.
Residual risks
No catalog migration is required. Planner-backed reconstruction resolves
authoritative visibility only where it owns the source table and catalog
snapshot. Context-free CDC, publication, dump, and
get_ddlconsumers retainthe historical visible fallback for an unmarked proto3 false definition; they
cannot safely resolve a pre-marker explicitly invisible index without a
separate source-catalog ownership change outside #27078's CLONE/LIKE scope.