924060929 opened a new issue, #70990: URL: https://github.com/apache/doris/issues/70990
### Background Physical row-ID block sampling (`FIXED_BLOCK`) assumes each surviving logical row lives at a single physical row position (`DUP_KEYS` and `UNIQUE_KEYS` Merge-on-Write). On `UNIQUE_KEYS` Merge-on-Read (MOR) and `AGG_KEYS` indexes, multiple uncompacted rowsets hold versions, delete signs, or partial aggregate states of the same key, so sampling arbitrary row-ID ranges fails to merge matching keys across segments. ### Current behavior Legacy sampled `ANALYZE TABLE` skips `AGG_KEYS` and MOR value columns completely (`StatisticsUtil.canCollectColumn`), and uses pre-merge physical tablet row counts rather than post-merge logical row counts: ```sql ANALYZE TABLE agg_tbl WITH SAMPLE ROWS 400000 WITH SYNC; SHOW COLUMN STATS agg_tbl; -- Non-key AGG_KEYS / MOR value columns have no statistics collected. ``` ### Expected behavior Eligible `UNIQUE_KEYS` (MOR) and `AGG_KEYS` indexes sample mutually exclusive sort-key intervals (`KEY_RANGE_BLOCK`) across all captured segments of a tablet, execute storage-layer key merging across all overlapping segments inside those key intervals, collect sampled statistics for both key and value columns, and scale `row_count`, `ndv`, `null_count`, and `data_size` from the post-merge logical population estimate `ROUND(n / q)`. ### Proposed design 1. Add `TTabletSamplingAlgorithm::KEY_RANGE_BLOCK = 1`, `TKeyRangeBlockSampleParams`, and BE heartbeat capability `supports_key_range_block_sampling_v1`. 2. Implement `KeyRangeBlockSampler` and `SegmentKeySeeker` on BE: k-way merge short-key block heads across captured segments, subdivide coarse blocks or prefix runs within bounded probe budgets, select intervals via dependent rounding with `max_sample_units_per_tablet`, and resolve `[lower_rowid, upper_rowid)` per segment while forcing merged `BlockReader` execution (`PreAggStatus.OFF`, `direct_mode = false`). 3. Admit MOR and `AGG_KEYS` value columns in `StatisticsUtil.canCollectColumn` when `enable_fixed_block_stats_sampling` is active on a key-range-capable index, emit raw merged sample moments `(n, z, d, singletons, bytes)`, and freeze a single Horvitz-Thompson logical row count `ROUND(n / q)` per `(job, indexId)`. - Rejected alternative: sampling physical rows without cross-segment key-range alignment, which corrupts `SUM`/`MIN`/`MAX`/MOR delete-sign semantics and overcounts logical rows before compaction. ### Impact OLAP statistics collection and internal `TABLESAMPLE` execution on `UNIQUE_KEYS` (MOR) and `AGG_KEYS` tables across shared-nothing and Cloud modes (`gensrc/thrift`, `be/src/storage/sampling`, `be/src/storage/segment`, `fe-core`). ### Reproduction or evidence Verified via `KeyRangeBlockSamplerTest`, `SegmentKeySeekerTest`, `VerticalSegmentWriterWritePathsTest.KeyRangeSeeksStoredKeys`, `KeyRangeBlockSamplingTest`, and live-cluster `test_key_range_block_sample.groovy` + `test_fixed_block_analyze.groovy`. ### Scope and non-goals Covers hash-routed `UNIQUE_KEYS` (MOR) and `AGG_KEYS` `KEY_RANGE_BLOCK` sampling and post-merge value-column statistics. High-overlap galloping seeks and `RANDOM`-distributed `AGG_KEYS` shared key-range coordination are handled in follow-up optimizations. ### Acceptance criteria - Sampled `ANALYZE` collects accurate key and value column statistics on uncompacted MOR (with delete signs and sequence columns) and `AGG_KEYS` tables. - Frozen post-merge logical `row_count` tracks true merged key cardinality rather than uncompacted physical row count. ### Risks and compatibility All Thrift fields (`TTabletSamplingAlgorithm::KEY_RANGE_BLOCK = 1`, `TTabletSampleOptions.key_range_block_params = 7`, `TBackendInfo.supports_key_range_block_sampling_v1 = 13`) are `optional` and collision-free across `branch-3.1` through `master`. Mixed-version clusters fall back safely. ### Related Builds on `FIXED_BLOCK` scan ranges and the budgeted OLAP statistics sampling framework. -- 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]
