Skip to content

fix(fulltext): validate stale cross-CN plans before execution - #28289

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
LeftHandCold:fix/fulltext-cross-cn-visibility-28286
Sep 7, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
LeftHandCold:fix/fulltext-cross-cn-visibility-28286

Conversation

@LeftHandCold

@LeftHandCold LeftHandCold commented Sep 6, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Enhancement
  • refactoring
  • pkg-wasm
  • user-interface

Which issue(s) this PR fixes:

Fixes #28286

What this PR does / why we need it:

A MATCH ... AGAINST statement can be planned on one CN with a table definition that predates a concurrent CREATE FULLTEXT INDEX committed by another CN.

The planner rewrites fulltext_match only when the local TableDef.Indexes already contains a usable FULLTEXT index. With the stale definition, the unresolved runtime placeholder remains in the plan. Ordinary SELECT plans previously enabled the pre-pipeline mo_tables metadata lock only when they contained a Node_LOCK_OP, so this plan skipped the existing catalog-version validation and executed the placeholder, returning error 20105 even though the DDL had already committed and populated the hidden index table.

This change recognizes unresolved fulltext_match and fulltext_match_score expressions in SELECT plans and enables the existing metadata validation path. If a DDL committed after the plan snapshot, lockservice's retained table commit watermark causes the RC snapshot to advance and returns ErrTxnNeedRetryWithDefChanged, rebuilding the plan with the current index definition.

The scope is intentionally narrow:

  • Successfully rewritten FULLTEXT plans contain no unresolved placeholder and take no additional metadata lock.
  • Ordinary SELECT behavior is unchanged.
  • A genuine MATCH query without a FULLTEXT index still returns the original 20105 error.
  • This does not change lock protocols, catalog formats, DDL transaction semantics, or index data paths.

The regression test deterministically reproduces the production ordering across two CNs:

  1. A query CN compiles a stale unresolved FULLTEXT plan and pauses before metadata validation.
  2. Another CN commits CREATE FULLTEXT INDEX.
  3. The query resumes only after the DDL is fully committed.
  4. Metadata validation forces retry/replan, and MATCH succeeds on the non-DDL CN.

Disabling only the new needLockMeta decision makes the same test fail deterministically with the incident's 20105 error after the DDL has committed.

Local validation:

  • go test ./pkg/sql/compile -count=1 -timeout=15m
  • go test ./pkg/tests/issues -run '^TestIssue27487ConcurrentInsertIsIncludedInNewIndex$' -count=3 -timeout=8m
  • go test -race ./pkg/tests/issues -run '^TestIssue27487ConcurrentInsertIsIncludedInNewIndex$/fulltext_index$' -count=1 -timeout=10m
  • git diff --check

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

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

Deep review of 63021cb, including issue #28286, the metadata-lock/DDL-watermark path, snapshot refresh and Compile.Run replanning, fault-barrier cleanup, and ordinary-query overhead.

The stale-plan repair direction is sound: validate before pipeline execution, use the existing definition-changed retry rather than sleeps, and preserve the actual missing-index error. The current cross-CN regression passes. However, the new classifier also enables metadata locking for already-rewritten ordinary FULLTEXT predicates because it examines unreachable optimizer nodes. This violates the stated narrow scope and introduces avoidable locking/waiting on the common path. See the reproduced P2 below.

Executed on this head with controlled macOS CGo/native inputs:

  • TestSelectMetaLockRequirement and matching TestLockMeta tests: PASS.
  • TestIssue27487ConcurrentInsertIsIncludedInNewIndex in a disposable embedded two-CN cluster: PASS (12.893 s package execution).
  • Added review-only tests using mysql.Parse + plan.BuildPlan and the existing docs_ft mock catalog: bare MATCH predicate and COUNT(*) variants reproduce the false-positive classifier; projection score, wrapped predicate, and ORDER BY controls pass. The only remaining placeholder is in an unreachable FILTER node, not in the executable graph.
  • git diff --check: PASS.

