Skip to content

fix: retry stale regular index hints across CNs - #28641

Merged
mergify[bot] merged 5 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-28639-94d7deef
Sep 12, 2026
Merged

mergify[bot] merged 5 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-28639-94d7deef

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Sep 10, 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:

Related to #28639

What this PR does / why we need it:

A verifier CN can plan an index-hinted SELECT using a table definition from before a concurrent CREATE INDEX. Returning MySQL 1176 during planning prevents the compiler's existing metadata lock from detecting the committed definition change and rebuilding the statement.

The planner records unresolved permanent-table index hints and their parent table references in an additive query-plan field. SELECT compilation includes those references in the existing metadata-lock boundary. A definition change requests the existing statement retry; an index that remains absent returns 1176 before data sources start. Temporary tables, prepared statements, and metadata-unlocked scans retain immediate planner validation. Sirius rejects marked plans so offloading cannot bypass validation.

Plan consumers that never execute the query must also reject unresolved hints. One shared ValidateUnresolvedIndexHints function now owns the terminal error for execution, ordinary EXPLAIN (both planner and frontend output paths), view definitions, and CTAS schema inference. CREATE/REPLACE/ALTER VIEW cannot persist a marked inner query, and invalid CTAS fails before creating a table. EXPLAIN ANALYZE and physical-plan execution retain their existing executable-plan path. DeepCopyQuery preserves the marker list and independently copies each parent object reference.

The shared validator retains the CI follow-up's direct first-marker selection, preserving first-missing-name order without the staticcheck-invalid always-returning loop. This revision rebases the branch without conflicts onto origin/main at e2580f993a5a742f562f3cfcd0f53ca89a9ee373; the protobuf source and generated binding are unchanged from the reviewed head.

Issue-to-test proof

  • The authenticated two-CN regression pauses a regular-index SELECT after compilation against the old definition, allows CREATE INDEX to commit, then verifies successful retry, actual index use in EXPLAIN, and index/base-table row agreement. Separate writer commit and rollback cases preserve the concurrency and visibility oracles, with existing FULLTEXT controls.
  • The same fixture includes no-DDL-race cases for SELECT, ordinary/verbose/explicit-text EXPLAIN, and CREATE VIEW with missing USE/FORCE/IGNORE and order-scoped hints. It asserts protocol error 1176, absence of failed CREATE VIEW/CTAS catalog objects, and unchanged results after rejected CREATE OR REPLACE VIEW and ALTER VIEW. A valid PRIMARY hint remains usable.
  • Planner tests cover missing versus existing hints for EXPLAIN, CREATE VIEW, and CTAS. Frontend coverage asserts validation before EXPLAIN result publication. Deep-copy tests check marker retention and mutation isolation; existing tests cover protobuf round-trip, temporary/PREPARE rejection, parent metadata locking, first-error order, empty markers, and Sirius eligibility.
  • Before the review correction, the new integration test failed on EXPLAIN and CREATE VIEW, while the new deep-copy assertion observed a missing marker list. These failures were reproduced after rebasing the original PR code onto the current base.

Validation

Local validation on the rebased correction (Darwin/arm64, Go 1.26.4; native tests use .agents/skills/mo-dev/scripts/mo-cgo-test):

  • Full ./pkg/sql/plan ./pkg/sql/compile, -count=1 -timeout=10m: passed (16.246s / 7.334s).
  • Full ./pkg/frontend, -count=1 -timeout=15m: passed (39.360s).
  • ./pkg/tests/issues, -v -cover -count=3 -timeout=10m -run '^TestIssue27487ConcurrentInsertIsIncludedInNewIndex$': all three iterations passed (19.362s). This package has no production statements; actual kernel instrumentation is separately checked below.
  • CGo-configured GOWORK=off golangci-lint run --concurrency 2 -c .golangci.yml --new-from-rev origin/main ./pkg/pb/plan ./pkg/sql/plan ./pkg/sql/compile ./pkg/frontend ./pkg/tests/issues: passed, 0 issues.
  • ./pkg/tests/issues, -coverpkg=./pkg/sql/plan,./pkg/sql/compile,./pkg/frontend -count=3 -timeout=10m -run '^TestIssue27487ConcurrentInsertIsIncludedInNewIndex$': passed (32.219s; 21.6% coverage across the three instrumented packages).

Earlier validation recorded for the reviewed head 480add48fe (not claimed as new-head runs): make generate-pb; native tests of pkg/pb/plan, pkg/sql/plan, and pkg/sql/compile; the targeted multi-CN test in normal mode and with -race -count=2; full pkg/sql/compile with -race -count=1; CGo-configured go vet of the protobuf/compiler/planner/issues packages; compiler golangci-lint. CI run 34589843787 completed successfully, including Ubuntu UT, coverage, SCA, and both multi-CN BVT jobs.

The SQL regression uses the existing authenticated embedded fixture and real MySQL frontend. It adds one one-row table and reuses the fixture; no additional service or mo-tester changes are needed. The deterministic stale-plan proof requires the in-process compiler barrier and held writer, so it remains in this integration suite rather than a separate external BVT script.

Residual risks

The protobuf field is additive. The coordinator resolves/retries or rejects unresolved execution plans before sources start; ordinary EXPLAIN and schema-only consumers retain immediate missing-key rejection. This does not introduce a global synchronous catalog-publication barrier or a new retry mechanism. Required CI and human review remain separate from local verification.

