924060929 opened a new pull request, #70997:
URL: https://github.com/apache/doris/pull/70997
### Background
Fixed row-ID block sampling works on duplicate-key and merge-on-write
unique-key indexes where each surviving row lives at one physical row position.
On `UNIQUE_KEYS` Merge-on-Read (MOR) and `AGG_KEYS` indexes, multiple
uncompacted rowsets can hold versions, tombstones, or partial aggregates of the
same key, while FE-reported index row counts reflect pre-merge physical rows
rather than merged logical rows, and legacy sampled `ANALYZE` skipped MOR and
aggregate value columns entirely.
### What problem does this PR solve?
Issue Number: close #70990
Related PR: #70996 (depends on)
PR Type: Feature
Problem Summary:
Add `KEY_RANGE_BLOCK` sampling across BE storage/execution, Thrift
protocols, Nereids internal `TABLESAMPLE`, and FE OLAP statistics collection so
eligible hash-routed `UNIQUE_KEYS` (MOR) and `AGG_KEYS` indexes sample mutually
exclusive key intervals across all captured segments, run full storage-layer
merge across both key and value columns, and scale column statistics from
merged logical row estimates.
### Details
- **Change map:** 2 Thrift files, 17 BE storage/scan production files
(`KeyRangeBlockSampler`, `SegmentKeySeeker`, `ShortKeyIndexDecoder`,
`OlapScanLocalState`, `OlapScanner`, `BlockReader`, `HeartbeatServer`), 15 FE
production files (`FixedBlockSampleSpec`, `LogicalPlanBuilder`, `BindRelation`,
`PhysicalPlanTranslator`, `OlapScanNode`, `AnalysisJob`, `OlapAnalysisTask`,
`StatisticsUtil`, `TableStatisticsSqlBuilder`,
`HierarchicalFixedBudgetTabletSamplingMethod`, `IndexSamplingSnapshot`,
`SampledScanSqlRenderer`, `Backend*`, `HeartbeatMgr`), and 12 BE/FE/regression
test files.
- **Scope:** Internal `KEY_RANGE_BLOCK` OLAP scans and sampled `ANALYZE` on
hash-routed lexical `UNIQUE_KEYS` (MOR) and `AGG_KEYS` indexes whose
distribution and visibility columns are preserved on the selected index.
- **Design:**
- `KeyRangeBlockSampler` k-way merges short-key block heads across all
non-empty segments in the captured `TabletReadSource`, subdivides coarse
short-key blocks or within-segment prefix runs using full typed sort-key tuples
within a bounded probe/byte budget while keeping multi-rowset scans zero-I/O
when short-key blocks already provide sufficient resolution, applies dependent
rounding with the hard `max_sample_units_per_tablet` fuse, and resolves
per-segment `[lower_rowid, upper_rowid)` via `SegmentKeySeeker`.
- FE `BindRelation`, `PhysicalPlanTranslator`, and BE `OlapScanLocalState`
/ `OlapScanner` / `BlockReader` reject `PREAGGOPEN` and raw/debug bypass modes,
force `PreAggStatus.OFF` and `direct_mode = false`, preserve MOR delete-sign,
sequence, delete-predicate, and row-TTL semantics, and execute one merged
reader per sampled tablet.
- `StatisticsUtil.canCollectColumn` admits MOR and `AGG_KEYS` value
columns into sampled `ANALYZE` when `enable_fixed_block_stats_sampling` is
enabled on a key-range-capable index, while `OlapAnalysisTask` skips unmerged
value columns if a job falls back to `Legacy`.
- `TableStatisticsSqlBuilder` emits raw merged sample moments `(n, z, d,
singletons, bytes)` for `KEY_RANGE_BLOCK` tasks; `OlapAnalysisTask` freezes a
single Horvitz-Thompson logical population estimate `ROUND(n / q)` per `(job,
indexId)` and recomputes `row_count`, `ndv`, `null_count`, and `data_size` for
every column against that frozen count.
- **Usage:** Controlled automatically by `SET GLOBAL
enable_fixed_block_stats_sampling = true;` for eligible `ANALYZE` jobs.
- **Default behavior:** Remains gated behind
`enable_fixed_block_stats_sampling` (default `false`); `RANDOM`-distributed
`AGG_KEYS`, Z-order/cluster-key indexes, mixed-capability clusters, and
zero-row samples safely fall back to `Legacy` or preserve existing statistics.
- **Compatibility:** Allocates `TTabletSamplingAlgorithm::KEY_RANGE_BLOCK =
1`, `7: optional TKeyRangeBlockSampleParams key_range_block_params` on
`TTabletSampleOptions`, and `13: optional bool
supports_key_range_block_sampling_v1` on `TBackendInfo`, verified unused across
`branch-3.1` through `master`.
### Testing
- Ran `./run-fe-ut.sh` across planner/heartbeat/statistics test suites
including `KeyRangeBlockSamplingTest` and `StatisticsUtilTest` (all passed, 0
failures).
- Ran BE unit tests for `KeyRangeBlockSamplerTest`, `SegmentKeySeekerTest`,
`FixedRowIdBlockSamplerTest`, and
`VerticalSegmentWriterWritePathsTest.KeyRangeSeeksStoredKeys` (all passed).
- Ran all 4 regression suites (`test_sample_minmax_batch`,
`test_fixed_block_sample`, `test_key_range_block_sample`,
`test_fixed_block_analyze`) end-to-end against a live local FE+BE cluster (all
passed, 0 failures) and benchmarked multi-million-row `DUP_KEYS`, `UNIQUE_KEYS`
(MOW/MOR), and `AGG_KEYS` tables.
- Verified `build-support/check-build-hygiene.sh`,
`build-support/check-format.sh` (clang-format 16), and FE Checkstyle (0
violations).
### Notes for Reviewers
- Stacked on #70996; review top commit `f0933c8db8c` for the standalone diff
until #70996 merges.
### Release note
Support key-range block sampling, value-column sampled statistics, and
merged logical row scaling on `UNIQUE_KEYS` (Merge-on-Read) and `AGG_KEYS`
tables.
### Check List (For Author)
- Behavior changed: No
- Does this need documentation: No
- Pre-submission status: Ready
### AI Disclosure
- Tool: GPT-6.2-Astra and Antigravity
- Generated: Implementation and unit/regression tests
- Human review: Reviewed `OlapTable` read-lock discipline, sibling-column
DDL fault isolation, `StatisticsUtil.canCollectColumn` value-column admission
and fallback guards, `SegmentKeySeeker` lifetimes, short-key vs intra-block
boundary subdivision, and post-merge logical population freezing
--
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]