924060929 opened a new pull request, #70996:
URL: https://github.com/apache/doris/pull/70996

   ### Background
   
   Legacy sampled OLAP statistics collection selects whole tablets and applies 
`LIMIT` on value columns, which scans entire large tablets on key/partition 
columns, biases prefix values on clustered columns, and can publish slightly 
different `row_count` values across columns of the same index 
(`FilterEstimation.isOnBase()` sensitivity). In addition, delayed tablet 
row-count reports on written partitions (especially in Cloud mode) can cause 
auto-analyze to drop existing statistics or write all-zero rows.
   
   ### What problem does this PR solve?
   
   Issue Number: close #70989
   Related PR: #70995 (depends on)
   PR Type: Feature
   
   Problem Summary:
   
   Introduce a pluggable FE OLAP sampling framework 
(`LegacyTabletSamplingMethod` and 
`HierarchicalFixedBudgetTabletSamplingMethod`) gated by 
`enable_fixed_block_stats_sampling` (default `false`), execute single-scan 
sampled statistics SQL over PR2's internal `FIXED_BLOCK` scan ranges, freeze 
one authoritative population row count `N` per `(job, indexId)`, and protect 
existing statistics when tablet row reports are pending or when a block sample 
observes zero visible rows.
   
   ### Details
   
   - **Change map:** 20 FE production files 
(`org.apache.doris.statistics.sampling.*`, `TableStatisticsSqlBuilder`, 
`OlapAnalysisTask`, `BaseAnalysisTask`, `AnalysisJob`, 
`StatisticsAutoCollector`, `ColStatsData`, `SessionVariable`, `StatisticsUtil`) 
and 12 FE unit/benchmark/regression test files. External table statistics 
classes remain untouched.
   - **Scope:** Table-level OLAP column statistics collection on Local and 
Cloud clusters, including explicitly bound non-base rollup indexes.
   - **Design:**
     - `HierarchicalFixedBudgetTabletSamplingMethod` performs three-stage 
equal-probability physical block sampling (`pi_h * p_h = q`) with logarithmic 
tablet-size stratification (`<= 3` tiers), water-filling seat allocation (`K / 
16` for key/partition columns, `K / 32` for value columns), pre-draw worst-case 
`m`-partition tablet-count and UTF-8 SQL-byte enforcement, and exact binary64 
`BigInteger` systematic rounding (`<= 4` groups, supporting 
`statistics_max_sample_tablets >= 1`).
     - `TableStatisticsSqlBuilder` eliminates the third CTE consumer via `stats 
LEFT JOIN hot_top ON TRUE` and `OlapAnalysisTask` configures 
`enableCTEMaterialize = true`, `inlineCTEReferencedThreshold = 1`, 
`cteInlineMode = -1` so sampled and full OLAP statistics queries execute a 
single physical `OlapScanNode` while preserving long-string `assert_true` 
guards.
     - `AnalysisJob` freezes a single authoritative `N` per target `indexId` 
across all columns in the job, enforces `0 <= null_count <= N` and `0 <= ndv <= 
N - null_count`, preserves 64-bit integer precision in `ColStatsData`, and 
skips publishing when a `FIXED_BLOCK` sample observes `n = 0` visible rows on a 
non-empty index.
     - `IndexSamplingSnapshot` checks partition `visibleVersion` (via 
MetaService snapshot in Cloud mode outside `table.readLock()`), imputes 
zero/unreported tablets in written partitions (`visibleVersion > 1`) using 
partition-then-index positive tablet means strictly for 
budgeting/stratification, and defers analyze instead of dropping or zeroing 
statistics when written partitions have no positive row reports yet.
   - **Usage:**
     - `SET GLOBAL enable_fixed_block_stats_sampling = true;` (default `false`)
     - `SET GLOBAL statistics_sample_unit_rows = 1024;`
     - `SET GLOBAL statistics_max_sample_tablets = 512;`
   - **Default behavior:** `enable_fixed_block_stats_sampling` defaults to 
`false`, keeping `LegacyTabletSamplingMethod` as the default sampler while 
sharing the job-level frozen index row count and delayed-report safeguards.
   - **Compatibility:** Fixed-block sampling is gated to `DUP_KEYS` and 
`UNIQUE_KEYS` Merge-on-Write indices where all queryable mix-node candidate 
backends advertise `supports_fixed_block_sampling_v1`; `AGG_KEYS`, 
`UNIQUE_KEYS` Merge-on-Read, non-unique single-distribution columns, and 
mixed-version clusters automatically use `LegacyTabletSamplingMethod`.
   
   ### Testing
   
   - Ran `./run-fe-ut.sh` across 12 statistics/planner test classes (128 tests 
passed, 0 failures), including `TableStatisticsSqlBuilderTest` (verifying 1 
physical `OlapScanNode` across 5 rollup query shapes), 
`HierarchicalFixedBudgetTabletSamplingMethodTest` (16,000-seed marginal 
inclusion verification, ULP boundary rounding, `cap = 1`, and UTF-8 byte caps), 
`OlapSamplingIntegrationTest`, and `SamplingEstimationBenchmarkTest` (600-seed 
Monte Carlo comparison across 5 data distributions).
   - Ran `mvn checkstyle:check -pl fe-core` (0 violations).
   - Ran `regression-test/suites/statistics/test_fixed_block_analyze.groovy` on 
a local FE+BE cluster (passed).
   
   ### Notes for Reviewers
   
   - Stacked on #70995; review top commit `bea99a581c0` for the standalone diff 
until #70995 merges.
   
   ### Release note
   
   Add optional fixed-block sampling for OLAP statistics collection 
(`enable_fixed_block_stats_sampling`, default `false`), unify per-index column 
row counts within an analyze job, and prevent delayed tablet row reports from 
overwriting existing statistics with zeros.
   
   ### Check List (For Author)
   
   - Behavior changed: No
   - Does this need documentation: Yes (global variables 
`enable_fixed_block_stats_sampling`, `statistics_sample_unit_rows`, 
`statistics_max_sample_tablets`)
   - Pre-submission status: Ready
   
   ### AI Disclosure
   
   - Tool: Antigravity & Codex
   - Generated: FE sampling framework, SQL builder, unit/benchmark/regression 
tests, and commit description
   - Human review: Reviewed external-catalog scope isolation, exact binary64 
systematic rounding, `FullScanClause` HLL memory bounds, decimal count 
rounding, `OlapTable` read-lock discipline around Cloud MS RPCs, and 
single-scan Nereids physical plans
   


-- 
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]

Reply via email to