Repository navigation
fix(plan): rewrite MATCH beneath a window operator and OUTER JOIN to the fulltext index (#28974) - #29069
Conversation
…dex (matrixorigin#28974) A top-level WHERE MATCH() AGAINST() predicate is served by a FULLTEXT/FULLTEXT2 index, but adding a window function (e.g. ROW_NUMBER() OVER (...)) put a WINDOW node between the query block and the base scan. applyIndices anchors the fulltext rewrite at PROJECT/SORT/AGG only, so the scan's fulltext_match survived beneath the WINDOW and execution failed with ERROR 20105. Add a Node_WINDOW fulltext anchor (mirroring the Node_AGG anchor from matrixorigin#28681): applyIndicesForWindowUsingFullTextIndex builds the index-scan join for the scan's MATCH filters and reparents the window's child onto it. Post-order recursion runs this before the PROJECT pass, which then finds no MATCH and no-ops. Also make replaceScoreFnInExprBy traverse Expr_W (window function, OVER partition/order-by), so a MATCH that also appears inside the window spec -- e.g. ROW_NUMBER() OVER (ORDER BY match(...)) with the same MATCH in WHERE -- is rewritten to the score column instead of surviving as 20105. Aggregate/projection exprs never contain an Expr_W, so existing callers are unaffected. Verified live for both FULLTEXT2 and classic FULLTEXT: the window+MATCH query now returns the ranked rows. Unit test TestFullTextWindowMatchRewritten and BVT fulltext2_window_match (control, primary, EXPLAIN fulltext2_search, and the combined window-orderby case) cover it. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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? |
…8974) Classic-FULLTEXT sibling of fulltext2_window_match: the same window+MATCH rewrite fix applies to both algorithms (one shared applyIndices path). Covers the control MATCH, the primary ROW_NUMBER() OVER (...) + WHERE MATCH case, an EXPLAIN assertion that the fulltext_index_scan TVF is reached beneath the WINDOW, and the combined case where the same MATCH also appears in the window's OVER order-by. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
fixed outer join |
aunjgr
left a comment
There was a problem hiding this comment.
Reviewed c1e8e53. The full-text rewrite preserves the outer-join side, safely handles the admitted WINDOW/PARTITION/PROJECT chains, performs binding-aware score replacement, and has meaningful result and plan coverage for LEFT, RIGHT, SINGLE, null-extension, partitioned, and stacked-plan cases. I found no blocking correctness issue.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review(head c1e8e53)
结论:REQUEST_CHANGES。上次旧 head 的两项 P2 已修复,但发现 1 个新的 P2;未发现 P0/P1。
- [P2] WINDOW.FilterList 中已被索引服务的 MATCH 没有继续改写。见 apply_indices_fulltext.go:358-367。rewriteWindowMatchesFromServed 只处理 WinSpecList 和紧邻 PARTITION 的 OrderBy,遗漏 windowNode.FilterList。
- 外层谓词经过 PROJECT 后,score 引用会被展开为原始 MATCH;含 window binding 的条件进入 WINDOW.FilterList 并在窗口后求值,但该独立副本没有被替换。WINDOW 编译时仍会执行 compileRestrict,残留 MATCH 可能返回 20105 unsupported。
- 典型反例:窗口中计算 MATCH score,外层同时以 rn 和 score 过滤;WHERE MATCH 已被服务,但窗口后的 FilterList 仍保留原始 MATCH。
建议使用同一 binding-aware rewriter 处理窗口后谓词,保持窗口求值位置,并补 typed-plan UT 以及 FULLTEXT/FULLTEXT2 两种索引的结果 BVT。
旧问题复核:PARTITION 下探、OUTER JOIN null-preservation、祖先排序和叠加窗口 score 传播已修复;索引 scope、NULL/空匹配、资源释放未发现新的确定性问题。
当前 head 的 Build、Linux UT、SCA、Coverage、两组 BVT 和 CI Required 均通过,但相关 BVT 没覆盖上述窗口后 FilterList 反例。CI:https://github.com/matrixorigin/matrixone/actions/runs/35242693427
aptend
left a comment
There was a problem hiding this comment.
Deep re-review at exact head c1e8e53. The previous PARTITION traversal and served-score propagation findings are fixed, and the new outer-join rewrite preserves the nullable-side semantics in the covered LEFT/RIGHT/SINGLE cases. However, one execution-blocking window path remains: a served MATCH copied into WINDOW.FilterList is not rewritten, so compileRestrict can still evaluate raw fulltext_match and return 20105. I reproduced this with a temporary typed-plan regression: after applyIndices, one reachable fulltext_match remained in WINDOW.FilterList while the scan copy had been consumed. The targeted existing window/outer-join tests pass, but they do not cover this post-window predicate shape.
…igin#28974) rewriteWindowMatchesFromServed rewrote a served fulltext_match in the WINDOW's WinSpecList and in the adjacent PARTITION order-by, but skipped the window node's own FilterList. A post-window predicate that also references a window column (e.g. `rn = 1 OR score > 0`) cannot be pushed below the WINDOW, so it stays on WINDOW.FilterList and is evaluated after the window (Node_WINDOW runs compileRestrict after compileWin). Predicate pushdown expands the projected `score` alias back to the raw MATCH there, so that post-window copy kept a bare fulltext_match even though the scan's WHERE MATCH was served and removed -- reaching execution as ERROR 20105 for both FULLTEXT and FULLTEXT2. Apply the same binding-aware rewriter (servedFullTextScoreSameTable) to windowNode.FilterList, so the post-window copy resolves to the served score column at the window's evaluation position; a MATCH no served scan answers is left intact and still raises 20105. Tests: TestFullTextWindowFilterListMatchRewritten (typed plan; verified to fail without the fix). BVT fulltext_window_match / fulltext2_window_match add the subquery-window + post-window `rn = 1 OR score > 0` counterexample, asserting the rows return and the index scan is used. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
fixed |
XuPeng-SH
left a comment
There was a problem hiding this comment.
P2 blocker at apply_indices_fulltext.go:366-370: the fix only rewrites MATCH expressions in WINDOW.FilterList. A reachable outer FILTER above WINDOW can still retain a served fulltext_match when it does not reference window columns and cannot be pushed by partition keys. I reproduced this with a real query using score > 0: the optimized plan has one fulltext index scan but still retains one reachable fulltext_match, which enters the unsupported execution path. Please add binding-aware replacement for this independent FILTER while preserving post-window evaluation, and add regression coverage for both fulltext index forms. The current head and required CI were verified at d6fb993.
…ve WINDOW (matrixorigin#28974) The WINDOW fulltext anchor rewrote served fulltext_match in the window's own spec/FilterList/PARTITION, but not in a distinct Node_FILTER above the window. An outer predicate that references neither a window column nor a partition key (e.g. `... where score > 0` inlined by predicate pushdown to `fulltext_match(...) > 0`) stays in that independent FILTER and was never rewritten, so the raw fulltext_match reached execution as error 20105 even though the index scan existed. Extract rewriteServedMatchesInFilterList (binding-tag-aware; leaves an unserved MATCH intact so it still raises 20105) and add a Node_FILTER case in applyIndices that applies it. Post-order recursion guarantees the anchor below has published its score (ftJoinServed) first; the filter keeps its position, so evaluation stays post-window. The WINDOW.FilterList loop now shares the same helper. Adds TestFullTextOuterFilterAboveWindowMatchRewritten (proven to fail without the fix) and BVT coverage for both fulltext index forms. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
aptend
left a comment
There was a problem hiding this comment.
Re-reviewed the full diff and the changes since my prior review at c1e8f7a. The two previously blocking paths are now closed: WINDOW.FilterList MATCH expressions are rewritten by the window anchor, and an independent FILTER above WINDOW is rewritten after child recursion. I also verified the PARTITION/stacked-window/projected-score paths and the preserved side of LEFT/RIGHT/SINGLE joins against the implementation and regression coverage. Focused planner tests for all 11 added cases pass at exact head c9a2b1c; git diff --check also passes. The failing coverage job is from unrelated TestIssue26404MixedDataBranchLifecycleDoesNotDeadlock/pick, while the regular Linux UT and relevant BVT jobs passed. No blocking issue found.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review (exact head 8e98b85).\n\nAPPROVE.\n\nReviewed the complete planner, unit-test, and FULLTEXT/FULLTEXT2 BVT diff against base 510e28e. The WINDOW/PARTITION anchor preserves the plan shape while reparenting the scan below the index join, publishes served scores to projections, ancestor/stacked windows, WINDOW.FilterList and independent outer FILTERs, and leaves unsupported MATCH expressions unresolved. The preserved-side LEFT/RIGHT/SINGLE rewrites remain row-preserving and retain null-extended unmatched rows.\n\nThe prior PARTITION, served-score propagation, WINDOW.FilterList and outer-FILTER blockers are closed at this head. Exact-head focused planner tests, FULLTEXT/FULLTEXT2 window/view/join BVTs, CI and diff checks are green. No concrete blocker remains.
Merge Queue Status
This pull request spent 59 seconds in the queue, with no time running CI. Waiting for any of
All conditions
ReasonPull request #29069 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.
HintYou 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. Tick the box to put this pull request back in the merge queue (same as
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #28974 #20687
What this PR does / why we need it:
Both issues are the same class of defect: a
MATCH() AGAINST()on an indexed column reaches execution as ERROR 20105 becauseapplyIndicesdid not anchor the fulltext rewrite for that plan shape. The invariant is "nofulltext_matchmay surviveapplyIndices"; this PR extends the anchors to two more shapes.#28974 — MATCH beneath a WINDOW operator
A top-level
WHERE MATCH() AGAINST()is served by a FULLTEXT/FULLTEXT2 index, but adding a window function (e.g.ROW_NUMBER() OVER (...)) puts aWINDOWnode between the query block and the base scan.applyIndicesanchored the fulltext rewrite at PROJECT/SORT/AGG only, so the scan'sfulltext_matchsurvived beneath the WINDOW and threw 20105.Node_WINDOWfulltext anchor (mirroring theNode_AGGanchor from [Bug]: fulltext MATCH score remains unrewritten inside aggregate expressions #28681): it builds the index-scan join for the scan's MATCH filters and reparents the window's child onto it. Post-order recursion runs it before the PROJECT pass, which then finds no MATCH and no-ops.OVER (PARTITION BY ...)inserts aNode_PARTITIONbetween the WINDOW and the scan.resolveScanNodeUnderWindowdescends that partition to reach the scan, and the rewrite reparents the scan's immediate parent onto the index join so the partition is not dropped.ftJoinServed, so a MATCH projected in the SELECT list, in an ancestor ORDER BY, or in a stacked outer window is rewritten to the score column instead of surviving as 20105.exprCallsFunc/replaceScoreFnInExprBynow traverseExpr_W(window function, OVER partition/order-by), so a MATCH inside the window spec (OVER (ORDER BY match(...))) is rewritten too. Aggregate/projection exprs never contain anExpr_W, so existing callers are unaffected.WHERE MATCHalongside a window function is now servable, sofulltext_view_ddl/fulltext2_view_ddlaccept those views (a MATCH that appears only in an OVER spec with no WHERE seed stays refused, as before).#20687 — MATCH on the preserved side of an outer JOIN
A LEFT JOIN B WHERE match(A.x)(and the RIGHT / scalar-subquery SINGLE equivalents) also failed with 20105:applyFullTextFiltersForJoinChildrenonly served the null-extending child of an outer join, never the row-preserved child.A
fulltext_matchon a scan'sFilterListis a pure filter on that input's own columns, so re-expressing it as the 1-row-per-pk INNER-join semi-join is row-equivalent to the WHERE that placed it there — on the preserved side too.A LEFT JOIN B WHERE match(A.x)becomes(A INNER JOIN A_ft) LEFT JOIN B, so a matcher with no join partner is kept null-extended, not dropped. Both children of LEFT/RIGHT/SINGLE are now eligible; ANTI/MARK/DEDUP and ASOF stay conservative (filtering those inputs is not a pure filter), and FULL OUTER does not exist in MO.(This is not the index-less full-table-scan case originally described in #20687 — that is infeasible for CJK, which has no whitespace tokenizer without an index; this fix serves MATCH via the existing index on the preserved side of the join.)
How is this PR tested:
pkg/sql/plan):TestFullTextWindowMatchRewritten,TestFullTextWindowPartitionMatchRewritten,...ProjectedMatchPropagated,...StackedSpecMatchPropagated,TestFullTextWindowPartitionByMatchServed,TestResolveScanNodeUnderWindow,TestExprCallsFuncTraversesWindowSpec,TestReplaceScoreFnInExprByTraversesWindowSpec, andTestFullTextJoinRewriteServesOuterJoinPreservedChild(LEFT/RIGHT/SINGLE preserved child).fulltext_window_match/fulltext2_window_match(window + PARTITION BY + projected/ancestor/stacked MATCH),fulltext_view_ddl/fulltext2_view_ddl(view acceptance), andfulltext_join/fulltext2_join(INNER/LEFT/RIGHT/SINGLE + a null-extension counterexample where a partner-less matcher is kept as(id, NULL), with EXPLAIN pinning the index scan nested under the outer join).🤖 Generated with Claude Code