[Feature] Support BUCKET(id, ...) query hint to scan specific buckets of an olap table
- Dominant language
- Java
- Stars
- 15.9k
- Forks
- 3.9k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 520
Description
### Search before asking
- [x] I had searched in the [issues](https://github.com/apache/doris/issues) and found no similar issues.
### Description
Doris already supports a `TABLET(id, ...)` hint to restrict a scan to specific tablets, e.g. `SELECT * FROM tbl TABLET(10086)`. This is useful for debugging and targeted scans, but it requires the user to first look up raw tablet ids (via `SHOW TABLETS`), and those ids change across schema changes and differ per partition.
It would be convenient to target buckets by their **ordinal** instead. Bucket `k` is stable and meaningful (it is the bucket that the distribution-key hash maps to), so `BUCKET(0, 2)` lets a user scan the buckets holding specific keys without any tablet-id lookup.
**Proposal:** add a `BUCKET(, ...)` table hint that mirrors `TABLET(...)` at bucket-ordinal granularity:
```sql
SELECT * FROM tbl [PARTITION(...)] BUCKET(0, 2) alias;
```
A bucket id `k` resolves to the k-th tablet of each selected partition (`partition.getBaseIndex().getTablets().get(k)`) and reuses the existing manually-specified-tablet scan path. `BUCKET` and `TABLET` are mutually exclusive.
### Use case
Debugging and targeted scans of specific buckets without having to look up raw tablet ids first.
### Related issues
_No response_
### Are you willing to submit PR?
- [x] Yes I am willing to submit a PR!
### Code of Conduct
- [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
Contributor guide
Research direction
Start by tracing the existing TABLET(...) table-hint handling and its manually-specified-tablet scan path. Review how partition.getBaseIndex().getTablets().get(k) would resolve bucket ordinals, then add coverage for BUCKET syntax, selected partitions, invalid ordinals, and mutual exclusion with TABLET.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, sql
- Domain
- database
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100