You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8fc7d7c
Browse filesBrowse the repository at this point in the historyBrowse files
[fix](nereids) Reject score() in correlated subqueries and in HAVING through aliases
### What problem does this PR solve?
Issue Number: None
Related PR: apache#69292
Problem Summary:
Review of 2e999db found three gaps in the checks of BindScoreToOlapScan:
- A correlated subquery could call score() with ORDER BY score() LIMIT, e.g.
EXISTS (SELECT 1 FROM t a WHERE a.c1 = b.c1 AND a.c1 MATCH 'apple'
AND score() > 0.6 ORDER BY score() DESC LIMIT 1). Decorrelation removes
that LIMIT and ORDER BY (EliminateLimitUnderApply, EliminateSortUnderApply),
so a predicate inferred from the outer query, such as an outer MATCH on
b.c1, reaches the scored scan and adds to its score. score() is now
rejected anywhere in a correlated subquery, also in a derived table in it,
whose LIMIT can end up directly under the subquery once the derived table
is merged.
- HAVING and QUALIFY could read MATCH through an alias of the select list,
e.g. c1 MATCH 'red' AS m ... QUALIFY m AND rn = 1 with PARTITION BY c1.
Pushing that filter through the window moves the MATCH into the scan,
where it adds to the score. Aliases of score(), MATCH and SEARCH in the
select list or GROUP BY, and aliases of those aliases, are now treated
like the expressions themselves.
- A nested SELECT with HAVING on a column it does not return, e.g.
... WHERE c1 MATCH 'apple' HAVING c2 = 'sweet' ORDER BY s DESC LIMIT 2,
was rejected: analysis restores the select list with a projection between
LIMIT and ORDER BY, and the check required them to be adjacent. The check
now skips projections of plain columns between them.
### Release note
None
### Check List (For Author)
- Test: Unit Test and Regression test
- BindScoreToOlapScanTest: the reviewer's correlated EXISTS, QUALIFY alias
and nested HAVING queries, plus a scored derived table in a correlated
EXISTS, a correlated scalar subquery, HAVING and GROUP BY ... HAVING on a
MATCH alias, and an uncorrelated EXISTS with the TopN. With the previous
binder the five new tests fail; with this change all 73 pass.
Checkstyle passes.
- Regression tests: test_score_filter_usage gets the correlated EXISTS,
the QUALIFY alias and the nested HAVING query, with its .out regenerated
by the framework. The 19 suites that use score() pass on a private
cluster.
- Behavior changed: Yes. score() in a correlated subquery, and HAVING or
QUALIFY that read score(), MATCH or SEARCH through an alias, are rejected.
A nested scored SELECT with HAVING on a column it does not return is
accepted.
- Does this need documentation: No
Co-Authored-By: Claude Opus 5.5 <[email protected]>
0 commit comments