924060929 opened a new issue, #70989: URL: https://github.com/apache/doris/issues/70989
### Background OLAP sampled `ANALYZE TABLE` previously coupled tablet selection, row limiting, and SQL generation inside `OlapAnalysisTask`, causing large-tablet full scans on key columns, prefix bias on value columns, inconsistent per-column `row_count` values on the same index, and zeroed statistics when tablet row-count reports lagged behind newly committed partitions. ### Current behavior Running `ANALYZE TABLE tbl WITH SAMPLE ROWS 400000` selects whole tablets and executes 3 CTE scans per column query, can publish different `row_count` values across columns of the same index, and can overwrite existing statistics with zeros when a written partition (`visibleVersion > 1`) has not yet reported tablet row counts. ### Expected behavior Provide a pluggable OLAP sampling framework (`LegacyTabletSamplingMethod` and `HierarchicalFixedBudgetTabletSamplingMethod`), execute single-scan sampled statistics SQL over `FIXED_BLOCK` scan ranges, freeze one authoritative population row count `N` per `(AnalysisJob, indexId)`, and defer/protect existing statistics when row reports are pending or when a sample draw observes zero visible rows. ### Proposed design 1. Introduce `TabletSamplingMethod` with `LegacyTabletSamplingMethod` and `HierarchicalFixedBudgetTabletSamplingMethod` (3-stage equal-probability `pi_h * p_h = q` block sampling with logarithmic tablet-size stratification, water-filling seat allocation, SQL byte budgeting, and exact binary64 `BigInteger` systematic rounding). 2. Refactor `TableStatisticsSqlBuilder` (`stats LEFT JOIN hot_top ON TRUE`) with materialized CTE settings so sampled and full OLAP column statistics execute a single physical `OlapScanNode`. 3. Freeze one authoritative population row count `N` per `(job, indexId)` in `AnalysisJob`, clamp `0 <= null_count <= N` and `0 <= ndv <= N - null_count`, and skip publishing when `FIXED_BLOCK` observes `n = 0` visible rows on a non-empty index. 4. Inspect partition `visibleVersion` in `IndexSamplingSnapshot` (fetching Cloud version snapshots outside `table.readLock()`) to impute unreported sibling tablets and defer analyze when written partitions have zero reported rows. - Rejected alternative: post-hoc clamping of inconsistent per-column `row_count` inside `StatsCalculator`, which leaves persisted `column_statistics` inconsistent. ### Impact FE OLAP statistics collection (`org.apache.doris.statistics.sampling.*`, `OlapAnalysisTask`, `TableStatisticsSqlBuilder`, `AnalysisJob`, `SessionVariable`) on shared-nothing and Cloud deployments. ### Reproduction or evidence Verified via 128 FE unit/planner/Monte Carlo benchmark tests (`HierarchicalFixedBudgetTabletSamplingMethodTest`, `TableStatisticsSqlBuilderTest`, `OlapSamplingIntegrationTest`, `SamplingEstimationBenchmarkTest`) and live-cluster `test_fixed_block_analyze.groovy`. ### Scope and non-goals Covers table-level OLAP statistics sampling framework, single-scan CTE SQL generation, and `DUP_KEYS` / `UNIQUE_KEYS` (MOW) `FIXED_BLOCK` integration behind `enable_fixed_block_stats_sampling`. `UNIQUE_KEYS` (MOR) and `AGG_KEYS` key-range merging are covered in the next PR. ### Acceptance criteria - Equal marginal block inclusion probability `q` verified across stratified tablet tiers. - Single physical `OlapScanNode` per sampled column SQL plan. - Identical `row_count` across all columns of an index within one `AnalysisJob`, and existing stats preserved when row reports lag. ### Risks and compatibility Pure FE change (`enable_fixed_block_stats_sampling` introduced with `SET GLOBAL` fallback to `LegacyTabletSamplingMethod`). Mixed-version clusters without `supports_fixed_block_sampling_v1` automatically use `LegacyTabletSamplingMethod`. ### Related Builds on repeatable `FIXED_BLOCK` OLAP scan support. -- 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]