@mergify mergify Bot added the kind/bug Something isn't working label Sep 10, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Sep 10, 2026
@gouhongshen
gouhongshen force-pushed the agent/issue-28639-94d7deef branch from e5a9038 to c30779e Compare September 10, 2026 14:52
@gouhongshen

Copy link
Copy Markdown
Contributor Author

Unrelated CI blockers from MatrixOne ALL CI run 34491898016 (attempt 1):

@gouhongshen
gouhongshen force-pushed the agent/issue-28639-94d7deef branch from 435e98d to b264c48 Compare September 11, 2026 05:48
@gouhongshen
gouhongshen force-pushed the agent/issue-28639-94d7deef branch from b264c48 to dd95a4d Compare September 11, 2026 06:10
@gouhongshen
gouhongshen force-pushed the agent/issue-28639-94d7deef branch from dd95a4d to 2f7921e Compare September 11, 2026 06:17

@XuPeng-SH XuPeng-SH 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 480add4 against main 23b20ea. One concrete validation-boundary regression remains.

[P2] Preserve missing-index validation for consumers that never run prePipelineInitializer. recordUnresolvedIndexHint now admits every non-prepared permanent-table SELECT with a lockable ObjRef, but the deferred 1176 is restored only by Compile.prePipelineInitializer. Ordinary EXPLAIN instead calls frontend.doExplainStmt -> buildPlanWithAuthorization -> writeExplainResult directly. With CREATE TABLE t(id INT PRIMARY KEY); EXPLAIN SELECT id FROM t FORCE INDEX(idx_missing);, planning now succeeds with an unresolved marker and EXPLAIN emits a base-table plan instead of the former 1176. No DDL race is needed.

CREATE VIEW has the same boundary issue: genViewTableDef binds/optimizes the inner SELECT, validates temporary tables/plugins, then extracts columns and ViewSql; buildCreateView returns a DDL plan, not that marked Query. CREATE VIEW v AS SELECT id FROM t FORCE INDEX(idx_missing) can therefore persist an invalid definition without the new terminal check. A later SELECT from v then reaches the 1176. These are reachable consumers of the newly relaxed validation, not optional extra test preferences.

Please restrict deferral to an explicitly execution-owned/retry-capable planning context, or validate/retry unresolved hints at each non-executing consumer before returning EXPLAIN output or committing a view definition. Preserve immediate 1176 when no metadata-validation owner exists. Add both no-DDL-race negative cases. Also keep UnresolvedIndexHints in DeepCopyQuery: the manual copier currently omits the new correctness-bearing field, unlike protobuf round-trip; it should not disappear when a marked plan is copied.

Other closure review: planner canonicalization retains first-missing-name order; normal SELECT compilation includes parent metadata locking and returns the error before sources start, while Sirius rejects marked plans. Temporary/PREPARE/not-lock-meta cases remain immediate failures. The deterministic two-CN commit/rollback cases reuse the existing fixture and verify actual index use plus row visibility. The protobuf addition is additive and does not itself require sending an unresolved query to old CNs on the normal native path, because the coordinator must resolve/retry or fail before execution.

Evidence: current diff/producer/consumer source inspection and author-reported package, targeted multi-CN and race validation. I did not run native tests or independently execute the SQL counterexamples; findings are source-closed. No source modification or CI wait. Exact head/base rechecked before posting.

@gouhongshen

Copy link
Copy Markdown
Contributor Author

@XuPeng-SH — addressed your review in acb0f05478 after rebasing onto e2580f993a.

Preserve missing-index validation for consumers that never run prePipelineInitializer.

Confirmed as a valid, in-scope regression: the new real-frontend tests reproduced successful text EXPLAIN and invalid CREATE VIEW publication before the correction. The new deep-copy assertion also failed before the change.

The terminal check is now shared between native execution and the non-executing consumers: ordinary EXPLAIN (planner and frontend output paths), view definitions, and CTAS schema inference. Non-executing consumers return 1176 before output or catalog publication. Native SELECT keeps its existing metadata-lock/retry boundary. DeepCopyQuery preserves and independently copies unresolved hints and their parent references.

New tests cover ordinary/verbose/explicit-text EXPLAIN and CREATE VIEW with missing USE/FORCE/IGNORE/order-scoped hints, no catalog objects after rejected CREATE VIEW/CTAS, unchanged view results after rejected REPLACE/ALTER, valid hints, and copy mutation isolation. The existing deterministic regular-index writer commit/rollback and FULLTEXT cases are retained.

Validation results are recorded in the updated PR description. Full planner, compiler, and frontend packages passed; the complete targeted integration test passed three times and passed three more times with planner/compiler/frontend coverage instrumentation (32.219s, 21.6% coverage). Incremental lint reported zero issues.

No protected workflow/orchestration files or mo-tester changes. Re-requesting review; no merge performed.

@XuPeng-SH XuPeng-SH 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 updated head. The prior blockers are closed: validation now covers EXPLAIN and persisted view/CTAS consumers, and DeepCopy preserves the marker without aliasing ObjectRefs. The stale-definition path either retries through the existing bounded transaction retry or returns 1176 before data-source execution; I found no remaining correctness or liveness blocker. Exact-head CI is green.

@mergify

mergify Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-12 06:10 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-09-12 08:29 UTC · at 1695c139956e9dea5a6b5ef4bd02367cec63b164 · squash

This pull request spent 2 hours 18 minutes 27 seconds in the queue, including 53 minutes 45 seconds running CI.

Required conditions to merge

This branch was previously deployed

1 inactive deployment
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.

3 participants