Skip to content

fix(fulltext2): gate candidate LIMIT on exact pure-MUST filters - #27252

Merged
mergify[bot] merged 6 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/fulltext2-safe-candidate-limit
Aug 30, 2026
Merged

mergify[bot] merged 6 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/fulltext2-safe-candidate-limit

Conversation

@VioletQwQ-0

@VioletQwQ-0 VioletQwQ-0 commented Aug 17, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement

Which issue(s) this PR fixes:

Issue #27251

What this PR does / why we need it:

This change makes FULLTEXT2 candidate LIMIT pushdown safe for the narrow exact-filter path:

  • a single FULLTEXT2 MATCH stream;
  • literal IN BOOLEAN MODE pure-MUST single-term clauses;
  • an exact integer primary-key membership prefilter;
  • a literal LIMIT/OFFSET, with the candidate bound set to LIMIT + OFFSET.

It preserves current main behavior when there is no residual WHERE predicate, including dynamic LIMIT and INCLUDE in-index filtering.

Approximate Bloom membership, BIT/VARCHAR/UUID primary keys, complex Boolean shapes, implicit or explicit phrases/prefixes, multiple MATCH streams, prepared residual-path limits, and pushdown-disabled plans keep the unbounded candidate path.

This update also closes the two semantic review findings:

  • Runtime-filter terminal status is preserved as UNIQUEJOINKEYS, PASS, or DROP. PASS (or a missing exact payload) disables the filter-dependent candidate bound so the final residual join cannot under-fill; DROP returns no FULLTEXT2 rows; an exact payload retains the bound. Reset restores the planned limit and clears query-local filter state.
  • Planner eligibility uses the executor's parser-aware buildBooleanQuery AST. Default/ngram CJK phrase/prefix shapes are rejected, while supported JSON-value atomic terms and genuine single gojieba terms remain eligible.

The implementation remains five focused commits:

  1. fix(fulltext2): push candidate limit only with exact prefilters
  2. fix(fulltext2): gate candidate limit on exact pure-must filters
  3. test(fulltext2): cover safe candidate limit pushdown
  4. fix(fulltext2): preserve runtime filter terminal states
  5. test(fulltext2): cover runtime membership filter branches

Validation

Latest rebased base/head:

  • Base: 3a52dd0ecf7ad7ee04fcf14700682caaf5b3466a
  • Head: c405c7dd0f63dddcf031b74d69ca3b667cf8bc66

Passed on the latest rebased head:

  • owning package tests for pkg/fulltext2, pkg/sql/plan, pkg/sql/colexec/table_function, and pkg/vectorindex/sqlexec;
  • focused race tests for the changed planner, parser, runtime-filter waiter, and FULLTEXT2 table-function paths;
  • git diff --check;
  • exact-head semantic preflight.

The broader controlled Linux/CGo validation below was run on the same semantic patch before this history-only rebase; the complete base-to-head patch is byte-identical:

  • focused FULLTEXT2 parser eligibility tests;
  • status-preserving unique-key waiter tests;
  • deterministic hashbuild PASS producer tests (optional allocation rejection, marshal-budget rejection, one-byte-short admission, and spill);
  • focused Planner candidate-limit route and boundary tests;
  • focused FULLTEXT2 table-function PASS/DROP/Available/None, Reset, malformed-payload, and under-fill tests;
  • owning package tests for pkg/fulltext2, pkg/common/docfilter, pkg/vectorindex/sqlexec, and pkg/sql/colexec/table_function;
  • focused race tests plus the full pkg/fulltext2 race suite;
  • go build ./cmd/mo-service;
  • owning-package go vet;
  • git diff --check.

BVT on the same semantic patch before this history-only rebase:

  • fulltext2_candidate_limit: 35/35 passed;
  • classic FULLTEXT fulltext_plugin_smoke control: 12/12 passed.

The BVT covers exact BIGINT LIMIT 2 OFFSET 1 (candidate bound 3), under-fill protection, pushdown ON/OFF equivalence, VARCHAR/UUID rejection, complex Boolean/phrase/prefix/CJK rejection, and preservation of no-residual and INCLUDE candidate limits.

