924060929 opened a new pull request, #70995:
URL: https://github.com/apache/doris/pull/70995
### Background
Sampled OLAP statistics collection currently relies on whole-tablet
`TABLESAMPLE` or row `LIMIT`, which either reads entire large tablets or
introduces prefix bias on sorted key and partition columns. At the storage
layer, BE already knows segment row counts and physical segment IDs at the
scan's captured visible version and supports segment-level `RowRanges`
filtering.
### What problem does this PR solve?
Issue Number: close #70988
Related PR: #70994 (depends on)
PR Type: Feature
Problem Summary:
Add versioned internal `TABLESAMPLE (FIXED_BLOCK unit_rows = ..., GROUP
(...)) REPEATABLE <seed>` support from FE SQL parsing and planning down to BE
version-pinned rowid-block sampling (`FixedRowIdBlockSampler`), gated by BE
heartbeat capability `supports_fixed_block_sampling_v1`. `OlapAnalysisTask`
continues to use its existing sampling path in this PR.
### Details
- **Change map:** ~780 lines production code across `gensrc/thrift/`,
`be/src/storage/sampling/`, `be/src/exec/`, `be/src/storage/rowset/`,
`be/src/agent/`, `fe/fe-sql-parser/`, and `fe/fe-core/`; ~710 lines FE/BE unit
and regression tests.
- **Scope:** Internal OLAP query scans (including explicitly selected
non-changelog rollup indexes), gated to internal sessions
(`ConnectContext.getState().isInternal()`) or debug point
`TableSample.allowInternalFixedBlock`.
- **Design:**
- Allocate blocks across segments via 128-bit fixed-point systematic
`DependentRounding` and rank blocks within each segment using physical
`segment.id()` so Cloud non-contiguous segment IDs are handled identically
across serial and parallel scans.
- Skip iterator construction on empty sampled middle segments in
`BetaRowsetReader` and skip scanner creation on zero-hit tablets in
`OlapScanLocalState` so empty `rs_splits` never recapture full tablets.
- Slice sparse sampled `RowRanges` across parallel scanners via
`SampleRangeSplitter`, disable storage-layer aggregate/TopN/ANN pushdown,
point-query short-circuiting, and query-cache normalization on `FIXED_BLOCK`
scans, validate target index and normal/temporary partition ownership at bind
and scan-range build time, and route mixed-version replicas only to v1-capable
backends during rolling upgrades.
- **Usage:** Internal SQL syntax `TABLESAMPLE (FIXED_BLOCK unit_rows = <U>,
GROUP (tablet_rate = ..., unit_rate = ..., max_units = ..., TABLETS (...)))
REPEATABLE <seed>`.
- **Default behavior:** Public `ROWS` / `PERCENT` sampling and existing
`ANALYZE` execution remain unchanged.
- **Compatibility:** All added Thrift fields
(`TBackendInfo.supports_fixed_block_sampling_v1 = 12`,
`TPaloScanRange.sample_options = 15`, and `TTabletSampleOptions`) are
`optional` and collision-free across release branches 3.1 through 4.2.
### Testing
- Ran `./run-fe-ut.sh --run
'FixedBlockTableSamplePlanTest,StatsCalculatorTest'` (30 tests passed, 0
failures) and `mvn checkstyle:check -pl fe-sql-parser,fe-core` (0 violations).
- Ran native and UBSan builds of `FixedRowIdBlockSamplerTest` (8/8 tests
passed), compiled all modified BE production and test translation units, and
verified `build-support/check-build-hygiene.sh`,
`build-support/check-format.sh` (clang-format 16), and `clang-tidy` (0
warnings).
- Ran `regression-test/suites/statistics/test_fixed_block_sample.groovy` on
a local FE+BE cluster (passed).
### Notes for Reviewers
- Stacked on #70994; review top commit `4e179b75ff5` for the standalone diff
until #70994 merges.
### Release note
None
### Check List (For Author)
- Behavior changed: No
- Does this need documentation: No (internal syntax)
- Pre-submission status: Ready
### AI Disclosure
- Tool: Antigravity & Codex
- Generated: FE/BE/Thrift implementation, unit/regression tests, and commit
description
- Human review: Reviewed Thrift field compatibility, 128-bit dependent
rounding math, Cloud physical segment ID vs position invariants,
empty-segment/zero-hit scanner traps, rolling-upgrade replica routing, and
Nereids pushdown guards
--
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]