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

   ### Background
   
   Sampled `ANALYZE TABLE` on OLAP tables creates one `OlapAnalysisTask` per 
column. Even when columns of the same index share a compatible `FIXED_BLOCK` or 
`KEY_RANGE_BLOCK` plan, each column task runs its own `TABLESAMPLE` SQL query, 
repeating storage scans, MOR/`AGG_KEYS` multi-way key merges, Delete Bitmap 
checks, and `sample_tablet_key_ranges` RPCs once per column. Separately, 
`ColumnMinMaxBatchCollector` runs unbounded `SELECT MIN(c), MAX(c)` queries for 
key and `DUP_KEYS`/MOW columns, and `StatisticsUtil.buildConnectContext` pins 
both background auto-analyze and manual foreground `ANALYZE` to a single 
pipeline instance.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: #70999 (depends on)
   PR Type: Enhancement
   
   Problem Summary:
   
   Wide OLAP tables scan and merge sampled blocks `C` times for `C` columns, 
`ColumnMinMaxBatchCollector` degrades to a full-table scan or 
multi-thousand-tablet footer sweep on `RANDOM` `AGG_KEYS` keys, `row_ttl` 
tables, cut `>= 512B` string ZoneMaps, and high-tablet-count tables, narrow 
`KEY_RANGE_BLOCK` units amplify `64 KB` page reads across overlapping segments, 
and manual `ANALYZE` is serialized on one pipeline instance. This PR batches 
multi-column sampled scans per index via `ColumnSampleBatchCollector`, routes 
non-metadata-safe or high-tablet-count bounds to in-sample `MIN`/`MAX`, caps 
policy-level `KEY_RANGE_BLOCK` intervals per selected tablet/partition, and 
decouples manual vs automatic statistics pipeline parallelism. Existing 
clusters automatically reduce wide-table sampled scans by up to 16x per index 
on upgrade without disk or RPC format changes.
   
   ### Details
   
   - **Change map:** 13 files (+1,123/-39): production FE code +784/-39 across 
11 files, JUnit tests +339/-0 across 2 files (`ColumnSampleBatchCollectorTest`, 
`TableStatisticsSqlBuilderTest`):
     1. Multi-column OLAP sample CTE batching (`ColumnSampleBatchCollector`, 
`TableStatisticsSqlBuilder`, `OlapAnalysisTask`, `BaseAnalysisTask`, ~740 
lines).
     2. Metadata-safe bounds routing, policy-level `KEY_RANGE_BLOCK` interval 
coalescing, and manual vs auto-analyze pipeline parallelism 
(`ColumnMinMaxBatchCollector`, `HierarchicalFixedBudgetTabletSamplingMethod`, 
`SessionVariable`, `Config`, ~45 lines).
   - **Before and after:**
     - Sampled OLAP column tasks on the same index batch up to 
`statistics_sample_batch_columns` (default `16`) columns into one materialized 
`WITH sample_base AS (...)` scan query (`MultiCastDataStreamSink`), isolating 
oversized strings per column via a boolean aggregate flag (`MAX(over_limit)`) 
and `NULL`-masking instead of aborting sibling columns with `assert_true`.
     - `RANDOM` `AGG_KEYS` key columns, `row_ttl` tables, string columns with 
max byte length `>= 512` (or `STRING`), partition-scoped samples, and indexes 
with tablet count exceeding `statistics_max_sample_tablets` compute `MIN`/`MAX` 
inside the sampled scan (`OlapAnalysisTask.prefersInSampleBounds`) rather than 
scanning the full table or all tablet footers.
     - Policy-level `KEY_RANGE_BLOCK` plans coalesce narrow `unit_rows` into at 
most ~32 stratified contiguous intervals per selected tablet/partition while 
preserving exact marginal inclusion probability.
     - Manual `ANALYZE` (`JobType.MANUAL`) executes internal SQL with 
`manual_statistics_sql_parallel_exec_instance_num` (`4`), while 
`JobType.SYSTEM` auto-analyze remains at 
`statistics_sql_parallel_exec_instance_num` (`1`).
   - **Configs and defaults:**
     - New global session variable `statistics_sample_batch_columns` (default 
`16`; `<= 1` disables multi-column sample batching at runtime via `SET GLOBAL`).
     - New mutable FE config `manual_statistics_sql_parallel_exec_instance_num` 
(default `4`).
   - **Impact on existing users:** Upgraded clusters automatically batch 
multi-column sampled OLAP scans, avoid full-table `MIN`/`MAX` fallbacks on 
`RANDOM` `AGG_KEYS` / `row_ttl` / `STRING` / `> 512`-tablet tables, and 
parallelize manual `ANALYZE` while keeping background auto-analyze throttled at 
1 instance. Setting `SET GLOBAL statistics_sample_batch_columns = 1` restores 
per-column sample queries.
   - **Results:** On a local `RELEASE` 1-FE/1-BE cluster (8 buckets):
     - 32-column `AGG_KEYS` table (4 keys + 28 value columns, 800,000 physical 
rows across 8 uncompacted overlapping rowsets, `SAMPLE ROWS 16384`, 3 runs 
after warmup): median latency dropped from `974.0 ms` (`min = 954.6 ms`, `max = 
991.9 ms`) at `statistics_sample_batch_columns = 1` to `486.3 ms` (`min = 464.6 
ms`, `max = 492.5 ms`) at `statistics_sample_batch_columns = 16` (`2.00x` 
speedup, 32/32 columns collected).
     - 16-column `RANDOM` `AGG_KEYS` table (600,000 physical rows across 6 
overlapping rowsets, `batch = 16` + in-sample bounds): median `264.3 ms` (`min 
= 263.2 ms`, `max = 271.1 ms`, 16/16 columns collected without a full-table 
`MIN`/`MAX` scan).
     - 2-column narrow `DUP_KEYS` control table (200,000 rows): `batch = 1` 
median `114.5 ms` vs `batch = 16` median `96.4 ms` (no regression).
   
   ### Testing
   
   - `mvn checkstyle:check -pl fe-common,fe-core`: 0 violations locally.
   - `./run-fe-ut.sh --run ...`: 111 FE unit tests passed locally, including 
`ColumnSampleBatchCollectorTest` and `TableStatisticsSqlBuilderTest`.
   - `./run-regression-test.sh` on local isolated cluster: 
`test_fixed_block_sample`, `test_key_range_block_sample`, 
`test_sample_minmax_batch`, `test_fixed_block_analyze`, and 
`test_analyze_long_string` passed.
   
   ### Notes for Reviewers
   
   - Stacked on #70999; review top commit `6bfcbabe8c5` for the standalone diff 
until #70999 merges.
   
   ### Release note
   
   Batch multi-column OLAP sampled statistics scans, bound `MIN`/`MAX` 
collection to metadata-safe tables within the sample tablet budget, cap 
`KEY_RANGE_BLOCK` interval seeks per tablet, and parallelize manual `ANALYZE` 
execution.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: Yes (new session variable 
`statistics_sample_batch_columns` and FE config 
`manual_statistics_sql_parallel_exec_instance_num` in `apache/doris-website`)
   - Pre-submission status: Ready
   
   ### AI Disclosure
   
   - Tool: Antigravity
   - Generated: code, tests, this description
   - Human review: not stated
   


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