Semantic preflight: PASS at exact head c405c7dd0f63dddcf031b74d69ca3b667cf8bc66, diff SHA256 fb1449645db40815223701c21f6401b6b21006f18b15828e774d075be9213582.

The historical host-busy directional run observed about 1.11x QPS and downstream candidates falling from 15,064 to 100. This PR does not claim a 20% search-kernel improvement; FULLTEXT2 search time was essentially unchanged.

Compatibility and follow-up

No SQL syntax, DDL, index format, FST, CDC, runtime-filter wire protocol, protobuf, or public configuration is changed. Natural phrase, BM25 OR, complex Boolean, and no-LIMIT paths remain on their existing routes.

Filtered scan reuse is intentionally out of scope. Existing cost evidence does not satisfy the agreed scan-reuse gate in enough representative scenarios.

QA required: yes.

Production entrypoint: FULLTEXT2 Planner candidate-limit routing and the fulltext2_search table function.

Automated terminal: test/distributed/cases/fulltext2/fulltext2_candidate_limit.sql plus focused Go tests.

Remaining validation: fresh exact-head CI and renewed semantic review. The PR is Ready for review while these gates are pending.

@VioletQwQ-0
VioletQwQ-0 force-pushed the codex/fulltext2-safe-candidate-limit branch from 08b37fb to 96c76d6 Compare August 18, 2026 02:48
@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Aug 18, 2026
@VioletQwQ-0
VioletQwQ-0 marked this pull request as ready for review August 18, 2026 04:41
@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 Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@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 completed on exact head 1f01793be46ef7ddf08bce03149e30dc25c8673c against merge-base 52336df80596de93a3f279dfcd6c993d7227bcb9. I read every changed hunk, traced planner admission through runtime-filter PASS/DROP/UNIQUEJOINKEYS and table-function Reset/streaming cleanup, reviewed the BVT oracle, and checked the conflict-free merge with current main. One correctness blocker remains.

[P1] Do not treat a volatile residual predicate as an exact, stable candidate domain.

At pkg/sql/plan/apply_indices_fulltext.go:417-436, any non-empty residual filter can enable the exact-membership candidate LIMIT. The prefilter branch then copies the original scan with its complete FilterList at lines 653-676, while the original outer scan retains and evaluates the same filters again. This is not a single exact domain when a residual contains a volatile function such as rand(): the copied scan and final scan evaluate it independently.

Concrete reachable path for MATCH ... AGAINST('+needle' IN BOOLEAN MODE) AND rand() < 0.5 LIMIT 1: the copied scan admits the highest-scoring row, so its PK enters UNIQUEJOINKEYS; FULLTEXT2 keeps only that top-1 candidate; the outer scan's second evaluation rejects it. A lower-scoring row that both evaluations admit is never considered, so the query returns zero rows where the unbounded candidate path returns one. Exact integer PK membership does not close this gap because the predicate result itself is unstable across the two scans.

Please keep the candidate stream unbounded whenever any final residual is volatile, and avoid reevaluating volatile predicates on the copied prefilter scan (split deterministic prefilter predicates from final-only volatile predicates, or disable this prefilter topology for that shape). Add a planner regression proving the volatile residual does not receive the table-function LIMIT and is not duplicated across both scans.

aunjgr
aunjgr previously requested changes Aug 30, 2026

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

