Repository navigation
Conversation
…t sort matrixorigin#30193 pushes an explicit ORDER BY score DESC LIMIT into the covered fulltext2 search only through SORT -> PROJECT -> implicit score SORT -> search. matrixorigin#30189 then omits that implicit sort when the explicit ORDER BY overwrites it, so the push declined and the search ran unbounded. The implicit sort is now optional in pushCoveredFulltext2ScoreLimitFromSort. The test call added by matrixorigin#30193 also misses the orderOverwritten argument added by matrixorigin#30189, so pkg/sql/plan tests did not compile on main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 of 7 tasks
XuPeng-SH
pushed a commit
that referenced
this pull request
Oct 15, 2026
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [x] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue #30164 Integration follow-up to #30189 and #30193, based on main `8795f3699b` after the emergency revert #30285. References the optional-inner-sort repair in #30274; that reference PR is unchanged. ## What this PR does / why we need it: Restore removal of implicit fulltext relevance sorts when an explicit order replaces them, while preserving safe covered FULLTEXT2 score candidate limits. The revert restored compilation and Top-K behavior but also restored the redundant sort reported in #30164. The score-LIMIT consumer now accepts both `SORT -> PROJECT -> INDEX_SEARCH_SCAN` and the equivalent shape with an intervening implicit score sort. A present inner sort must still have the same single score-DESC key. Direct-column projection, exact-search, filter, pagination, rank, secondary-key, ASC and overflow barriers remain enforced. The outer sort retains SQL pagination; the search receives LIMIT+OFFSET (2 for LIMIT 2, 3 with OFFSET 1). Search-level rank is also explicitly rejected. Python UDF handlers are conservatively treated as order-sensitive: the wrapper registry flags cannot establish handler purity. This applies recursively inside scalar wrappers and preserves the implicit relevance order before their projections. Update all covered-rewrite test callers together with the ordering change. Public parse/bind/optimize regressions cover default implicit relevance order, explicit MATCH and score aliases, nested pages, LIMIT/OFFSET and unsafe controls. Typed tests independently cover the optional sort's equivalence and refusal barriers. Restore #30189's ordering regressions and extend the canonical candidate-limit BVT with distinct-score pages and combined candidate-bound/single-sort assertions. Validation on `3d263e5c79bef731a1667c8c294708818d932cf6` (local run content matches this commit): - Reproduced raw `461bc8e349` planner UT compilation failure at the missing boolean argument. On an amended baseline containing only that mechanical argument fix, `score_alias` and `score_alias_offset` fail their candidate-limit assertions. - A new public planning regression fails in all 6 direct/wrapped Python UDF scenarios on the previous PR head `25a66777d2`, and passes with the local purity-proof repair. - PASS: fresh native `make -j8 cgo`; focused regressions; complete `pkg/sql/plan` tests (`-count=1`); owning build and vet; incremental golangci-lint. - PASS (reused unchanged consumer evidence): focused FULLTEXT2 search/Top-K/candidate/INCLUDE tests, complete `pkg/fulltext2/plugin/search`, and complete `pkg/sql/colexec/vectorscan` tests. - PASS: default SIMD `mo-service` build and real SQL on a private macOS/arm64 instance, Go 1.27.1. Toolchain PATH was pinned after the system launcher's automatic switching failed. - PASS: normal mo-tester `-n -g -o` comparison of `fulltext2/fulltext2_candidate_limit.sql`, `fulltext2/fulltext2_covered.sql`, and `fulltext/fulltext_overwritten_order.sql`, twice on the same instance: **180/180 statements per round, zero ignored or abnormal**. Fixtures were staged byte-for-byte outside `.codex` to avoid mo-tester's dotted-path rewriting. - PASS: independent test-database residue checks after each round; graceful instance shutdown, closed test ports and removal of its data directory; Python UDF catalog entries are also removed. - Python handler execution: NOT_RUN. The new SQL regression uses real CREATE FUNCTION/EXPLAIN without a Python service to assert the ordering barrier; it does not claim external-handler runtime validation. - Pending: exact-head Linux CI and formal QA/performance acceptance. These functional checks do not claim a throughput improvement. QA required: yes — the full issue's performance acceptance and exact-head CI remain separate from local functional validation. Ready for review; #30164 remains open for QA/performance acceptance. Exact-head CI is still in progress. No scoring, defaults, index format, cache, remote benchmark or issue-lifecycle changes. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
issue #
Main regression from two PRs that merged close together and conflict: #30193 (
77ccd7c438, bound covered FULLTEXT2 score searches) and #30189 (461bc8e349, omit overwritten implicit fulltext ordering).What this PR does / why we need it:
1.
pkg/sql/plantests do not compile on main.#30189 added the trailing
orderOverwritten boolparameter; #30193 added a call inTestCoveredFulltext2ScoreLimitOnBoundSQLwithout it. The call now passesfalse, like the other calls in the file.2. The covered FULLTEXT2 score LIMIT is no longer pushed into the search.
With the call compiling,
TestCoveredFulltext2ScoreLimitOnBoundSQL/score_aliasand/score_alias_offsetfail on main (Expected value not to be nil). Query shape, a FULLTEXT2 index with INCLUDE columns:CandidateLimit = 2(3 withOFFSET 1).Cause:
pushCoveredFulltext2ScoreLimitFromSort(perf(plan): bound covered FULLTEXT2 score searches #30193) pushes the limit only throughSORT(score DESC, LIMIT)→PROJECT→ implicitSORT(score DESC)→INDEX_SEARCH_SCAN.tryApplyCoveredFulltext2,orderOverwrittenbranch).Fix: the implicit score sort is optional in
pushCoveredFulltext2ScoreLimitFromSort. It only repeats the outer score-DESC order. When it is present, its key is still checked; the project-list checks are unchanged.Tests
TestCoveredFulltext2ScoreLimitOnBoundSQL(all 9 cases) passes; the fullpkg/sql/planpackage passes.🤖 Generated with Claude Code