924060929 opened a new pull request, #70998:
URL: https://github.com/apache/doris/pull/70998
### Background
Sampled `ANALYZE TABLE` in Apache Doris builds a `TabletSampleSpec` in
`OlapAnalysisTask`, collects column `MIN`/`MAX` bounds via
`ColumnMinMaxBatchCollector`, and executes a single CTE statistics query per
column (`FIXED_BLOCK` physical row-id blocks for `DUP_KEYS` and `UNIQUE_KEYS`
MOW, and `KEY_RANGE_BLOCK` merged storage key prefixes for hash-routed
`UNIQUE_KEYS` MOR and `AGG_KEYS`). `HistogramTask` separately populates
`histogram_statistics` for `ANALYZE TABLE ... WITH HISTOGRAM`.
### What problem does this PR solve?
Issue Number: None
Related PR: #70997 (depends on)
PR Type: Enhancement
Problem Summary:
Five gaps remained in sampled statistics collection: composite-key tables
distributed by a single hash bucket column fell back to legacy tablet sampling
(which skipped all MOR/AGG value columns), `UNIQUE_KEYS` (MOW) sampled tasks
published pre-compaction physical `RowCount` instead of post-delete live rows,
`AGG_KEYS` and MOR value columns triggered a full-table merge scan in
`ColumnMinMaxBatchCollector`, `RANDOM`-distributed `AGG_KEYS` tables and
`HistogramTask` could not use block sampling, and
`enable_fixed_block_stats_sampling` defaulted to `false`. This PR closes all
five gaps in FE without changing Thrift or BE protocols and enables
`enable_fixed_block_stats_sampling` by default. Existing users automatically
get bounded-I/O equal-probability sampling across `DUP_KEYS`, MOW, MOR,
hash/random `AGG_KEYS`, and sampled histograms while keeping `SET GLOBAL
enable_fixed_block_stats_sampling = false` as a one-command fallback.
### Details
- **Change map:** ~520 lines of FE production code across 13 classes and
~315 lines of FE unit and regression tests across 8 files (0 generated or doc
files):
- Subdomain-aware DUJ1 scaling for subsampled partition/hash-bucket
columns (`HierarchicalFixedBudgetTabletSamplingMethod`, `TabletSampleSpec`,
`OlapAnalysisTask`, `TableStatisticsSqlBuilder`, ~115 lines).
- Post-delete/TTL live row count estimation for MOW and row-TTL
`DUP_KEYS`, plus in-sample typed `MIN`/`MAX` for merged value columns without
full-table bounds scans (`ColumnMinMaxBatchCollector`, `OlapAnalysisTask`,
`TableStatisticsSqlBuilder`, ~110 lines).
- `RANDOM`-distributed `AGG_KEYS` whole-partition block pruning +
deterministic `xxhash_64` key-tuple filter (`FixedBlockSampleSpec`,
`RandomAggTabletSamplingMethod`, `SampledScanSqlRenderer`, `StatisticsUtil`,
`AnalysisJob`, ~155 lines).
- Sampled histogram execution and task-type preservation (`HistogramTask`,
`AnalysisManager`, `SessionVariable`, ~140 lines).
- **Before and after:**
- Composite-key tables with a single `HASH(col)` bucket column stay on
`FIXED_BLOCK` / `KEY_RANGE_BLOCK` instead of falling back to legacy sampling,
scaling DUJ1 across unvisited partition/bucket subdomains via `(partitionRate,
bucketRate)`.
- `UNIQUE_KEYS` (MOW) and row-TTL tables estimate live `row_count =
ROUND(n / q)` from post-Delete-Bitmap visible sampled rows instead of stale
pre-compaction physical tablet counts.
- Non-key columns on `AGG_KEYS` and MOR skip
`ColumnMinMaxBatchCollector`'s full-table merge scan and compute typed
`MIN`/`MAX` inside the merged sample scan (`ScanRows` on a 20M-row `AGG_KEYS`
table drops from 24.1M to 4.04M).
- `RANDOM`-distributed `AGG_KEYS` tables combine whole-partition
`FIXED_BLOCK (unit_rate = 1.0)` pruning with a collision-safe `xxhash_64`
key-tuple predicate pushed below Nereids pre-aggregation so every sampled key
retains all partial rows across random tablets.
- `ANALYZE TABLE ... WITH HISTOGRAM WITH SAMPLE ...` preserves
`AnalysisType.HISTOGRAM` in `AnalysisManager` and applies `FIXED_BLOCK`,
`KEY_RANGE_BLOCK`, or `RandomAggTabletSamplingMethod` in `HistogramTask`
(5.4x-5.6x faster than full histogram scans on 16M-20M row `AGG_KEYS` tables).
- **Configs and defaults:** `enable_fixed_block_stats_sampling` in
`SessionVariable` changes from `false` to `true`.
- **Impact on existing users:** Sampled manual and automatic `ANALYZE` now
collects MOR and `AGG_KEYS` (hash and pre-aggregatable `RANDOM`) value columns,
estimates post-delete MOW live row counts, avoids full-table `MIN`/`MAX` scans
on MOR/AGG value columns, and samples histograms out of the box. Setting `SET
GLOBAL enable_fixed_block_stats_sampling = false` restores legacy tablet
sampling.
- **Behavior change:** Yes (see Before and after and Configs and defaults
above).
### Testing
- Ran FE Checkstyle (`mvn checkstyle:check -pl fe-core`) and 10 FE unit test
classes (125 tests: `KeyRangeBlockSamplingTest`, `OlapSamplingIntegrationTest`,
`OlapAnalysisTaskTest`, `ColumnMinMaxBatchCollectorTest`,
`TableStatisticsSqlBuilderTest`, `HistogramTaskTest`,
`HierarchicalFixedBudgetTabletSamplingMethodTest`,
`SampledScanSqlRendererTest`, `StatisticsUtilTest`,
`FixedBlockTableSamplePlanTest`) locally via `./run-fe-ut.sh` — all passed.
- Started an isolated local FE+BE cluster and ran `./run-regression-test.sh`
on `test_sample_minmax_batch`, `test_fixed_block_sample`,
`test_key_range_block_sample`, and `test_fixed_block_analyze` — all 4 suites
passed.
- Benchmarked 16M-24M row MOW (with 20% deletes), MOR (with overwritten
stale bounds), composite-key single-bucket `AGG_KEYS`, `RANDOM`-distributed
`AGG_KEYS`, and sampled `WITH HISTOGRAM` on the local cluster to verify
`ScanRows`, latency, and post-merge accuracy.
### Notes for Reviewers
- Stacked on #70997; review top commit `63efe099247` for the standalone diff
until #70997 merges.
### Release note
Enable `enable_fixed_block_stats_sampling` by default and extend
block-sampled `ANALYZE` to cover composite-key single-bucket tables,
post-delete MOW live row counts, zero-full-scan bounds on MOR/`AGG_KEYS` value
columns, `RANDOM`-distributed `AGG_KEYS` tables, and sampled histograms.
### Check List (For Author)
- Behavior changed: Yes (see Details)
- Does this need documentation: No
- Pre-submission status: Ready
### AI Disclosure
- Tool: Antigravity
- Generated: code, tests, this description
- Human review: Reviewed architecture, estimator formulas, unit tests, and
live-cluster regression and benchmark results.
--
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]