No production changes were made. This review does not claim a production performance benchmark or complete historical incident reproduction. Please constrain the classifier to executable plan nodes and protect it with real optimizer-output tests, then retain the existing stale-plan cross-CN test as the positive control.

Comment thread pkg/sql/compile/compile2.go Resolved

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

Review of commit 63021cb141f6eea6b2f1a4b6b9938dea67cbf12d.

No blocking finding in the reviewed change. Unresolved FULLTEXT placeholders enable the existing pre-execution metadata validation/retry path, and the deterministic cross-CN regression covers a stale plan resuming after CREATE FULLTEXT INDEX commits. Ordinary SELECT and genuine missing-index controls are retained.

Evidence: source review and existing passing CI for this commit; no new local test run was performed for this review.

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

Deep-reviewed exact head 63021cb141f6eea6b2f1a4b6b9938dea67cbf12d. The deterministic cross-CN regression passes, but the production classifier introduces a blocking false positive for already-rewritten indexed FULLTEXT queries. I reproduced it with a real parser + optimizer plan; details are inline. Validation: focused compile tests PASS; cross-CN TestIssue27487ConcurrentInsertIsIncludedInNewIndex PASS; focused race test PASS (100 runs); go vet PASS. The complete pkg/sql/compile suite also ran, with five pre-existing parquet fanout failures in unrelated scope_test.go tests.

Comment thread pkg/sql/compile/compile2.go Resolved
@LeftHandCold

Copy link
Copy Markdown
Collaborator Author

Addressed both reviews in 02a5a17.

I verified the finding independently. The optimizer retains the original FILTER containing fulltext_match after rewriting bare MATCH and COUNT(*) queries to use the FULLTEXT index. Scanning all Query.Nodes therefore added metadata locking to valid, already-rewritten queries.

The classifier now traverses the executable graph from Query.Steps through Children and SourceStep indirections, with visited-node deduplication and node/step bounds checks. Abandoned filters no longer trigger metadata locking.

Added real parser/optimizer tests for bare MATCH, COUNT(*), score projection, wrapped predicates and score ordering. The first two explicitly assert that the abandoned MATCH remains in optimizer storage while the classifier reports no lock and no unresolved expression, directly guarding the reported false positive. Graph tests cover reachable placeholders, LOCK_OP, shared/cyclic edges, nil nodes and invalid references. The original two-CN test still covers stale-index retry and the genuine missing-index error.

Validation passed:

  • Focused classifier and LockMeta tests, including race mode.
  • TestIssue27487ConcurrentInsertIsIncludedInNewIndex, all subcases under race (15.273s).
  • git diff --check.

This corrects the scope of the original fix: only an executable unresolved FULLTEXT expression requests the additional metadata validation.

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

Deep re-review of exact head 9613b78d031a839f276a338fa8b48a9fe4669cf3, including the increment from my previous reviewed head 02a5a178d5d755cf2272ff9d2e0152e4121991b0 and the complete three-file diff against base f14eb824df4c74fb341ebecd46d2da3358503a95. I read all historical reviews, inline comments, author replies and resolved/outdated thread states.

Both prior findings are closed. The executable graph walk continues to exclude abandoned optimizer nodes, and the classifier now checks ORDER BY plus other executable expression slots, including nested window expressions. The real planner regression covers the original unindexed ORDER BY counterexample, while indexed MATCH/COUNT negative controls retain abandoned filters without requesting metadata locks. DML already enables metadata validation independently, so its separate expression slots do not require this SELECT classifier.

The existing pre-pipeline lock and definition-changed retry path remains the owner of catalog validation, snapshot advancement and replanning. The fault barrier is context-aware and has bounded cleanup. No new resource, lock-order or correctness blocker was found.

Validation on this exact head: native dependencies and cgo built successfully; complete pkg/sql/compile tests passed (4.499s); focused classifier/planner tests with -race passed (1.256s); the two-CN TestIssue27487ConcurrentInsertIsIncludedInNewIndex passed (13.191s), including WHERE, ORDER BY and genuine missing-index controls. GitHub required checks are green. Worktree is clean and git diff --check passes.

@mergify mergify Bot added the queued label Sep 7, 2026
@mergify

