re20052 opened a new pull request, #66187:
URL: https://github.com/apache/doris/pull/66187
### What problem does this PR solve?
Problem Summary:
Support a new `max_visible_partition()` syntax after the table name so a
query can be automatically pruned to the latest partition that has visible
data, without hardcoding the partition name.
The common workaround `where pt = (select max(pt) from t)` requires an extra
sub-query, adding overhead in the Plan / Schedule / Execute phases. This syntax
lets the engine resolve the target partition during Nereids binding and reuse
the existing partition-pruning path, so the change is confined to FE and does
not touch the execution layer.
- RANGE table: prune to the partition with the greatest range upper bound
that has visible data (physical comparison on the upper endpoint via
`PartitionKey.compareTo`, type-aware for numbers/dates, not by partition name).
- UNPARTITIONED table: return the single partition if it has data, otherwise
empty.
- LIST table: no natural "latest" partition, return empty result.
- Only OLAP table and materialized view are supported; other table types
(View / external tables) are rejected explicitly at bind time.
- When no visible partition is found, an empty query
(`LogicalEmptyRelation`) is built instead of throwing or falling back to a full
scan.
### Release note
Support `max_visible_partition()` syntax to query the latest visible
partition.
### Check List (For Author)
- Test
- [x] Regression test
- [ ] Unit Test
- [x] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason
Regression suite:
`regression-test/suites/nereids_syntax_p0/max_visible_partition.groovy`,
covering RANGE pruning, materialized view, View rejection, and UNPARTITIONED /
LIST empty-result cases.
Manual test on cluster `doris_ad_ttam_my3` (table
`ad_stats_test.new_uid_sketch_creative_hourly`): sub-query form 594ms / 4
fragments vs `max_visible_partition()` 27ms / 2 fragments.
- Behavior changed:
- [ ] No.
- [x] Yes. Adds a new optional `max_visible_partition()` clause after
the table name. `MAX_VISIBLE_PARTITION` is a non-reserved keyword, so existing
SQL is unaffected.
- Does this need documentation?
- [ ] No.
- [x] Yes. Design doc:
https://bytedance.sg.larkoffice.com/docx/Lkhsdma7eoX2LRxWSutl4ExvgOd
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label
--
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]