924060929 opened a new issue, #70988:
URL: https://github.com/apache/doris/issues/70988

   ### Background
   
   Sampled OLAP statistics collection needs to estimate column statistics from 
a bounded I/O budget on arbitrarily large tables without scanning entire 
multi-gigabyte tablets or biasing toward prefix key ranges. Doris Segment V2 
already stores segment row counts at the captured visible version and supports 
sparse `RowRanges` filtering inside `BetaRowsetReader`.
   
   ### Current behavior
   
   `TABLESAMPLE` on OLAP tables selects whole tablets (or applies a row 
`LIMIT`), which reads entire large tablets on key/partition columns and 
introduces prefix bias on sorted columns:
   
   ```sql
   SELECT COUNT(*) FROM large_dup_tbl TABLESAMPLE (400000 ROWS) REPEATABLE 1;
   -- Scans whole selected tablets rather than sparse rowid blocks across 
segments.
   ```
   
   ### Expected behavior
   
   Internal OLAP queries support repeatable version-pinned `FIXED_BLOCK` block 
sampling (`TABLESAMPLE (FIXED_BLOCK unit_rows = ..., GROUP (...)) REPEATABLE 
<seed>`) that selects sparse fixed-size rowid blocks across segments at the 
captured visible version, skips empty middle segments and zero-hit tablets 
without constructing iterators, and slices sampled `RowRanges` across parallel 
scanners.
   
   ### Proposed design
   
   1. Add internal Nereids syntax `TABLESAMPLE (FIXED_BLOCK unit_rows = <U>, 
GROUP (tablet_rate = ..., unit_rate = ..., max_units = ..., TABLETS (...))) 
REPEATABLE <seed>` gated to internal sessions 
(`ConnectContext.getState().isInternal()`) or debug point 
`TableSample.allowInternalFixedBlock`.
   2. Add optional Thrift `TPaloScanRange.sample_options` 
(`TTabletSampleOptions`) and BE heartbeat flag 
`supports_fixed_block_sampling_v1`.
   3. Implement `FixedRowIdBlockSampler` on BE using 128-bit fixed-point 
systematic `DependentRounding` ordered by physical `segment.id()` so 
shared-nothing and Cloud non-contiguous segment IDs produce identical draws 
across serial and parallel scans.
   4. Disable storage-layer aggregate/TopN/ANN pushdown, point-query 
short-circuiting, and query-cache normalization on `FIXED_BLOCK` scans, and 
route replicas only to v1-capable backends during rolling upgrades.
   - Rejected alternative: reservoir row-level sampling after decompression, 
which still reads and decompresses every data page.
   
   ### Impact
   
   Internal OLAP statistics scans on both shared-nothing and Cloud deployments 
(`fe-sql-parser`, `fe-core`, `be/src/storage/sampling`, `be/src/exec`, 
`gensrc/thrift`). Public `TABLESAMPLE (... ROWS/PERCENT)` queries are 
unaffected.
   
   ### Reproduction or evidence
   
   Verified via `FixedRowIdBlockSamplerTest` (8/8 BE GTests under native and 
UBSan), `FixedBlockTableSamplePlanTest` + `StatsCalculatorTest` (30/30 FE JUnit 
tests), and live-cluster `test_fixed_block_sample.groovy`.
   
   ### Scope and non-goals
   
   Covers internal `FIXED_BLOCK` physical rowid-block scan planning and 
execution on `DUP_KEYS` and `UNIQUE_KEYS` (Merge-on-Write) indexes. Does not 
wire `OlapAnalysisTask` yet (handled in the follow-up sampling framework PR) 
and does not cover `UNIQUE_KEYS` Merge-on-Read or `AGG_KEYS` key-range merging 
(handled in the key-range block sampling PR).
   
   ### Acceptance criteria
   
   - Deterministic `FIXED_BLOCK` block selection across serial and parallel 
scanners with physical segment IDs.
   - Zero-hit tablets and empty sampled middle segments skip scanner/iterator 
construction.
   - Rolling upgrade routing selects only `supports_fixed_block_sampling_v1` 
backends.
   
   ### Risks and compatibility
   
   All Thrift additions (`TBackendInfo.supports_fixed_block_sampling_v1 = 12`, 
`TPaloScanRange.sample_options = 15`, `TTabletSampleOptions`) are `optional` 
and collision-free across `branch-3.1` through `master`.
   
   ### Related
   
   Part of the OLAP & Lakehouse bounded-budget block-sampling statistics series.
   


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