mergify Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-07 10:20 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-07 10:52 UTC · at c5a7fa520e44335fc90a4da1c9c17e61363deeda

This pull request spent 31 minutes 30 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]

Reason

Pull request #28289 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.

The author needs to enable "Allow edits from maintainers" on this pull request.

Failing checks:

Hint

You 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.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit a989dab into matrixorigin:main Sep 7, 2026
25 of 26 checks passed
@mergify mergify Bot added dequeued and removed queued labels Sep 7, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…origin#28289)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Enhancement
- [ ] refactoring
- [ ] pkg-wasm
- [ ] user-interface

## Which issue(s) this PR fixes:

Fixes matrixorigin#28286

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

A `MATCH ... AGAINST` statement can be planned on one CN with a table
definition that predates a concurrent `CREATE FULLTEXT INDEX` committed
by another CN.

The planner rewrites `fulltext_match` only when the local
`TableDef.Indexes` already contains a usable FULLTEXT index. With the
stale definition, the unresolved runtime placeholder remains in the
plan. Ordinary SELECT plans previously enabled the pre-pipeline
`mo_tables` metadata lock only when they contained a `Node_LOCK_OP`, so
this plan skipped the existing catalog-version validation and executed
the placeholder, returning error 20105 even though the DDL had already
committed and populated the hidden index table.

This change recognizes unresolved `fulltext_match` and
`fulltext_match_score` expressions in SELECT plans and enables the
existing metadata validation path. If a DDL committed after the plan
snapshot, lockservice's retained table commit watermark causes the RC
snapshot to advance and returns `ErrTxnNeedRetryWithDefChanged`,
rebuilding the plan with the current index definition.

The scope is intentionally narrow:

- Successfully rewritten FULLTEXT plans contain no unresolved
placeholder and take no additional metadata lock.
- Ordinary SELECT behavior is unchanged.
- A genuine MATCH query without a FULLTEXT index still returns the
original 20105 error.
- This does not change lock protocols, catalog formats, DDL transaction
semantics, or index data paths.

The regression test deterministically reproduces the production ordering
across two CNs:

1. A query CN compiles a stale unresolved FULLTEXT plan and pauses
before metadata validation.
2. Another CN commits `CREATE FULLTEXT INDEX`.
3. The query resumes only after the DDL is fully committed.
4. Metadata validation forces retry/replan, and MATCH succeeds on the
non-DDL CN.

Disabling only the new `needLockMeta` decision makes the same test fail
deterministically with the incident's 20105 error after the DDL has
committed.

Local validation:

- `go test ./pkg/sql/compile -count=1 -timeout=15m`
- `go test ./pkg/tests/issues -run
'^TestIssue27487ConcurrentInsertIsIncludedInNewIndex$' -count=3
-timeout=8m`
- `go test -race ./pkg/tests/issues -run
'^TestIssue27487ConcurrentInsertIsIncludedInNewIndex$/fulltext_index$'
-count=1 -timeout=10m`
- `git diff --check`

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…origin#28289)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Enhancement
- [ ] refactoring
- [ ] pkg-wasm
- [ ] user-interface

## Which issue(s) this PR fixes:

Fixes matrixorigin#28286

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

A `MATCH ... AGAINST` statement can be planned on one CN with a table
definition that predates a concurrent `CREATE FULLTEXT INDEX` committed
by another CN.

The planner rewrites `fulltext_match` only when the local
`TableDef.Indexes` already contains a usable FULLTEXT index. With the
stale definition, the unresolved runtime placeholder remains in the
plan. Ordinary SELECT plans previously enabled the pre-pipeline
`mo_tables` metadata lock only when they contained a `Node_LOCK_OP`, so
this plan skipped the existing catalog-version validation and executed
the placeholder, returning error 20105 even though the DDL had already
committed and populated the hidden index table.

This change recognizes unresolved `fulltext_match` and
`fulltext_match_score` expressions in SELECT plans and enables the
existing metadata validation path. If a DDL committed after the plan
snapshot, lockservice's retained table commit watermark causes the RC
snapshot to advance and returns `ErrTxnNeedRetryWithDefChanged`,
rebuilding the plan with the current index definition.

The scope is intentionally narrow:

- Successfully rewritten FULLTEXT plans contain no unresolved
placeholder and take no additional metadata lock.
- Ordinary SELECT behavior is unchanged.
- A genuine MATCH query without a FULLTEXT index still returns the
original 20105 error.
- This does not change lock protocols, catalog formats, DDL transaction
semantics, or index data paths.

The regression test deterministically reproduces the production ordering
across two CNs:

1. A query CN compiles a stale unresolved FULLTEXT plan and pauses
before metadata validation.
2. Another CN commits `CREATE FULLTEXT INDEX`.
3. The query resumes only after the DDL is fully committed.
4. Metadata validation forces retry/replan, and MATCH succeeds on the
non-DDL CN.

Disabling only the new `needLockMeta` decision makes the same test fail
deterministically with the incident's 20105 error after the DDL has
committed.

Local validation:

- `go test ./pkg/sql/compile -count=1 -timeout=15m`
- `go test ./pkg/tests/issues -run
'^TestIssue27487ConcurrentInsertIsIncludedInNewIndex$' -count=3
-timeout=8m`
- `go test -race ./pkg/tests/issues -run
'^TestIssue27487ConcurrentInsertIsIncludedInNewIndex$/fulltext_index$'
-count=1 -timeout=10m`
- `git diff --check`

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…origin#28289)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Enhancement
- [ ] refactoring
- [ ] pkg-wasm
- [ ] user-interface

## Which issue(s) this PR fixes:

Fixes matrixorigin#28286

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

A `MATCH ... AGAINST` statement can be planned on one CN with a table
definition that predates a concurrent `CREATE FULLTEXT INDEX` committed
by another CN.

The planner rewrites `fulltext_match` only when the local
`TableDef.Indexes` already contains a usable FULLTEXT index. With the
stale definition, the unresolved runtime placeholder remains in the
plan. Ordinary SELECT plans previously enabled the pre-pipeline
`mo_tables` metadata lock only when they contained a `Node_LOCK_OP`, so
this plan skipped the existing catalog-version validation and executed
the placeholder, returning error 20105 even though the DDL had already
committed and populated the hidden index table.

This change recognizes unresolved `fulltext_match` and
`fulltext_match_score` expressions in SELECT plans and enables the
existing metadata validation path. If a DDL committed after the plan
snapshot, lockservice's retained table commit watermark causes the RC
snapshot to advance and returns `ErrTxnNeedRetryWithDefChanged`,
rebuilding the plan with the current index definition.

The scope is intentionally narrow:

- Successfully rewritten FULLTEXT plans contain no unresolved
placeholder and take no additional metadata lock.
- Ordinary SELECT behavior is unchanged.
- A genuine MATCH query without a FULLTEXT index still returns the
original 20105 error.
- This does not change lock protocols, catalog formats, DDL transaction
semantics, or index data paths.

The regression test deterministically reproduces the production ordering
across two CNs:

1. A query CN compiles a stale unresolved FULLTEXT plan and pauses
before metadata validation.
2. Another CN commits `CREATE FULLTEXT INDEX`.
3. The query resumes only after the DDL is fully committed.
4. Metadata validation forces retry/replan, and MATCH succeeds on the
non-DDL CN.

Disabling only the new `needLockMeta` decision makes the same test fail
deterministically with the incident's 20105 error after the DDL has
committed.

Local validation:

- `go test ./pkg/sql/compile -count=1 -timeout=15m`
- `go test ./pkg/tests/issues -run
'^TestIssue27487ConcurrentInsertIsIncludedInNewIndex$' -count=3
-timeout=8m`
- `go test -race ./pkg/tests/issues -run
'^TestIssue27487ConcurrentInsertIsIncludedInNewIndex$/fulltext_index$'
-count=1 -timeout=10m`
- `git diff --check`

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

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/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CREATE FULLTEXT INDEX can be invisible to another CN immediately after successful DDL

5 participants