eldenmoon opened a new pull request, #69461:
URL: https://github.com/apache/doris/pull/69461
### What problem does this PR solve?
Fixes **DORIS-28583**.
`PushDownScoreTopNIntoOlapScan` recursively stripped `CAST` from score
predicates and pushed the literal threshold to the storage-level score filter.
For
```sql
SELECT id, score() AS s FROM t
WHERE title MATCH_ANY 'apple'
AND CAST(score() AS DECIMALV3(2,1)) >= 0.5
ORDER BY s DESC LIMIT 100
```
the raw score `>= 0.5` threshold is not equivalent to the rounded
`DECIMALV3(2,1) >= 0.5` threshold. Rows with scores `0.484` and `0.468` round
to `0.5` and satisfy the original predicate, but were dropped by the raw
threshold — the query returned an empty result. `TRY_CAST` had the same problem.
### What changes were proposed?
- Only unwrap a value-preserving `float -> double` widening cast in
`isScoreExpression`. Other casts keep their rounding semantics.
- For rounding casts (`DECIMALV3(p,s)` and integer targets), translate the
rounded threshold back into an equivalent raw score range before pushing it
down:
- `round_s(score) >= t` => `score >= t - 0.5 * 10^-s`
- `round_s(score) > t` => `score >= t + 0.5 * 10^-s`
- The storage-level score range filter and the score TopN pushdown stay
enabled, so no row-level predicate on the score virtual column is needed.
- New regression suite `test_search_score_range_cast` compares
`CAST`/`TRY_CAST` queries with a materialize-then-filter oracle, checks a
filtering threshold (`>= 0.6`), and verifies the plain `score() >= 0.45` path
is unchanged.
### Verification
Built FE from this branch and ran the suite on a single-FE/single-BE cluster
at master `5e3ed84abb0`:
```
oracle (materialize score, then filter CAST(s) >= 0.5) -> 2,3
CAST(score() AS DECIMALV3(2,1)) >= 0.5 -> 2,3
TRY_CAST(score() AS DECIMALV3(2,1)) >= 0.5 -> 2,3
CAST(score() AS DECIMALV3(2,1)) >= 0.6 -> empty
score() >= 0.45 -> 2,3
```
Before the fix the two cast queries returned empty while the oracle returned
`2,3`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]