Reviewed exact head 1f01793 against main. One blocking correctness path remains. applyIndicesForAggUsingFullTextIndex treats any non-empty residual FilterList as an exact prefilter candidate, copies the complete scan/filter into secondScanNode, and retains the same filter on the outer scan. Volatile expressions are therefore evaluated twice. For MATCH('+needle' IN BOOLEAN MODE) AND rand() < 0.5 LIMIT 1, the copied scan can admit the highest-scoring row into UNIQUEJOINKEYS, the bounded FULLTEXT2 stream keeps only that candidate, and the outer scan's independent rand() evaluation can reject it; a lower-scoring qualifying row is never considered, so the bounded path under-fills relative to the established unbounded path. Exact integer membership does not stabilize the predicate. Keep the candidate stream unbounded whenever a final residual is volatile and avoid duplicating volatile predicates into the copied prefilter scan, or split deterministic prefilter predicates from final-only predicates. Add a planner regression proving no TVF candidate LIMIT and no double placement for RAND/another real-time function. Exact-head green CI does not cover this shape.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Addressed the volatile residual-filter finding in 938becd8ee7b198137bee3c427cc98c68c588d29.

  • The planner now disables the duplicated exact-prefilter topology whenever a residual contains a volatile function. The final scan evaluates rand() once, and the FULLTEXT2 table function remains unbounded for this route.
  • Added TestFullTextCandidateLimitRejectsVolatileResidualFilter, which asserts a nil table-function candidate limit and exactly one table scan retaining the volatile residual.
  • Added the corresponding FULLTEXT2 EXPLAIN case and result oracle.
  • Validation: focused ^TestFullTextCandidateLimit CGo tests (count=3) PASS; full ./pkg/sql/plan CGo test PASS; focused and owning-package CGo race tests PASS; make build PASS; local mo-tester BVT could not start because Java Runtime is unavailable.

The branch also includes the latest upstream/main merge. Please re-review the current head.

@VioletQwQ-0
VioletQwQ-0 requested a review from XuPeng-SH August 30, 2026 08:25
@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Also addressed the blocking volatile-residual finding from aunjgr, reviewed on the superseded 1f01793be46ef7ddf08bce03149e30dc25c8673c head. The current 938becd8ee7b198137bee3c427cc98c68c588d29 head disables the duplicated prefilter topology for volatile residuals, keeps the FULLTEXT2 candidate stream unbounded, and includes the planner regression for single evaluation. The validation and local BVT limitation are recorded in the preceding reply. Please re-review the current head.

@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 completed on exact head 938becd against merge-base a3f1328.

The prior volatile-residual blocker is closed: volatile predicates now disable the duplicated prefilter topology before a copied scan is built, so the TVF remains unbounded and the final scan evaluates the volatile predicate only once.

I traced the full closure across planner admission, parser-aware pure-MUST eligibility, exact integer membership filters, PASS/DROP/UNIQUEJOINKEYS handling, Search/Reset lifecycle, cancellation and ownership paths, and BVT boundaries. Approximate or noninteger filters, dynamic inputs, richer Boolean/CJK forms, multi-stream cases, disabled pushdown, and classic fulltext remain conservatively unbounded. PASS safely falls back to unbounded streaming; DROP terminates empty; reset restores the planned state. No new protocol, index-format, catalog, CDC, or compatibility surface is introduced.

Exact-head focused CGo tests passed for the parser, planner, table-function runtime-filter states, membership filter, reset, and underfill model. Full exact-head UT, SCA, build, coverage, and BVT CI is green. Current-main drift does not overlap the affected closure.

No blocking correctness, performance, hang, leak, or unhappy-path issue found.

@mergify

mergify Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-30 09:31 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-08-30 09:55 UTC · at 9e72102973c01fa70ea62fe1ba4b7b024989b385

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

Reason

The pull request can't be updated

For security reasons, Mergify can't update this pull request. Try updating locally.
GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/jstfu-maven-cache.yaml without workflows permission

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Requeued — the merge queue status continues in this comment ↓.

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

Reviewed exact head 9e72102. The volatile-residual blocker is closed at the correct ownership boundary: containsVolatileFunction is evaluated before the copied prefilter topology is constructed, so any volatile residual disables filter-dependent candidate limiting, leaves the FULLTEXT2 stream unbounded, and keeps the volatile expression on only the final scan. Wrapped MATCH residuals remain independently unbounded through the existing wrappedMatchFilters guard. The new typed planner regression proves both necessary structural claims (nil TVF limit and one volatile scan placement), while the existing BVT and runtime-filter tests cover the public exact-filter path and PASS/DROP/UNIQUEJOINKEYS lifecycle. All GitHub Actions workflows are green or intentionally skipped; the lone red status is a Mergify queue-policy rule, not CI. I found no blocking correctness, lifecycle, or performance issue in the updated diff.

@mergify

mergify Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-30 17:16 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-08-30 17:16 UTC · at c405c7dd0f63dddcf031b74d69ca3b667cf8bc66 · squash

This pull request spent 23 seconds in the queue, including 3 seconds running CI.

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

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/enhancement size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants