Repository navigation
fix(fulltext2): gate candidate LIMIT on exact pure-MUST filters - #27252
mergify[bot] merged 6 commits into
Conversation
08b37fb to
96c76d6
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? |
|
Queued — the merge queue status continues in this comment ↓. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
|
Addressed the volatile residual-filter finding in
The branch also includes the latest |
|
Also addressed the blocking volatile-residual finding from aunjgr, reviewed on the superseded |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
Merge Queue Status
This pull request spent 24 minutes 10 seconds in the queue, with no time running CI. ReasonThe pull request can't be updated
HintYou should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again. Requeued — the merge queue status continues in this comment ↓. |
aunjgr
left a comment
There was a problem hiding this comment.
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.
Merge Queue Status
This pull request spent 23 seconds in the queue, including 3 seconds running CI. Required conditions to merge
|
What type of PR is this?
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:
IN BOOLEAN MODEpure-MUST single-term clauses;LIMIT + OFFSET.It preserves current
mainbehavior 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:
UNIQUEJOINKEYS,PASS, orDROP.PASS(or a missing exact payload) disables the filter-dependent candidate bound so the final residual join cannot under-fill;DROPreturns no FULLTEXT2 rows; an exact payload retains the bound.Resetrestores the planned limit and clears query-local filter state.buildBooleanQueryAST. 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:
fix(fulltext2): push candidate limit only with exact prefiltersfix(fulltext2): gate candidate limit on exact pure-must filterstest(fulltext2): cover safe candidate limit pushdownfix(fulltext2): preserve runtime filter terminal statestest(fulltext2): cover runtime membership filter branchesValidation
Latest rebased base/head:
3a52dd0ecf7ad7ee04fcf14700682caaf5b3466ac405c7dd0f63dddcf031b74d69ca3b667cf8bc66Passed on the latest rebased head:
pkg/fulltext2,pkg/sql/plan,pkg/sql/colexec/table_function, andpkg/vectorindex/sqlexec;git diff --check;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:
pkg/fulltext2,pkg/common/docfilter,pkg/vectorindex/sqlexec, andpkg/sql/colexec/table_function;pkg/fulltext2race suite;go build ./cmd/mo-service;go vet;git diff --check.BVT on the same semantic patch before this history-only rebase:
fulltext2_candidate_limit: 35/35 passed;fulltext_plugin_smokecontrol: 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 SHA256fb1449645db40815223701c21f6401b6b21006f18b15828e774d075be9213582.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_searchtable function.Automated terminal:
test/distributed/cases/fulltext2/fulltext2_candidate_limit.sqlplus focused Go tests.Remaining validation: fresh exact-head CI and renewed semantic review. The PR is Ready for review while these gates are pending.