You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by "mrhhsg (via GitHub)" <gi...@apache.org> on 2026/03/20 01:28:05 UTC
[PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
mrhhsg opened a new pull request, #61535:
URL: https://github.com/apache/doris/pull/61535
Introduce an EWMA-based AdaptiveBlockSizePredictor that dynamically adjusts SegmentIterator chunk row counts so each output Block stays near the session-variable-configured preferred_block_size_bytes target. A complementary byte-budget stop condition is added to all BlockReader and VCollectIterator accumulation loops so the final Block returned to the upper layer is also bounded.
Key changes:
- New BE config: enable_adaptive_batch_size (default: true)
- New session variables: preferred_block_size_bytes (8 MB), preferred_max_column_in_block_size_bytes (1 MB)
- New Thrift fields 204/205 for FE→BE propagation
- AdaptiveBlockSizePredictor: EWMA per-row and per-column byte estimator with conservative segment-metadata bootstrap
- SegmentIterator: predicts rows before each next_batch call; updates EWMA on success path
- BlockReader: byte-stop in _replace_key_next_block, _unique_key_next_block, _agg_key_next_block
- VCollectIterator: byte-stop in Level1Iterator::_merge_next
- Unit tests and regression tests included
### What problem does this PR solve?
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
### Release note
None
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [ ] Regression test
- [ ] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
- Behavior changed:
- [ ] No.
- [ ] Yes. <!-- Explain the behavior change -->
- Does this need documentation?
- [ ] No.
- [ ] Yes. <!-- Add document PR link here. eg: https://github.com/apache/doris-website/pull/1214 -->
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR should merge into -->
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4098796200
# Cloud UT Coverage Report
Increment line coverage ` ` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/ae43fe96d6a20040c16d54f6ee49141576a11c2a_ae43fe96d6a20040c16d54f6ee49141576a11c2a_cloud/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/ae43fe96d6a20040c16d54f6ee49141576a11c2a_ae43fe96d6a20040c16d54f6ee49141576a11c2a_cloud/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 78.63% (1796/2284) |
| Line Coverage | 64.36% (32264/50130) |
| Region Coverage | 65.24% (16154/24760) |
| Branch Coverage | 55.65% (8602/15456) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "velodb-robyang (via GitHub)" <gi...@apache.org>.
velodb-robyang commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3071099182
##########
be/src/exec/common/hash_table/join_hash_table.h:
##########
@@ -100,22 +100,27 @@ class JoinHashTable {
_keep_null_key = keep_null_key;
}
+ // batch_size_limit: when > 0, overrides max_batch_size for this call only (thread-safe).
template <int JoinOpType>
auto find_batch(const Key* __restrict keys, const uint32_t* __restrict build_idx_map,
int probe_idx, uint32_t build_idx, int probe_rows,
uint32_t* __restrict probe_idxs, bool& probe_visited,
uint32_t* __restrict build_idxs, const uint8_t* null_map,
- bool with_other_conjuncts, bool is_mark_join, bool has_mark_join_conjunct) {
+ bool with_other_conjuncts, bool is_mark_join, bool has_mark_join_conjunct,
+ int batch_size_limit = 0) {
Review Comment:
这里不要加默认值0, 你如果加了,就意味着上面有一些地方没有传递,就会漏,后面可能我们这次改完了,有人没设置这个batch size 就会引入新问题,我们就得继续定位。
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3007194811
##########
be/src/storage/iterators.h:
##########
@@ -111,6 +111,13 @@ class StorageReadOptions {
OlapReaderStatistics* stats = nullptr;
bool use_page_cache = false;
uint32_t block_row_max = 4096 - 32; // see https://github.com/apache/doris/pull/11816
+ // Adaptive batch size target (bytes). 0 = disabled.
+ size_t preferred_block_size_bytes = 0;
+ // Per-column byte limit for the EWMA predictor. 0 = no column limit.
+ size_t preferred_max_col_bytes = 1048576;
+ // True output columns of the final block. Used by AdaptiveBlockSizePredictor.
+ // Must match the order and count of columns in the block passed to next_batch().
+ std::vector<ColumnId> adaptive_batch_output_columns;
Review Comment:
我感觉这里跟是否true output 没有关系。
我们的读取是分层的,应该是每层都有自己的output,那么就应该每层根据自己的output 来控制block size
##########
be/src/storage/segment/adaptive_block_size_predictor.cpp:
##########
@@ -0,0 +1,138 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "storage/segment/adaptive_block_size_predictor.h"
+
+#include <algorithm>
+#include <cstddef>
+
+#include "core/block/block.h"
+#include "storage/segment/segment.h"
+#include "storage/tablet/tablet_schema.h"
+
+namespace doris::segment_v2 {
+
+AdaptiveBlockSizePredictor::AdaptiveBlockSizePredictor(size_t preferred_block_size_bytes,
+ size_t preferred_max_col_bytes,
+ const Segment& segment,
Review Comment:
This interface is tight coupling with current internal table's logic. We could not use it in other cases, for example:
1. scan next table
2. stream load
3. join operator?
maybe we should move segment like logic from this class, and this class should be a util
##########
be/src/storage/segment/segment_iterator.cpp:
##########
@@ -369,6 +369,14 @@ Status SegmentIterator::_init_impl(const StorageReadOptions& opts) {
// Read options will not change, so that just resize here
_block_rowids.resize(_opts.block_row_max);
+ // Adaptive batch size: snapshot the initial row limit and create predictor if enabled.
Review Comment:
And please use AI to find all scan like operators that may need use adaptive block size. because we need pick scan like optimizations to branch 4.0 and branch 4.1.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3007170018
##########
be/src/storage/segment/segment_iterator.cpp:
##########
@@ -369,6 +369,14 @@ Status SegmentIterator::_init_impl(const StorageReadOptions& opts) {
// Read options will not change, so that just resize here
_block_rowids.resize(_opts.block_row_max);
+ // Adaptive batch size: snapshot the initial row limit and create predictor if enabled.
Review Comment:
some other cases:
1. topn lazy materialization also use segment iterator?
2. point query ?
3. scan stage of streamload?
4. external table, especially max compute table , iceberg, paimon, hive
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3007170018
##########
be/src/storage/segment/segment_iterator.cpp:
##########
@@ -369,6 +369,14 @@ Status SegmentIterator::_init_impl(const StorageReadOptions& opts) {
// Read options will not change, so that just resize here
_block_rowids.resize(_opts.block_row_max);
+ // Adaptive batch size: snapshot the initial row limit and create predictor if enabled.
Review Comment:
some other cases:
1. topn lazy materialization also use segment iterator?
2. point query ?
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4199709277
run buildall
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4140502868
PR approved by anyone and no changes requested.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4256595131
/review
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4190236354
# BE UT Coverage Report
Increment line coverage `57.73% (392/679)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/a6852d1b3244bc2b4b0e0ed25aad98b25f80599e_a6852d1b3244bc2b4b0e0ed25aad98b25f80599e/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/a6852d1b3244bc2b4b0e0ed25aad98b25f80599e_a6852d1b3244bc2b4b0e0ed25aad98b25f80599e/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 53.01% (20112/37942) |
| Line Coverage | 36.58% (188929/516450) |
| Region Coverage | 32.86% (146792/446773) |
| Branch Coverage | 33.95% (64221/189142) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4136818707
# BE Regression && UT Coverage Report
Increment line coverage `100% (0/0)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_841c2a7248322bd5f241495adbc38da11aecef50_merge/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_841c2a7248322bd5f241495adbc38da11aecef50_merge/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 71.81% (26495/36898) |
| Line Coverage | 54.67% (279490/511188) |
| Region Coverage | 51.82% (231780/447244) |
| Branch Coverage | 53.31% (100222/187989) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3007164674
##########
fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java:
##########
@@ -1282,6 +1285,20 @@ public void checkQuerySlotCount(String slotCnt) {
@VariableMgr.VarAttr(name = BROKER_LOAD_BATCH_SIZE, fuzzy = true, checker = "checkBatchSize")
public int brokerLoadBatchSize = 16352;
+ // Target output block size in bytes for adaptive batch size. 0 disables the byte limit.
+ // Default 8MB. Passed to storage layer to control how many rows each SegmentIterator chunk
+ // should contain so the final Block stays near this size.
+ @VariableMgr.VarAttr(name = PREFERRED_BLOCK_SIZE_BYTES, needForward = true,
+ description = {"目标输出 Block 字节数上限,自适应 batch size 功能使用,0 表示不限制,默认 8MB",
+ "Target output block size in bytes for adaptive batch size. 0 disables the limit. Default 8MB."})
+ public long preferredBlockSizeBytes = 8388608L; // 8MB
+
+ // Per-column byte limit when computing adaptive chunk rows. 0 disables the per-column limit.
+ @VariableMgr.VarAttr(name = PREFERRED_MAX_COLUMN_IN_BLOCK_SIZE_BYTES, needForward = true,
+ description = {"自适应 batch size 时单列字节数上限,0 表示不限制,默认 1MB",
+ "Per-column byte limit for adaptive batch size. 0 disables per-column limit. Default 1MB."})
+ public long preferredMaxColumnInBlockSizeBytes = 1048576L; // 1MB
Review Comment:
why need this parameter?
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4174467142
# FE UT Coverage Report
Increment line coverage ` 100.00% (6/6)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_eee985b7d8c909cb70ddac3af54a70d35d76ba9a/fe_increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_eee985b7d8c909cb70ddac3af54a70d35d76ba9a/fe_report/index.html)
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3025552834
##########
be/src/storage/iterator/vcollect_iterator.cpp:
##########
@@ -913,6 +955,24 @@ Status VCollectIterator::Level1Iterator::_merge_next(Block* block) {
continuous_row_in_block = 0;
pre_row_ref = cur_row;
Review Comment:
1. 输出行数已被硬限制:`_topn_next` 最终只输出 _topn_limit 行(通常很小,如 LIMIT 20),sorted_row_pos 始终被裁剪到 _topn_limit 大小(line 440-445)。这个行数天然远小于任何 batch 上限。
2. 语义不同:_merge_next 是一个流式合并迭代器,会被上层反复调用产出 block,每次产出多少行直接影响 pipeline 下游的内存占用。而 _topn_next 是一次性调用——它遍历所有 rowset,维护一个 top-N
堆,最后一次性输出结果,不存在"中途可以切分输出"的场景。
3. 内存已有保护:line 448 有 shrink 逻辑(mutable_block.rows() > _topn_limit
* 2 时压缩),且中间态的 `mutable_block `行数也被限制在 2 * `_topn_limit` 左右。
4. 调用链不同:`_topn_next` 由 VCollectIterator::next(Block*) 在 `_topn_filter_is_set` 时直接走此路径,上层期望拿到完整的 top-N 结果,强行截断反而破坏语义正确性。
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4098317159
run buildall
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4128045326
# Cloud UT Coverage Report
Increment line coverage ` ` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/841c2a7248322bd5f241495adbc38da11aecef50_841c2a7248322bd5f241495adbc38da11aecef50_cloud/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/841c2a7248322bd5f241495adbc38da11aecef50_841c2a7248322bd5f241495adbc38da11aecef50_cloud/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 78.67% (1796/2283) |
| Line Coverage | 64.39% (32276/50128) |
| Region Coverage | 65.25% (16157/24761) |
| Branch Coverage | 55.73% (8612/15454) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3090222544
##########
be/src/runtime/runtime_state.h:
##########
@@ -138,7 +138,41 @@ class RuntimeState {
const DescriptorTbl& desc_tbl() const { return *_desc_tbl; }
void set_desc_tbl(const DescriptorTbl* desc_tbl) { _desc_tbl = desc_tbl; }
- MOCK_FUNCTION int batch_size() const { return _query_options.batch_size; }
+
+ // Row-count limit for output blocks (default 65535, range [1, 65535]).
+ // Consistent with SessionVariable.batchSize on FE side.
+ MOCK_FUNCTION int batch_size() const {
+ static constexpr int kDefault = 65535;
+ auto v = _query_options.batch_size;
+ return std::min(std::max(1, v), kDefault);
+ }
+
+ // Target byte budget per output block (default 8MB).
+ // FE validates the range [1MB, 512MB] in SessionVariable; BE trusts that
+ // but applies a default when the field is unset.
+ MOCK_FUNCTION size_t preferred_block_size_bytes() const {
+ static constexpr int64_t kDefault = 8388608L; // 8MB
+ static constexpr int64_t kMax = 536870912L; // 512MB
+ static constexpr int64_t kMin = 1048576L; // 1MB
+ if (_query_options.__isset.preferred_block_size_bytes) [[likely]] {
+ return std::max(kMin, std::min(_query_options.preferred_block_size_bytes, kMax));
+ }
+ return kDefault;
Review Comment:
`preferred_block_size_bytes()` returning an 8MB default when the thrift field is *unset* breaks the feature flag / compatibility contract. In mixed-version clusters, an old FE cannot send field 214 at all, but new BEs will still enable adaptive sizing because callers like `OlapScanner`, `Scanner`, `Union`, `Sort`, etc. read this accessor directly. That changes execution semantics during rolling upgrade and also means `enable_adaptive_batch_size=false` does not fully disable the feature for paths that only consult `RuntimeState`. The unset case needs to preserve legacy behavior (typically `0`) unless the feature was explicitly requested by FE.
##########
be/src/storage/iterator/block_reader.cpp:
##########
@@ -476,9 +493,16 @@ Status BlockReader::_agg_key_next_block(Block* block, bool* eof) {
}
if (!_next_row.is_same) {
Review Comment:
This check is too sparse for the path that actually assembles the final block. Because it only runs every 64 groups, a wide-row workload can overshoot the byte budget by dozens of rows before the first stop condition is even evaluated. There is no later storage-layer trimming step here, so `UNIQUE_KEYS` / `AGG_KEYS` can still return blocks far above the configured target (for example, 1MB rows with an 8MB budget still grow to ~64MB before the first check). That defeats the core invariant this PR is trying to enforce.
##########
fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java:
##########
@@ -6035,6 +6063,30 @@ public void checkBatchSize(String batchSize) {
}
}
+ private static final long PREFERRED_BLOCK_SIZE_BYTES_MIN = 1048576L; // 1MB
+ private static final long PREFERRED_BLOCK_SIZE_BYTES_MAX = 536870912L; // 512MB
+
Review Comment:
The new API/behavior contract is internally inconsistent here. The thrift comment says `preferred_block_size_bytes = 0` disables adaptive sizing, and the PR description also documents `SET preferred_block_size_bytes = 0` as the per-query off switch. But this validator rejects `0`, and BE currently clamps an explicitly sent `0` up to `1MB` instead of honoring it. So users cannot actually disable the feature per query as documented, and non-FE clients following the thrift contract will get the opposite behavior. Please make FE validation, thrift comments, and BE handling agree on the same sentinel semantics.
##########
be/src/exec/sort/vsorted_run_merger.cpp:
##########
@@ -196,6 +223,14 @@ Status VSortedRunMerger::get_next(Block* output_block, bool* eos) {
do_insert();
return Status::OK();
Review Comment:
The multi-run merge path still enforces the byte budget too late. Rows are buffered and materialized into `m_block` only every 256 rows, and the byte limit is checked only after that batched insert. For wide rows, that means the first stop point can already be orders of magnitude above the target (for example, ~256MB before checking against an 8MB budget with 1MB rows). Since `ExchangeSourceOperator` and the sort sources now wire this budget through, this path should enforce it at a finer granularity or with a safe estimate before materializing another large batch.
##########
be/src/storage/iterator/vcollect_iterator.cpp:
##########
@@ -488,10 +495,56 @@ Status VCollectIterator::_topn_next(Block* block) {
<< " mutable_block.rows()=" << mutable_block.rows();
*block = mutable_block.to_block();
+ // If byte budget is active and the result exceeds it, split into chunks.
+ size_t preferred_bytes = _reader->preferred_block_size_bytes();
+ if (preferred_bytes > 0 && block->rows() > 1 && block->bytes() > preferred_bytes) {
+ _topn_result_block = std::move(*block);
+ _topn_result_offset = 0;
+ return _topn_next_chunk(block);
+ }
+
_topn_eof = true;
return block->rows() > 0 ? Status::OK() : Status::Error<END_OF_FILE>("");
}
+Status VCollectIterator::_topn_next_chunk(Block* block) {
+ size_t total_rows = _topn_result_block.rows();
+ if (_topn_result_offset >= total_rows) {
+ _topn_result_block.clear();
+ _topn_eof = true;
+ return Status::Error<END_OF_FILE>("");
+ }
+
+ size_t remaining = total_rows - _topn_result_offset;
+ size_t chunk_rows = remaining;
+
+ // Cap by batch_max_rows.
+ chunk_rows = std::min(chunk_rows, (size_t)_reader->batch_max_rows());
+
+ // Cap by byte budget.
+ size_t preferred_bytes = _reader->preferred_block_size_bytes();
Review Comment:
This chunking logic uses the *global average* row width of the full TopN result to choose `chunk_rows`, but it never checks the actual byte size of the prefix being emitted. With skewed row sizes, the first chunk can still exceed `preferred_block_size_bytes` by a large margin even when a smaller prefix would fit. Example: one very large leading row plus many tiny rows keeps the average low, so `chunk_rows` stays > 1 and the first returned chunk still violates the budget. To preserve the byte-budget contract, this needs a prefix-size based split rather than an average over the whole result block.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4254205504
# BE UT Coverage Report
Increment line coverage `59.31% (548/924)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/d4d5d5f9628109e8fd7fc00ceaf529d5bf8dd0c6_d4d5d5f9628109e8fd7fc00ceaf529d5bf8dd0c6/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/d4d5d5f9628109e8fd7fc00ceaf529d5bf8dd0c6_d4d5d5f9628109e8fd7fc00ceaf529d5bf8dd0c6/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 53.15% (20224/38053) |
| Line Coverage | 36.73% (190626/519035) |
| Region Coverage | 32.98% (148004/448737) |
| Branch Coverage | 34.10% (64809/190053) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4094763230
/review
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4245079901
run buildall
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4245567667
# Cloud UT Coverage Report
Increment line coverage ` ` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/122017b741600708da7557ac4142cc8b07d21d0e_122017b741600708da7557ac4142cc8b07d21d0e_cloud/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/122017b741600708da7557ac4142cc8b07d21d0e_122017b741600708da7557ac4142cc8b07d21d0e_cloud/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 78.48% (1798/2291) |
| Line Coverage | 64.13% (32288/50345) |
| Region Coverage | 65.07% (16246/24967) |
| Branch Coverage | 55.60% (8685/15620) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4246480029
# FE Regression Coverage Report
Increment line coverage ` 78.57% (11/14)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_122017b741600708da7557ac4142cc8b07d21d0e_merge_fe/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_122017b741600708da7557ac4142cc8b07d21d0e_merge_fe/report/index.html)
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4097276979
# BE UT Coverage Report
Increment line coverage ` ` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/f404b067c8aa7622413fd7d269235aaccd195121_f404b067c8aa7622413fd7d269235aaccd195121/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/f404b067c8aa7622413fd7d269235aaccd195121_f404b067c8aa7622413fd7d269235aaccd195121/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 52.85% (19877/37610) |
| Line Coverage | 36.36% (185718/510836) |
| Region Coverage | 32.61% (143863/441137) |
| Branch Coverage | 33.79% (62960/186314) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4095727520
# BE Regression && UT Coverage Report
Increment line coverage `100% (0/0)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_daebf3f9ccd3a062258f75fb387de4d89c7ecce6_merge/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_daebf3f9ccd3a062258f75fb387de4d89c7ecce6_merge/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 73.32% (26944/36750) |
| Line Coverage | 56.73% (288414/508437) |
| Region Coverage | 53.94% (239774/444521) |
| Branch Coverage | 55.74% (103911/186407) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4175496566
# BE Regression && UT Coverage Report
Increment line coverage `88.89% (368/414)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_eee985b7d8c909cb70ddac3af54a70d35d76ba9a_merge/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_eee985b7d8c909cb70ddac3af54a70d35d76ba9a_merge/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 73.68% (27354/37125) |
| Line Coverage | 57.25% (294304/514110) |
| Region Coverage | 54.33% (244503/450043) |
| Branch Coverage | 56.16% (106269/189226) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4174615630
<details>
<summary>TPC-H: <b>Total hot run time: 29872 ms</b></summary>
```
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit eee985b7d8c909cb70ddac3af54a70d35d76ba9a, data reload: false
------ Round 1 ----------------------------------
orders Doris NULL NULL 0 0 0 NULL 0 NULL NULL 2023-12-26 18:27:23 2023-12-26 18:42:55 NULL utf-8 NULL NULL
============================================
q1 17645 3830 3800 3800
q2 q3 10685 897 613 613
q4 4714 467 373 373
q5 7792 1353 1144 1144
q6 317 176 143 143
q7 1043 943 775 775
q8 11009 1474 1407 1407
q9 7555 5391 5356 5356
q10 6344 2022 1774 1774
q11 471 292 282 282
q12 841 707 516 516
q13 18033 2807 2174 2174
q14 287 280 257 257
q15 q16 906 869 800 800
q17 1086 1109 832 832
q18 6554 5729 5565 5565
q19 1175 1262 1266 1262
q20 733 644 479 479
q21 4595 2440 1991 1991
q22 442 394 329 329
Total cold run time: 102227 ms
Total hot run time: 29872 ms
----- Round 2, with runtime_filter_mode=off -----
orders Doris NULL NULL 150000000 42 6422171781 NULL 22778155 NULL NULL 2023-12-26 18:27:23 2023-12-26 18:42:55 NULL utf-8 NULL NULL
============================================
q1 4640 4498 4525 4498
q2 q3 4633 4776 4146 4146
q4 2033 2110 1425 1425
q5 4956 4968 5270 4968
q6 196 169 128 128
q7 2024 1839 1597 1597
q8 3309 3040 3063 3040
q9 8283 8308 8551 8308
q10 4676 4471 4196 4196
q11 582 423 380 380
q12 666 717 491 491
q13 3238 3157 2442 2442
q14 308 328 275 275
q15 q16 762 764 692 692
q17 1415 1284 1238 1238
q18 7991 7042 7076 7042
q19 1185 1185 1161 1161
q20 2306 2250 1971 1971
q21 6207 5339 4833 4833
q22 535 499 422 422
Total cold run time: 59945 ms
Total hot run time: 53253 ms
```
</details>
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3043611938
##########
be/src/storage/segment/segment_iterator.cpp:
##########
@@ -2511,6 +2541,28 @@ Status SegmentIterator::next_batch(Block* block) {
_init_virtual_columns(block);
auto status = [&]() {
RETURN_IF_CATCH_EXCEPTION({
+ // Adaptive batch size: predict how many rows this batch should read.
Review Comment:
This clamp prevents the storage-side predictor from ever growing past the legacy reader cap. `_initial_block_row_max` is captured from `_opts.block_row_max`, and that value still comes from `read_context->batch_size` in `BetaRowsetReader`. For narrow OLAP scans, `predict_next_rows()` may return a much larger value, but `std::min(predicted, _initial_block_row_max)` forces it back down to the old fixed batch size, so this path can only shrink batches, never grow toward `preferred_block_size_rows()`.
##########
be/src/runtime/runtime_state.h:
##########
@@ -138,7 +138,40 @@ class RuntimeState {
const DescriptorTbl& desc_tbl() const { return *_desc_tbl; }
void set_desc_tbl(const DescriptorTbl* desc_tbl) { _desc_tbl = desc_tbl; }
+
+ MOCK_FUNCTION int block_max_rows() const {
+ return config::enable_adaptive_batch_size
Review Comment:
`preferred_block_size_bytes = 0` is documented as the session-level switch to disable adaptive sizing, but `block_max_rows()` still returns `max(batch_size, preferred_block_size_rows())` whenever the global config is on. After this PR, many operators use `state->block_max_rows()`, so `SET preferred_block_size_bytes = 0` still inflates the row cap from the legacy `batch_size` to 65535 by default instead of restoring the old fixed-row behavior. The same issue exists in `TabletReader::batch_max_rows()`, so the disable path is inconsistent across BE.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4127708145
run buildall
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4133710924
# Cloud UT Coverage Report
Increment line coverage ` ` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/841c2a7248322bd5f241495adbc38da11aecef50_841c2a7248322bd5f241495adbc38da11aecef50_cloud/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/841c2a7248322bd5f241495adbc38da11aecef50_841c2a7248322bd5f241495adbc38da11aecef50_cloud/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 78.67% (1796/2283) |
| Line Coverage | 64.42% (32291/50128) |
| Region Coverage | 65.30% (16170/24761) |
| Branch Coverage | 55.74% (8614/15454) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4295042196
/review
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3037577896
##########
be/src/runtime/runtime_state.h:
##########
@@ -138,7 +138,40 @@ class RuntimeState {
const DescriptorTbl& desc_tbl() const { return *_desc_tbl; }
void set_desc_tbl(const DescriptorTbl* desc_tbl) { _desc_tbl = desc_tbl; }
+
+ MOCK_FUNCTION int block_max_rows() const {
+ return config::enable_adaptive_batch_size
+ ? std::max(_query_options.batch_size, int(preferred_block_size_rows()))
Review Comment:
`preferred_block_size_rows` is documented in FE as an upper bound, but this `std::max()` turns it into a lower bound whenever the session value is smaller than `batch_size`. After this PR, operators like `SetSource`, `StreamingAgg`, `HashJoinProbe`, etc. call `state->block_max_rows()`, so a session such as `set batch_size = 8192; set preferred_block_size_rows = 1024;` will still emit 8192-row blocks. That looks like a behavior regression against the new session-variable contract.
##########
be/src/exec/operator/distinct_streaming_aggregation_operator.cpp:
##########
@@ -392,9 +392,13 @@ Status DistinctStreamingAggOperatorX::pull(RuntimeState* state, Block* block, bo
bool DistinctStreamingAggOperatorX::need_more_input_data(RuntimeState* state) const {
auto& local_state = get_local_state(state);
- const bool need_batch = local_state._stop_emplace_flag
- ? local_state._aggregated_block->empty()
- : local_state._aggregated_block->rows() < state->batch_size();
Review Comment:
Checking `block_max_bytes` only in `need_more_input_data()` is too late for this operator. `_distinct_pre_agg_with_serialized_key()` can materialize an oversized `_aggregated_block` in a single `push()`, because the split logic in `_insert_keys_into_block()` still only enforces the row cap stored in `batch_size`. For wide grouping keys, `pull()` will then return a block that already exceeds `state->block_max_bytes()`.
##########
be/src/exec/sort/vsorted_run_merger.cpp:
##########
@@ -197,6 +201,14 @@ Status VSortedRunMerger::get_next(Block* output_block, bool* eos) {
do_insert();
return Status::OK();
}
+
Review Comment:
This fixes the multi-run merge loop, but the `if (_priority_queue.size() == 1)` fast path above still swaps the entire remaining supplier block into `output_block` without checking `_batch_size` or `_block_max_bytes`. Once the merge collapses to one run, sort sources can still emit an oversized block and bypass the adaptive limit.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4198371655
/review
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4249081630
# BE Regression && UT Coverage Report
Increment line coverage `87.50% (791/904)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_25b25c07c01b606be38d8cb16601a25f8a559167_merge/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_25b25c07c01b606be38d8cb16601a25f8a559167_merge/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 73.57% (27411/37258) |
| Line Coverage | 57.21% (295945/517283) |
| Region Coverage | 54.32% (245952/452765) |
| Branch Coverage | 55.98% (106669/190565) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4140502729
PR approved by at least one committer and no changes requested.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4101479003
<details>
<summary>TPC-DS: <b>Total hot run time: 169678 ms</b></summary>
```
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit ae43fe96d6a20040c16d54f6ee49141576a11c2a, data reload: false
query5 4311 670 499 499
query6 340 232 235 232
query7 4219 492 266 266
query8 334 237 226 226
query9 8742 2742 2713 2713
query10 539 414 374 374
query11 6986 5083 4861 4861
query12 189 131 127 127
query13 1280 475 349 349
query14 5737 3760 3545 3545
query14_1 2939 2858 2883 2858
query15 209 200 176 176
query16 982 472 477 472
query17 924 744 642 642
query18 2448 459 351 351
query19 219 226 195 195
query20 133 127 129 127
query21 215 140 112 112
query22 13437 14426 14713 14426
query23 16117 15651 15646 15646
query23_1 15909 15702 15816 15702
query24 7297 1620 1240 1240
query24_1 1234 1239 1279 1239
query25 559 498 404 404
query26 1237 268 151 151
query27 2774 487 305 305
query28 4345 1861 1865 1861
query29 820 566 488 488
query30 310 224 196 196
query31 996 952 903 903
query32 80 71 71 71
query33 515 346 293 293
query34 893 879 547 547
query35 646 703 592 592
query36 1074 1104 986 986
query37 141 100 82 82
query38 2937 2940 2900 2900
query39 849 822 811 811
query39_1 793 794 809 794
query40 237 157 140 140
query41 63 59 61 59
query42 260 261 255 255
query43 256 248 229 229
query44
query45 199 193 186 186
query46 875 997 605 605
query47 2495 2130 2072 2072
query48 308 332 234 234
query49 635 471 393 393
query50 693 281 221 221
query51 4027 3958 4048 3958
query52 263 270 260 260
query53 297 348 293 293
query54 311 275 284 275
query55 100 88 87 87
query56 320 336 346 336
query57 1888 1916 1708 1708
query58 285 280 274 274
query59 2783 2967 2773 2773
query60 352 346 328 328
query61 161 161 162 161
query62 638 581 511 511
query63 315 287 294 287
query64 4882 1302 1006 1006
query65
query66 1467 463 390 390
query67 24220 24234 24122 24122
query68
query69 418 321 304 304
query70 993 962 946 946
query71 360 316 309 309
query72 3077 2928 2659 2659
query73 556 559 327 327
query74 9567 9619 9383 9383
query75 2884 2801 2468 2468
query76 2155 1052 695 695
query77 373 432 317 317
query78 10875 11020 10521 10521
query79 2691 762 589 589
query80 1792 675 574 574
query81 564 262 233 233
query82 965 152 121 121
query83 338 271 250 250
query84 303 130 103 103
query85 921 506 477 477
query86 419 317 279 279
query87 3141 3175 3028 3028
query88 3631 2686 2677 2677
query89 429 377 348 348
query90 2038 193 188 188
query91 174 165 137 137
query92 87 74 84 74
query93 1367 822 523 523
query94 638 280 292 280
query95 600 398 325 325
query96 648 532 235 235
query97 2442 2487 2398 2398
query98 248 225 217 217
query99 1029 1008 919 919
Total cold run time: 252034 ms
Total hot run time: 169678 ms
```
</details>
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4095230996
<details>
<summary>TPC-H: <b>Total hot run time: 30963 ms</b></summary>
```
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit daebf3f9ccd3a062258f75fb387de4d89c7ecce6, data reload: false
------ Round 1 ----------------------------------
orders Doris NULL NULL 0 0 0 NULL 0 NULL NULL 2023-12-26 18:27:23 2023-12-26 18:42:55 NULL utf-8 NULL NULL
============================================
q1 17671 4802 4775 4775
q2 q3 10807 879 646 646
q4 4755 454 351 351
q5 8228 1316 1095 1095
q6 258 209 176 176
q7 950 934 776 776
q8 10868 1770 1663 1663
q9 7254 5324 5288 5288
q10 6476 2021 1901 1901
q11 487 320 294 294
q12 839 671 526 526
q13 18097 3025 2203 2203
q14 236 234 218 218
q15 q16 789 777 704 704
q17 935 819 758 758
q18 6446 5588 5519 5519
q19 1231 1428 1089 1089
q20 676 602 476 476
q21 5538 2505 2175 2175
q22 431 355 330 330
Total cold run time: 102972 ms
Total hot run time: 30963 ms
----- Round 2, with runtime_filter_mode=off -----
orders Doris NULL NULL 150000000 42 6422171781 NULL 22778155 NULL NULL 2023-12-26 18:27:23 2023-12-26 18:42:55 NULL utf-8 NULL NULL
============================================
q1 5106 5051 5083 5051
q2 q3 4094 4498 4007 4007
q4 1364 1465 1080 1080
q5 4535 4723 4680 4680
q6 244 215 178 178
q7 1910 1680 1541 1541
q8 2860 3070 2966 2966
q9 7980 7939 7658 7658
q10 4027 4178 3874 3874
q11 614 525 477 477
q12 615 700 528 528
q13 3018 3319 2470 2470
q14 304 311 295 295
q15 q16 774 811 747 747
q17 1395 1560 1468 1468
q18 7783 7183 6930 6930
q19 1284 1334 1259 1259
q20 2104 2347 2038 2038
q21 4969 4316 4150 4150
q22 516 445 422 422
Total cold run time: 55496 ms
Total hot run time: 51819 ms
```
</details>
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4184128405
# Cloud UT Coverage Report
Increment line coverage ` ` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/d31415c3d10e81478f835e3fc8b1cf0a15f97d38_d31415c3d10e81478f835e3fc8b1cf0a15f97d38_cloud/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/d31415c3d10e81478f835e3fc8b1cf0a15f97d38_d31415c3d10e81478f835e3fc8b1cf0a15f97d38_cloud/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 78.48% (1798/2291) |
| Line Coverage | 64.16% (32278/50310) |
| Region Coverage | 65.01% (16178/24886) |
| Branch Coverage | 55.49% (8625/15542) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4189832371
/review
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4184267531
# FE UT Coverage Report
Increment line coverage ` 100.00% (6/6)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_d31415c3d10e81478f835e3fc8b1cf0a15f97d38/fe_increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_d31415c3d10e81478f835e3fc8b1cf0a15f97d38/fe_report/index.html)
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3123449201
##########
be/src/exec/sort/sorter.cpp:
##########
@@ -86,14 +86,16 @@ Status MergeSorterState::build_merge_tree(const SortDescription& sort_descriptio
return Status::OK();
}
-Status MergeSorterState::merge_sort_read(doris::Block* block, int batch_size, bool* eos) {
+Status MergeSorterState::merge_sort_read(doris::Block* block, int batch_size, bool* eos,
+ size_t block_max_bytes) {
DCHECK(_sorted_blocks.empty());
DCHECK(unsorted_block()->empty());
- _merge_sort_read_impl(batch_size, block, eos);
+ _merge_sort_read_impl(batch_size, block, eos, block_max_bytes);
Review Comment:
这些变量的顺序,还是得注意一下,别老是往后加,这样看着代码不连续,比如eos 是返回值,应该放到最后的
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3123058148
##########
be/src/exec/operator/schema_scan_operator.cpp:
##########
@@ -242,7 +243,8 @@ Status SchemaScanOperatorX::get_block(RuntimeState* state, Block* block, bool* e
break;
}
- if (src_block.rows() >= state->batch_size()) {
+ const BlockBudget budget(state->batch_size(), state->preferred_block_size_bytes());
Review Comment:
也不需要了
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3123060318
##########
be/src/exec/operator/set_source_operator.h:
##########
@@ -51,6 +51,7 @@ class SetSourceLocalState final : public PipelineXLocalState<SetSharedState> {
RuntimeProfile::Counter* _get_data_from_hashtable_rows = nullptr;
IColumn::Selector _result_indexs;
bool _null_key_output = false;
+ size_t _estimated_row_bytes = 0;
Review Comment:
这个是不是也放到operator 里?
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3134969901
##########
be/src/storage/segment/segment.cpp:
##########
@@ -623,6 +624,22 @@ Status Segment::_create_column_meta(const SegmentFooterPB& footer) {
// Initialize column meta accessor which internally maintains uid -> column_ordinal mapping.
_column_meta_accessor = std::make_unique<ColumnMetaAccessor>();
RETURN_IF_ERROR(_column_meta_accessor->init(footer, _file_reader));
+
Review Comment:
**[High]** `_create_column_meta()` runs under `DorisCallOnce` on cached `Segment` instances, so gating this cache fill on `config::enable_adaptive_batch_size` makes the result depend on whichever query touched the segment first. If a segment is opened while the BE param is `false`, `_column_uid_to_raw_bytes` stays empty forever for that cached object. After a later `set_be_param('enable_adaptive_batch_size', 'true')`, `SegmentIterator` will start building predictors again, but every `column_raw_data_bytes()` lookup on the reused segment still returns `0` until cache eviction or restart.
This is a separate lifecycle bug from the existing config-gating comments: even after the feature is re-enabled correctly, cached segments never regain their metadata hints. Please populate `_column_uid_to_raw_bytes` unconditionally here (or lazily on first lookup) so dynamic config flips do not change behavior based on cache history.
##########
be/src/storage/segment/segment_iterator.cpp:
##########
@@ -367,6 +367,36 @@ Status SegmentIterator::_init_impl(const StorageReadOptions& opts) {
// Read options will not change, so that just resize here
_block_rowids.resize(_opts.block_row_max);
+ // Adaptive batch size: snapshot the initial row limit and create predictor if enabled.
+ _initial_block_row_max = _opts.block_row_max;
+ if (config::enable_adaptive_batch_size && _opts.preferred_block_size_bytes > 0) {
+ // Collect per-column raw byte metadata from the segment footer.
+ std::vector<AdaptiveBlockSizePredictor::ColumnMetadata> col_metadata;
+ uint32_t seg_rows = _segment->num_rows();
+ if (seg_rows > 0) {
+ const auto& ts = _segment->tablet_schema();
+ if (ts) {
+ for (ColumnId cid : _opts.adaptive_batch_output_columns) {
+ if (static_cast<size_t>(cid) < ts->num_columns()) {
+ int32_t uid = ts->column(cid).unique_id();
+ uint64_t raw_bytes = _segment->column_raw_data_bytes(uid);
Review Comment:
**[High]** This footer bootstrap is still using `raw_data_bytes / segment_rows` as if it were the runtime bytes-per-row of the returned block. That is not true for sparse nullable fixed-width columns: `raw_data_bytes` only counts non-null payload, but the read block still materializes the nested POD array plus the null map for every row. A `Nullable<Int32>` column with 1% non-nulls can therefore contribute almost nothing here even though the returned block still costs about `type_size + 1` bytes per row, so the first prediction stays near the 4096-row probe cap and can blow far past `preferred_block_size_bytes` before EWMA has any history.
This is distinct from the existing `origin_return_columns` thread: the column order can be correct and we still underestimate badly. `merger.cpp` already has to correct footer raw sizes with `max(raw_per_row, type_size)` plus the null-map byte; this path needs the same adjustment (or a shared helper) for the query-side bootstrap too.
##########
be/src/exec/sort/partition_sorter.cpp:
##########
@@ -145,12 +146,18 @@ Status PartitionSorter::_read_row_num(Block* output_block, bool* eos, int batch_
} else {
queue.remove_top();
}
+
+ // block_max_bytes == 0 means no byte budget.
Review Comment:
**[Medium]** The new byte-budget check is still bypassed by the `ROW_NUMBER` whole-block fast path a few lines above:
```cpp
if (current->impl->is_last(step) && current->impl->pos == 0) {
...
output_block->swap(*current->impl->block);
return Status::OK();
}
```
When `current_rows` covers the whole source block and `merged_rows == 0`, `_read_row_num()` returns that entire block before any `block_max_bytes` test runs. A partition whose first remaining sorted block is already wider than the target will still emit an oversized batch. This is distinct from the existing `vsorted_run_merger` comment: it is the partition-sort row-number fast path, not the merge-run reader.
The new test only checks `num_blocks > 1`, so it would still pass if the first returned block is larger than `preferred_block_size_bytes`. Please gate the fast path on the byte budget (or split that block before swapping) and add an assertion on per-block size.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4305392056
/review
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4206541913
# BE Regression && UT Coverage Report
Increment line coverage `84.10% (709/843)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_d8bccbf45af9d4a40148ae7511fb7eb2ccb34b36_merge/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_d8bccbf45af9d4a40148ae7511fb7eb2ccb34b36_merge/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 63.20% (23517/37213) |
| Line Coverage | 46.73% (241293/516369) |
| Region Coverage | 43.73% (197549/451784) |
| Branch Coverage | 45.06% (85723/190225) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r2964348197
##########
be/src/storage/segment/segment_iterator.cpp:
##########
@@ -2456,6 +2463,22 @@ Status SegmentIterator::next_batch(Block* block) {
_init_virtual_columns(block);
auto status = [&]() {
RETURN_IF_CATCH_EXCEPTION({
+ // Adaptive batch size: predict how many rows this batch should read.
+ if (_block_size_predictor) {
+ auto predicted = static_cast<uint32_t>(_block_size_predictor->predict_next_rows(
+ _initial_block_row_max, *_segment, _opts.adaptive_batch_output_columns));
+ _opts.block_row_max = std::min(predicted, _initial_block_row_max);
+ _opts.stats->adaptive_batch_size_predict_min_rows =
+ std::min(_opts.stats->adaptive_batch_size_predict_min_rows,
+ static_cast<int64_t>(predicted));
+ _opts.stats->adaptive_batch_size_predict_max_rows =
+ std::max(_opts.stats->adaptive_batch_size_predict_max_rows,
+ static_cast<int64_t>(predicted));
+ } else {
+ _opts.stats->adaptive_batch_size_predict_min_rows = _opts.block_row_max;
+ _opts.stats->adaptive_batch_size_predict_max_rows = _opts.block_row_max;
Review Comment:
**Minor (Low):** When `_block_size_predictor` is null (feature disabled), this `else` branch unconditionally overwrites `adaptive_batch_size_predict_min_rows` and `adaptive_batch_size_predict_max_rows` with `_opts.block_row_max` on **every** `next_batch()` call. Since `OlapReaderStatistics` is shared across segment iterators for the same scanner, and `adaptive_batch_size_predict_min_rows` is initialized to `INT64_MAX`, the first segment iterator's overwrite clobbers the sentinel.
This means the profile counters will show misleading values when the feature is disabled. Consider only setting these once, or guarding with a check (e.g., only set if currently `INT64_MAX` / `0`).
##########
be/test/storage/segment/adaptive_block_size_predictor_test.cpp:
##########
@@ -0,0 +1,544 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "storage/segment/adaptive_block_size_predictor.h"
+
+#include <gen_cpp/segment_v2.pb.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <vector>
+
+#include "common/config.h"
+#include "common/status.h"
+#include "core/block/block.h"
+#include "core/column/column_string.h"
+#include "core/column/column_vector.h"
+#include "core/data_type/data_type_number.h"
+#include "core/data_type/data_type_string.h"
+#include "storage/olap_common.h"
+#include "storage/segment/mock/mock_segment.h"
+#include "storage/tablet/tablet_schema.h"
+
+namespace doris {
+namespace segment_v2 {
+
+// ── helper functions ──────────────────────────────────────────────────────────
+
+// Build a Block with N rows, each containing a single Int32 column of the given value.
+static Block make_int32_block(size_t rows, int32_t value = 42) {
+ auto col = ColumnVector<TYPE_INT>::create();
+ col->reserve(rows);
+ for (size_t i = 0; i < rows; ++i) {
+ col->insert_value(value);
+ }
+ Block block;
+ block.insert({std::move(col), std::make_shared<DataTypeInt32>(), "c0"});
+ return block;
+}
+
+// Build a Block with N rows where each row holds a string of |str_len| bytes.
+static Block make_string_block(size_t rows, size_t str_len) {
+ auto col = ColumnString::create();
+ col->reserve(rows);
+ std::string s(str_len, 'x');
+ for (size_t i = 0; i < rows; ++i) {
+ col->insert_data(s.data(), s.size());
+ }
+ Block block;
+ block.insert({std::move(col), std::make_shared<DataTypeString>(), "c0"});
+ return block;
+}
+
+// ── AdaptiveBlockSizePredictorTest ───────────────────────────────────────────
+
+class AdaptiveBlockSizePredictorTest : public testing::Test {
+protected:
+ // 8 MB target, 1 MB per-column limit
+ static constexpr size_t kBlockBytes = 8 * 1024 * 1024;
+ static constexpr size_t kColBytes = 1 * 1024 * 1024;
+ static constexpr size_t kMaxRows = 4096;
+};
+
+// ── Test 1: no history ────────────────────────────────────────────────────────
+// Before any update, has_history == false and bytes_per_row == 0.
+// After the first update, has_history == true and bytes_per_row == block.bytes()/rows.
+TEST_F(AdaptiveBlockSizePredictorTest, NoHistoryReturnsMaxRows) {
+ AdaptiveBlockSizePredictor pred(kBlockBytes, kColBytes);
+
+ // Initially no history.
+ EXPECT_FALSE(pred.has_history_for_test());
+ EXPECT_DOUBLE_EQ(pred.bytes_per_row_for_test(), 0.0);
+
+ // After one update the first sample is stored directly (no EWMA blending).
+ Block blk = make_int32_block(100);
+ std::vector<ColumnId> cols = {0};
+ pred.update(blk, cols);
+
+ EXPECT_TRUE(pred.has_history_for_test());
+ double expected_bpr = static_cast<double>(blk.bytes()) / 100.0;
+ EXPECT_DOUBLE_EQ(pred.bytes_per_row_for_test(), expected_bpr);
+}
+
+// ── Test 2: EWMA convergence ──────────────────────────────────────────────────
+// When every update delivers the same sample, the EWMA stays exactly at that
+// value (0.9*v + 0.1*v == v for any v).
+TEST_F(AdaptiveBlockSizePredictorTest, EwmaConvergence) {
+ AdaptiveBlockSizePredictor pred(kBlockBytes, kColBytes);
+
+ std::vector<ColumnId> cols = {0};
+
+ // Compute expected bytes-per-row from an actual block so the test does not
+ // hard-code internal column memory layout assumptions.
+ Block probe = make_string_block(100, 100);
+ double expected_bpr = static_cast<double>(probe.bytes()) / 100.0;
+
+ // First update seeds the EWMA directly.
+ pred.update(probe, cols);
+ EXPECT_DOUBLE_EQ(pred.bytes_per_row_for_test(), expected_bpr);
+
+ // All subsequent updates carry the same sample → EWMA stays constant.
+ for (int i = 1; i < 50; ++i) {
+ Block blk = make_string_block(100, 100);
+ pred.update(blk, cols);
+ }
+ EXPECT_NEAR(pred.bytes_per_row_for_test(), expected_bpr, 0.01);
+}
+
+// ── Test 3: per-column constraint ────────────────────────────────────────────
+// After updates with a wide-column block the per-column limit must be tighter
+// than the total-bytes limit, verifying the predictor would apply it.
+TEST_F(AdaptiveBlockSizePredictorTest, PerColumnConstraint) {
+ AdaptiveBlockSizePredictor pred(kBlockBytes, kColBytes);
+
+ Block blk = make_string_block(100, 1024);
+ double first_bpr = static_cast<double>(blk.bytes()) / 100.0;
+ std::vector<ColumnId> cols = {0};
+ pred.update(blk, cols);
+
+ // After first update, col[0] estimate equals block bytes-per-row exactly.
+ EXPECT_NEAR(pred.col_bytes_per_row_for_test(0), first_bpr, 0.01);
+
+ // Second update with 200-row block of same row width → EWMA blends.
+ Block blk2 = make_string_block(200, 1024);
+ double second_bpr = static_cast<double>(blk2.bytes()) / 200.0;
+ pred.update(blk2, cols);
+
+ double col_bpr = pred.col_bytes_per_row_for_test(0);
+ double ewma_expected = 0.9 * first_bpr + 0.1 * second_bpr;
+ EXPECT_NEAR(col_bpr, ewma_expected, 1.0);
+
+ // The per-column row limit must be strictly smaller than the total row limit
+ // for a 1024 B/row column (1 MB col limit vs 8 MB block limit).
+ size_t col_limit = static_cast<size_t>(static_cast<double>(kColBytes) / col_bpr);
+ size_t total_limit =
+ static_cast<size_t>(static_cast<double>(kBlockBytes) / pred.bytes_per_row_for_test());
+ EXPECT_LT(col_limit, total_limit);
+}
+
+// ── Test 4: zero rows block is ignored ───────────────────────────────────────
+TEST_F(AdaptiveBlockSizePredictorTest, ZeroRowsBlockIgnored) {
+ AdaptiveBlockSizePredictor pred(kBlockBytes, kColBytes);
+
+ // update() with an empty block must be a no-op.
+ Block blk = make_int32_block(0);
+ std::vector<ColumnId> cols = {0};
+ pred.update(blk, cols);
+
+ EXPECT_FALSE(pred.has_history_for_test());
+ EXPECT_DOUBLE_EQ(pred.bytes_per_row_for_test(), 0.0);
+
+ // A subsequent real update must still work normally.
+ Block blk2 = make_int32_block(50);
+ pred.update(blk2, cols);
+ EXPECT_TRUE(pred.has_history_for_test());
+ double expected_bpr = static_cast<double>(blk2.bytes()) / 50.0;
+ EXPECT_DOUBLE_EQ(pred.bytes_per_row_for_test(), expected_bpr);
+}
+
+// ── Test 5: disabled when preferred_block_size_bytes == 0 ────────────────────
+// update() still records history; predict_next_rows() returns max_rows early
+// (requires a real Segment so that path is covered by integration tests).
+TEST_F(AdaptiveBlockSizePredictorTest, DisabledWhenBlockSizeIsZero) {
+ AdaptiveBlockSizePredictor pred(0, kColBytes);
+
+ Block blk = make_int32_block(1000);
+ std::vector<ColumnId> cols = {0};
+ pred.update(blk, cols);
+
+ // update() still records history even when budget == 0.
+ EXPECT_TRUE(pred.has_history_for_test());
+ EXPECT_GT(pred.bytes_per_row_for_test(), 0.0);
+}
+
+// ── Test 6: config flag disables predictor ────────────────────────────────────
+// When enable_adaptive_batch_size is false, no predictor should be created.
+// This is verified at the SegmentIterator level; here we just validate the
+// config default is true.
+TEST_F(AdaptiveBlockSizePredictorTest, ConfigDefaultEnabled) {
+ EXPECT_TRUE(config::enable_adaptive_batch_size);
+}
+
+// ── Test 7: multiple column sampling ─────────────────────────────────────────
+TEST_F(AdaptiveBlockSizePredictorTest, MultipleColumnSampling) {
+ AdaptiveBlockSizePredictor pred(kBlockBytes, kColBytes);
+
+ // Build a 2-column block: col0 = Int32 (4 B/row), col1 = String(100 B/row).
+ auto col0 = ColumnVector<TYPE_INT>::create();
+ auto col1 = ColumnString::create();
+ const size_t rows = 50;
+ std::string s(100, 'y');
+ for (size_t i = 0; i < rows; ++i) {
+ col0->insert_value(1);
+ col1->insert_data(s.data(), s.size());
+ }
+ Block blk;
+ blk.insert({std::move(col0), std::make_shared<DataTypeInt32>(), "c0"});
+ blk.insert({std::move(col1), std::make_shared<DataTypeString>(), "c1"});
+
+ std::vector<ColumnId> cols = {0, 1};
+ pred.update(blk, cols);
+
+ // Both columns must have per-column estimates after the first update.
+ double c0_bpr = pred.col_bytes_per_row_for_test(0);
+ double c1_bpr = pred.col_bytes_per_row_for_test(1);
+ EXPECT_GT(c0_bpr, 0.0);
+ EXPECT_GT(c1_bpr, 0.0);
+
+ // String column (100 B/row) must be much wider than Int32 column (4 B/row).
+ EXPECT_GT(c1_bpr, c0_bpr);
+
+ // Second update with same block → EWMA stays constant (same sample).
+ pred.update(blk, cols);
+
+ double expected_c0 = static_cast<double>(blk.get_by_position(0).column->byte_size()) / rows;
+ double expected_c1 = static_cast<double>(blk.get_by_position(1).column->byte_size()) / rows;
+ EXPECT_NEAR(pred.col_bytes_per_row_for_test(0), expected_c0, 0.01);
+ EXPECT_NEAR(pred.col_bytes_per_row_for_test(1), expected_c1, 0.01);
+}
+
+// ── predict_next_rows tests ──────────────────────────────────────────────────
+
+using ::testing::_;
+using ::testing::NiceMock;
+using ::testing::Return;
+
+// Helper: set up a MockSegment with tablet schema columns and a footer containing
+// ColumnMetaPB entries. Each entry in |col_specs| is {unique_id, uncompressed_bytes}.
+static NiceMock<MockSegment>* make_mock_segment(
+ uint32_t num_rows, const std::vector<std::pair<int32_t, uint64_t>>& col_specs) {
+ auto* seg = new NiceMock<MockSegment>();
+
+ // Set up num_rows mock.
+ ON_CALL(*seg, num_rows()).WillByDefault(Return(num_rows));
+
Review Comment:
**Bug (High):** `Segment::num_rows()` is **non-virtual** (declared as `uint32_t num_rows() const { return _num_rows; }` in `segment.h:119`). The `ON_CALL(*seg, num_rows()).WillByDefault(Return(num_rows))` configures gmock's virtual mock method, but when `predict_next_rows()` calls `segment.num_rows()` through a `Segment&` reference, the compiler statically dispatches to the base class's non-virtual method, bypassing the mock entirely.
The actual value returned will be whatever `_num_rows` was left at by the base `Segment` constructor — which does **not** initialize `_num_rows` in its member initializer list (see `segment.cpp:168-174`). This means tests like `PredictNoHistoryMetadataHint` are reading **indeterminate memory** (undefined behavior).
**Fix:** Since `MockSegment` is declared as a `friend` of `Segment`, you can directly set the member:
```cpp
seg->_num_rows = num_rows;
```
instead of (or in addition to) the `ON_CALL` mock.
##########
be/src/exec/scan/olap_scanner.cpp:
##########
@@ -840,6 +844,19 @@ void OlapScanner::_collect_profile_before_close() {
COUNTER_UPDATE(local_state->_variant_doc_value_column_iter_count,
stats.variant_doc_value_column_iter_count);
+ if (stats.adaptive_batch_size_predict_max_rows > 0) {
+ auto cur_min = local_state->_adaptive_batch_predict_min_rows_counter->value();
+ if (cur_min == 0 || stats.adaptive_batch_size_predict_min_rows < cur_min) {
Review Comment:
**Minor (Low):** This read-check-store pattern on shared `RuntimeProfile::Counter` is a classic TOCTOU race. Multiple scanners call `_collect_profile_before_close` concurrently on the same `local_state` counters. Thread A can read a stale `cur_min`, pass the check, and overwrite thread B's correct value.
Since these are display-only profile counters, this is benign — the worst outcome is a slightly inaccurate min/max in the query profile. But consider documenting this or using `COUNTER_UPDATE` with atomic min/max if `RuntimeProfile::Counter` supports it.
##########
regression-test/suites/query_p0/adaptive_batch_size/adaptive_batch_size.groovy:
##########
@@ -0,0 +1,220 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// Regression tests for the Adaptive Batch Size feature.
+//
+// Design notes:
+// - Each case runs the same query with the feature enabled and disabled, and
+// asserts that results are identical (correctness check).
+// - We do NOT directly assert internal block byte sizes, because the storage
+// layer does not expose them via SQL result columns. Correctness is the
+// primary requirement; performance / memory reduction is verified manually
+// or via profile counters in a separate benchmark.
+
+suite("adaptive_batch_size") {
+
+ // ── helpers ────────────────────────────────────────────────────────────────
+
+ def set_adaptive = { enabled ->
+ // preferred_block_size_bytes controls the feature end-to-end.
+ // Setting it to a very small value (e.g. 1 byte) forces the predictor to
+ // return row count = 1 every time, which is a good stress test.
+ if (enabled) {
+ sql "set preferred_block_size_bytes = 8388608" // 8 MB (default)
+ sql "set batch_size = 65535"
+ sql "set preferred_max_column_in_block_size_bytes = 1048576" // 1 MB
+ } else {
+ // Setting to 0 disables the byte-limit path at the accumulation layer.
+ sql "set preferred_block_size_bytes = 0"
+ sql "set batch_size = 4096"
+ sql "set preferred_max_column_in_block_size_bytes = 0"
+ }
+ }
+
+ // ── Test 1: wide table (VARCHAR columns) ──────────────────────────────────
+ // Each row is ~10 KB; with 4096 rows that is ~40 MB/batch which OOM-risks.
+ // With adaptive=on the batch is trimmed to ~8 MB worth of rows.
+
+ sql "drop table if exists abs_wide_table"
+ sql """
+ create table abs_wide_table (
+ id int not null,
+ c1 varchar(4096),
+ c2 varchar(4096),
+ c3 varchar(4096)
+ )
+ ENGINE=OLAP
+ DUPLICATE KEY(id)
+ DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES ("replication_allocation" = "tag.location.default: 1")
+ """
+
+ // Insert 1000 rows with ~3 KB data each.
+ def wide_rows = (1..1000).collect { i ->
+ "(${i}, '${('a' * 1000)}', '${('b' * 1000)}', '${('c' * 1000)}')"
+ }
+ sql "insert into abs_wide_table values ${wide_rows.join(',')}"
+
+ // Run query with adaptive enabled and collect result.
+ set_adaptive(true)
+ def res_enabled = sql "select id, length(c1) as l1, length(c2) as l2, length(c3) as l3 from abs_wide_table order by 1, 2, 3, 4"
+
+ qt_wide "select id, length(c1) as l1, length(c2) as l2, length(c3) as l3 from abs_wide_table order by 1, 2, 3, 4 limit 50"
+
Review Comment:
**Standards violation (Medium):** Per regression test standards, use `order_qt_` prefix instead of `qt_` to ensure deterministic ordered output. This applies to all query tags in this file (`qt_wide`, `qt_narrow`, `qt_agg`, `qt_unique`, `qt_flag`).
While some of these queries have explicit `ORDER BY` or return single rows, the standard convention is to consistently use `order_qt_` prefix.
##########
regression-test/suites/query_p0/adaptive_batch_size/adaptive_batch_size.groovy:
##########
@@ -0,0 +1,220 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// Regression tests for the Adaptive Batch Size feature.
+//
+// Design notes:
+// - Each case runs the same query with the feature enabled and disabled, and
+// asserts that results are identical (correctness check).
+// - We do NOT directly assert internal block byte sizes, because the storage
+// layer does not expose them via SQL result columns. Correctness is the
+// primary requirement; performance / memory reduction is verified manually
+// or via profile counters in a separate benchmark.
+
+suite("adaptive_batch_size") {
+
+ // ── helpers ────────────────────────────────────────────────────────────────
+
+ def set_adaptive = { enabled ->
+ // preferred_block_size_bytes controls the feature end-to-end.
+ // Setting it to a very small value (e.g. 1 byte) forces the predictor to
+ // return row count = 1 every time, which is a good stress test.
+ if (enabled) {
+ sql "set preferred_block_size_bytes = 8388608" // 8 MB (default)
+ sql "set batch_size = 65535"
+ sql "set preferred_max_column_in_block_size_bytes = 1048576" // 1 MB
+ } else {
+ // Setting to 0 disables the byte-limit path at the accumulation layer.
+ sql "set preferred_block_size_bytes = 0"
+ sql "set batch_size = 4096"
+ sql "set preferred_max_column_in_block_size_bytes = 0"
+ }
+ }
+
+ // ── Test 1: wide table (VARCHAR columns) ──────────────────────────────────
+ // Each row is ~10 KB; with 4096 rows that is ~40 MB/batch which OOM-risks.
+ // With adaptive=on the batch is trimmed to ~8 MB worth of rows.
+
+ sql "drop table if exists abs_wide_table"
+ sql """
+ create table abs_wide_table (
+ id int not null,
+ c1 varchar(4096),
+ c2 varchar(4096),
+ c3 varchar(4096)
+ )
+ ENGINE=OLAP
+ DUPLICATE KEY(id)
+ DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES ("replication_allocation" = "tag.location.default: 1")
+ """
+
+ // Insert 1000 rows with ~3 KB data each.
+ def wide_rows = (1..1000).collect { i ->
+ "(${i}, '${('a' * 1000)}', '${('b' * 1000)}', '${('c' * 1000)}')"
+ }
+ sql "insert into abs_wide_table values ${wide_rows.join(',')}"
+
+ // Run query with adaptive enabled and collect result.
+ set_adaptive(true)
+ def res_enabled = sql "select id, length(c1) as l1, length(c2) as l2, length(c3) as l3 from abs_wide_table order by 1, 2, 3, 4"
+
+ qt_wide "select id, length(c1) as l1, length(c2) as l2, length(c3) as l3 from abs_wide_table order by 1, 2, 3, 4 limit 50"
+
+ // Run query with adaptive disabled and collect result.
+ set_adaptive(false)
+ def res_disabled = sql "select id, length(c1) as l1, length(c2) as l2, length(c3) as l3 from abs_wide_table order by 1, 2, 3, 4"
+
+ // Results must be identical.
+ assertEquals(res_enabled.size(), res_disabled.size())
+ for (int i = 0; i < res_enabled.size(); i++) {
+ assertEquals(res_enabled[i].toString(), res_disabled[i].toString())
+ }
+
+ // sql "drop table abs_wide_table"
+
+
+ // ── Test 2: narrow table (INT columns) ───────────────────────────────────
+ // Rows are ~12 bytes each; with adaptive=on the predictor should converge
+ // toward returning close to max_rows (batch is still row-limited).
+
+ sql "drop table if exists abs_narrow_table"
+ sql """
Review Comment:
**Standards violation (Medium):** Per regression test standards: *"After completing tests, do not drop tables; instead drop tables before using them in tests, to preserve the environment for debugging."*
This `drop table` after use (and similar ones for `abs_agg_table`, `abs_unique_table`, `abs_flag_table`) should be removed. The `drop table if exists` before `CREATE TABLE` at the beginning of each test case is the correct pattern (and is already present).
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4094762857
run buildall
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4095703540
# BE UT Coverage Report
Increment line coverage ` ` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/daebf3f9ccd3a062258f75fb387de4d89c7ecce6_daebf3f9ccd3a062258f75fb387de4d89c7ecce6/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/daebf3f9ccd3a062258f75fb387de4d89c7ecce6_daebf3f9ccd3a062258f75fb387de4d89c7ecce6/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 52.71% (19793/37554) |
| Line Coverage | 36.23% (184854/510166) |
| Region Coverage | 32.50% (143146/440485) |
| Branch Coverage | 33.66% (62584/185927) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4096128541
/review
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4105570879
# BE Regression && UT Coverage Report
Increment line coverage `100% (0/0)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_ae43fe96d6a20040c16d54f6ee49141576a11c2a_merge/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_ae43fe96d6a20040c16d54f6ee49141576a11c2a_merge/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 73.19% (26941/36811) |
| Line Coverage | 56.68% (288586/509150) |
| Region Coverage | 53.99% (240339/445189) |
| Branch Coverage | 55.66% (103977/186813) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3037567427
##########
be/src/runtime/runtime_state.h:
##########
@@ -138,7 +138,40 @@ class RuntimeState {
const DescriptorTbl& desc_tbl() const { return *_desc_tbl; }
void set_desc_tbl(const DescriptorTbl* desc_tbl) { _desc_tbl = desc_tbl; }
+
+ MOCK_FUNCTION int block_max_rows() const {
+ return config::enable_adaptive_batch_size
+ ? std::max(_query_options.batch_size, int(preferred_block_size_rows()))
+ : _query_options.batch_size;
Review Comment:
block_max_rows() casts preferred_block_size_rows() (size_t) to int inside std::max. Since preferred_block_size_rows is user-controlled (session var forwarded via thrift) and has no obvious upper-bound enforcement here, this cast can overflow/underflow and produce an incorrect (possibly negative) row limit. Consider clamping preferred_block_size_rows to INT_MAX (or changing block_max_rows() to return size_t) before casting/combining with batch_size.
##########
gensrc/thrift/PaloInternalService.thrift:
##########
@@ -473,6 +473,18 @@ struct TQueryOptions {
210: optional double max_scan_mem_ratio = 0.3;
211: optional bool enable_adaptive_scan = false;
+
+ // Adaptive batch size: target output block size in bytes. 0 means disabled (fixed row count only).
+ // Default 8MB. Sent by FE session variable preferred_block_size_bytes.
+ 212: optional i64 preferred_block_size_bytes = 8388608
+
+ // Per-column byte limit for adaptive batch size. 0 means no per-column limit. Default 1MB.
+ 213: optional i64 preferred_max_column_in_block_size_bytes = 1048576
+
+ // Adaptive batch size: target output block row count limit. Default 65535.
+ // Sent by FE session variable preferred_block_size_rows.
+ 214: optional i64 preferred_block_size_rows = 65535
Review Comment:
The PR description mentions adding “Thrift fields 204/205 for FE→BE propagation”, but the new adaptive batch size fields added here are 212/213/214 (204/205 are already used for spill_*). Please update the PR description (or the field IDs if that was the intent) to avoid confusion for reviewers and future maintainers.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4175052595
# BE Regression && UT Coverage Report
Increment line coverage `100% (0/0)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_eee985b7d8c909cb70ddac3af54a70d35d76ba9a_merge/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_eee985b7d8c909cb70ddac3af54a70d35d76ba9a_merge/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 73.68% (27354/37125) |
| Line Coverage | 57.25% (294304/514110) |
| Region Coverage | 54.33% (244503/450043) |
| Branch Coverage | 56.16% (106269/189226) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4213502825
# BE Regression && UT Coverage Report
Increment line coverage `88.76% (758/854)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_7d63a11f9e4873bfd109d850bfda4b15d64275c6_merge/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_7d63a11f9e4873bfd109d850bfda4b15d64275c6_merge/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 73.69% (27439/37236) |
| Line Coverage | 57.38% (296526/516784) |
| Region Coverage | 54.60% (246949/452305) |
| Branch Coverage | 56.26% (107130/190405) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "velodb-robyang (via GitHub)" <gi...@apache.org>.
velodb-robyang commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3071372133
##########
fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java:
##########
@@ -1289,6 +1293,26 @@ public void checkQuerySlotCount(String slotCnt) {
@VarAttrDef.VarAttr(name = BROKER_LOAD_BATCH_SIZE, fuzzy = true, checker = "checkBatchSize")
public int brokerLoadBatchSize = 16352;
+ // Target output block size in bytes for adaptive batch size. 0 disables the byte limit.
+ // Default 8MB. Passed to storage layer to control how many rows each SegmentIterator chunk
+ // should contain so the final Block stays near this size.
+ @VarAttrDef.VarAttr(name = PREFERRED_BLOCK_SIZE_BYTES, needForward = true,
+ description = {"目标输出 Block 字节数上限,自适应 batch size 功能使用,0 表示不限制,默认 8MB",
+ "Target output block size in bytes for adaptive batch size. 0 disables the limit. Default 8MB."})
+ public long preferredBlockSizeBytes = 8388608L; // 8MB
Review Comment:
别用0 表示不限制,这种条件到BE 上得一堆判断是否小于0 的,可以直接用比较大的值。
这里得加一些check 条件,比如 最小1MB,最大 512MB 这样的
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4243155892
/review
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3123133983
##########
be/src/runtime/runtime_state.h:
##########
@@ -138,7 +138,41 @@ class RuntimeState {
const DescriptorTbl& desc_tbl() const { return *_desc_tbl; }
void set_desc_tbl(const DescriptorTbl* desc_tbl) { _desc_tbl = desc_tbl; }
- MOCK_FUNCTION int batch_size() const { return _query_options.batch_size; }
+
+ // Row-count limit for output blocks (default 65535, range [1, 65535]).
+ // Consistent with SessionVariable.batchSize on FE side.
+ MOCK_FUNCTION int batch_size() const {
+ static constexpr int kDefault = 65535;
+ auto v = _query_options.batch_size;
+ return std::min(std::max(1, v), kDefault);
+ }
+
+ // Target byte budget per output block (default 8MB).
+ // FE validates the range [1MB, 512MB] in SessionVariable; BE trusts that
+ // but applies a default when the field is unset.
+ MOCK_FUNCTION size_t preferred_block_size_bytes() const {
+ static constexpr int64_t kDefault = 8388608L; // 8MB
+ static constexpr int64_t kMax = 536870912L; // 512MB
+ static constexpr int64_t kMin = 1048576L; // 1MB
+ if (_query_options.__isset.preferred_block_size_bytes) [[likely]] {
+ return std::max(kMin, std::min(_query_options.preferred_block_size_bytes, kMax));
Review Comment:
Blocking: this accessor is now the byte-budget source for a lot of operator/sort/exchange paths, but it ignores `config::enable_adaptive_batch_size`. Storage/FileScanner gate on the config, yet unchanged consumers such as `FullSorter::get_next`, `ShuffleExchanger::get_block`, `UnionSinkOperatorX`, `ESScanner`, and the `BlockBudget` users still call `state->preferred_block_size_bytes()` directly. So `set_be_param('enable_adaptive_batch_size', 'false')` only disables part of the feature; those paths will continue splitting on bytes. The config needs to be enforced here or at every caller.
##########
fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java:
##########
@@ -1294,14 +1297,37 @@ public void checkQuerySlotCount(String slotCnt) {
@VarAttrDef.VarAttr(name = HAVE_QUERY_CACHE, flag = VarAttrDef.READ_ONLY)
public boolean haveQueryCache = false;
- // 4096 minus 16 + 16 bytes padding that in padding pod array
+ // Maximum rows per output block. Default 65535 (the maximum allowed value).
@VarAttrDef.VarAttr(name = BATCH_SIZE, fuzzy = true, checker = "checkBatchSize", needForward = true)
- public int batchSize = 8160;
Review Comment:
Blocking: this repurposes the longstanding `batch_size` default into the adaptive row ceiling instead of introducing the separate `preferred_block_size_rows` knob described in the PR. `toThrift()` still forwards `batch_size` as the normal BE row cap, so sessions that never touch adaptive sizing now default to `65535` rows everywhere, including fallback/non-adaptive paths (`TabletReader::batch_max_rows()` when the feature is off, schema scanners, result buffers, sink writers, etc.). That means `enable_adaptive_batch_size=false` no longer preserves the old fixed-row behavior; it silently makes fixed batches much larger. This needs a separate adaptive-only field instead of changing the semantics of the existing `batch_size` setting.
##########
fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java:
##########
@@ -6116,6 +6144,30 @@ public void checkAiContextWindowSize(String value) throws Exception {
checkFieldLongValue(AI_CONTEXT_WINDOW_SIZE, 1, value);
}
+ private static final long PREFERRED_BLOCK_SIZE_BYTES_MIN = 1048576L; // 1MB
+ private static final long PREFERRED_BLOCK_SIZE_BYTES_MAX = 536870912L; // 512MB
+
Review Comment:
Blocking: the new user/wire contract says `preferred_block_size_bytes = 0` disables adaptive sizing (the thrift comments and the PR release note both say that), but this validator rejects `0`, and BE currently clamps a received `0` to `1MB` instead of honoring the sentinel. So the documented disable path cannot work end to end. The same mismatch exists for `preferred_max_column_in_block_size_bytes` (`0` is documented as 'no per-column limit', but is rejected/clamped). Either support the sentinel everywhere or stop advertising it.
##########
be/src/storage/rowset/beta_rowset_reader.cpp:
##########
@@ -95,7 +95,20 @@ Status BetaRowsetReader::get_segment_iterators(RowsetReaderContext* read_context
RETURN_IF_ERROR(_rowset->load());
// convert RowsetReaderContext to StorageReadOptions
- _read_options.block_row_max = read_context->batch_size;
+ // When adaptive batch size is enabled and the byte budget is active, use the larger
+ // preferred_block_size_rows so the predictor can grow beyond the legacy batch_size.
+ if (config::enable_adaptive_batch_size && read_context->preferred_block_size_bytes > 0 &&
+ read_context->preferred_block_size_rows > 0) {
+ _read_options.block_row_max = cast_set<uint32_t>(read_context->preferred_block_size_rows);
+ } else {
+ _read_options.block_row_max = read_context->batch_size;
+ }
+ _read_options.preferred_block_size_bytes = read_context->preferred_block_size_bytes;
+ _read_options.preferred_block_size_rows = read_context->preferred_block_size_rows;
+ _read_options.preferred_max_col_bytes = read_context->preferred_max_col_bytes;
+ if (read_context->origin_return_columns != nullptr) {
+ _read_options.adaptive_batch_output_columns = *read_context->origin_return_columns;
Review Comment:
Blocking: `AdaptiveBlockSizePredictor::update()` assumes `output_columns[i]` matches the block column at position `i`, but the blocks coming out of rowset readers on non-direct AGG/UNIQUE paths are still laid out by `read_context->return_columns` (expanded key/sequence set), not `origin_return_columns`. Passing the origin list here mislabels per-column samples whenever storage adds key/sequence columns before a requested value column. For example, `SELECT v FROM agg_tbl` will account position 0 (the key column in the rowset block) as `v`, so the per-column cap can be enforced on the wrong cid. Either keep this vector aligned with the expanded block shape or move the predictor update after BlockReader has projected back to the origin columns.
##########
be/src/exec/scan/file_scanner.cpp:
##########
@@ -482,6 +602,10 @@ Status FileScanner::_get_block_wrapped(RuntimeState* state, Block* block, bool*
// For query job, simply set _src_block_ptr to block.
size_t read_rows = 0;
RETURN_IF_ERROR(_init_src_block(block));
+
Review Comment:
High: this runs for both load and query scans, but only the load path ever calls `_update_adaptive_batch_size_before_truncate()` / `_update_adaptive_batch_size_after_truncate()`. `_process_src_block_after_read_for_query()` still just truncates and returns, so `_block_size_predictor` never learns on Parquet/ORC/JNI/CSV/JSON query scans. Since `predict_next_rows()` clamps the no-history case to `ADAPTIVE_BATCH_INITIAL_PROBE_ROWS`, those queries can stay pinned at 32 rows per read for the whole file. That's a significant throughput regression rather than an adaptive policy.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3122479630
##########
be/src/exec/operator/join/process_hash_table_probe.h:
##########
@@ -40,7 +40,8 @@ using ConstNullMapPtr = const NullMap*;
template <int JoinOpType>
struct ProcessHashTableProbe {
- ProcessHashTableProbe(HashJoinProbeLocalState* parent, int batch_size);
+ ProcessHashTableProbe(HashJoinProbeLocalState* parent, int batch_size,
+ size_t block_max_bytes = 0);
Review Comment:
why has default value?
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4175304603
# BE Regression && UT Coverage Report
Increment line coverage `88.89% (368/414)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_eee985b7d8c909cb70ddac3af54a70d35d76ba9a_merge/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_eee985b7d8c909cb70ddac3af54a70d35d76ba9a_merge/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 73.68% (27354/37125) |
| Line Coverage | 57.25% (294304/514110) |
| Region Coverage | 54.33% (244503/450043) |
| Branch Coverage | 56.16% (106269/189226) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "github-actions[bot] (via GitHub) via commits" <co...@doris.apache.org>.
github-actions[bot] closed pull request #61535: [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control
URL: https://github.com/apache/doris/pull/61535
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4095269476
<details>
<summary>TPC-DS: <b>Total hot run time: 173281 ms</b></summary>
```
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit daebf3f9ccd3a062258f75fb387de4d89c7ecce6, data reload: false
query5 4316 650 495 495
query6 335 228 226 226
query7 4249 527 281 281
query8 342 255 234 234
query9 9250 5274 5237 5237
query10 501 420 341 341
query11 7061 5150 4884 4884
query12 188 131 122 122
query13 1289 479 367 367
query14 5878 3947 3605 3605
query14_1 2995 3015 3003 3003
query15 209 200 180 180
query16 996 490 437 437
query17 916 757 662 662
query18 2436 488 357 357
query19 237 235 192 192
query20 136 131 129 129
query21 231 132 117 117
query22 13184 13369 13319 13319
query23 15963 15577 15361 15361
query23_1 15545 15514 15426 15426
query24 7340 1779 1334 1334
query24_1 1316 1310 1329 1310
query25 553 470 428 428
query26 1240 279 171 171
query27 2781 501 324 324
query28 4664 2704 2662 2662
query29 868 599 510 510
query30 312 234 193 193
query31 1053 965 882 882
query32 86 80 75 75
query33 513 346 288 288
query34 930 938 594 594
query35 678 692 606 606
query36 1120 1159 956 956
query37 138 104 86 86
query38 2973 3021 2889 2889
query39 869 830 814 814
query39_1 793 788 803 788
query40 233 153 146 146
query41 69 63 63 63
query42 273 265 271 265
query43 258 264 227 227
query44
query45 197 196 185 185
query46 967 1071 672 672
query47 2165 2187 2105 2105
query48 345 345 250 250
query49 646 469 395 395
query50 744 288 230 230
query51 4105 4090 4093 4090
query52 269 266 263 263
query53 314 353 309 309
query54 326 276 308 276
query55 92 87 89 87
query56 328 344 309 309
query57 1959 1825 1706 1706
query58 287 275 278 275
query59 2881 3060 2789 2789
query60 353 351 327 327
query61 158 158 186 158
query62 628 598 548 548
query63 323 304 287 287
query64 5107 1301 1007 1007
query65
query66 1474 486 372 372
query67 24257 24455 24139 24139
query68
query69 476 333 304 304
query70 937 1051 1003 1003
query71 350 310 306 306
query72 2814 2677 2423 2423
query73 597 601 374 374
query74 9644 9612 9419 9419
query75 3028 2901 2560 2560
query76 2342 1169 855 855
query77 404 400 318 318
query78 11103 11115 10530 10530
query79 1204 824 615 615
query80 729 648 556 556
query81 480 262 227 227
query82 1303 155 131 131
query83 353 274 263 263
query84 299 126 114 114
query85 872 518 480 480
query86 395 304 291 291
query87 3158 3122 3026 3026
query88 4341 3346 3346 3346
query89 460 390 353 353
query90 1969 208 196 196
query91 174 166 147 147
query92 78 80 77 77
query93 1020 933 594 594
query94 461 331 307 307
query95 605 358 340 340
query96 726 564 266 266
query97 2475 2502 2469 2469
query98 259 227 222 222
query99 1027 1034 914 914
Total cold run time: 251402 ms
Total hot run time: 173281 ms
```
</details>
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4096816912
<details>
<summary>TPC-DS: <b>Total hot run time: 169237 ms</b></summary>
```
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit f404b067c8aa7622413fd7d269235aaccd195121, data reload: false
query5 4328 658 511 511
query6 339 234 209 209
query7 4225 503 273 273
query8 357 255 238 238
query9 8698 2777 2790 2777
query10 514 391 349 349
query11 6983 5116 4889 4889
query12 195 133 132 132
query13 1279 462 362 362
query14 5762 3839 3592 3592
query14_1 2908 2900 2917 2900
query15 211 188 176 176
query16 972 413 452 413
query17 879 712 607 607
query18 2439 459 341 341
query19 231 225 194 194
query20 138 127 128 127
query21 214 135 114 114
query22 13266 14164 14916 14164
query23 16166 15714 15584 15584
query23_1 15849 15782 15826 15782
query24 7273 1668 1244 1244
query24_1 1243 1251 1242 1242
query25 562 469 410 410
query26 1255 274 154 154
query27 2768 507 305 305
query28 4477 1897 1859 1859
query29 841 566 499 499
query30 309 216 196 196
query31 1008 948 876 876
query32 88 74 70 70
query33 495 349 287 287
query34 913 903 543 543
query35 644 686 620 620
query36 1087 1108 927 927
query37 137 96 84 84
query38 2946 2916 2867 2867
query39 856 827 804 804
query39_1 786 786 796 786
query40 245 158 141 141
query41 63 60 58 58
query42 263 257 260 257
query43 248 274 257 257
query44
query45 200 196 187 187
query46 945 1019 633 633
query47 2099 2123 2026 2026
query48 319 322 231 231
query49 625 464 400 400
query50 717 289 224 224
query51 4164 4042 4004 4004
query52 266 266 257 257
query53 307 344 291 291
query54 315 285 273 273
query55 99 90 90 90
query56 320 328 317 317
query57 1906 1855 1658 1658
query58 294 287 272 272
query59 2822 2956 2743 2743
query60 363 344 335 335
query61 152 154 155 154
query62 631 584 529 529
query63 324 296 287 287
query64 5029 1298 1058 1058
query65
query66 1488 493 398 398
query67 24209 24298 24147 24147
query68
query69 422 316 297 297
query70 970 988 931 931
query71 366 322 306 306
query72 3170 2883 2363 2363
query73 562 573 332 332
query74 9597 9540 9387 9387
query75 2892 2778 2490 2490
query76 2292 1098 728 728
query77 378 415 330 330
query78 10970 11041 10476 10476
query79 3115 781 580 580
query80 1748 655 548 548
query81 576 268 226 226
query82 978 157 122 122
query83 339 269 255 255
query84 302 118 110 110
query85 948 500 477 477
query86 499 307 302 302
query87 3144 3130 3005 3005
query88 3685 2684 2686 2684
query89 435 386 360 360
query90 2024 187 189 187
query91 181 166 138 138
query92 81 80 71 71
query93 1816 846 505 505
query94 650 332 281 281
query95 594 415 326 326
query96 654 540 233 233
query97 2469 2501 2423 2423
query98 250 221 218 218
query99 1018 1005 931 931
Total cold run time: 253570 ms
Total hot run time: 169237 ms
```
</details>
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4101974220
# BE Regression && UT Coverage Report
Increment line coverage `100% (0/0)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_ae43fe96d6a20040c16d54f6ee49141576a11c2a_merge/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_ae43fe96d6a20040c16d54f6ee49141576a11c2a_merge/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 73.18% (26940/36811) |
| Line Coverage | 56.68% (288581/509150) |
| Region Coverage | 53.98% (240333/445189) |
| Branch Coverage | 55.66% (103972/186813) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4174147449
/review
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4184000257
run buildall
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4133467936
run buildall
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "velodb-robyang (via GitHub)" <gi...@apache.org>.
velodb-robyang commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3071360733
##########
be/src/runtime/runtime_state.h:
##########
@@ -138,7 +138,42 @@ class RuntimeState {
const DescriptorTbl& desc_tbl() const { return *_desc_tbl; }
void set_desc_tbl(const DescriptorTbl* desc_tbl) { _desc_tbl = desc_tbl; }
+
+ MOCK_FUNCTION int block_max_rows() const {
+ if (config::enable_adaptive_batch_size && preferred_block_size_bytes() > 0) {
+ auto rows = preferred_block_size_rows();
+ return static_cast<int>(std::min(rows, static_cast<size_t>(INT32_MAX)));
+ }
+ return _query_options.batch_size;
+ }
+
+ MOCK_FUNCTION size_t block_max_bytes() const {
Review Comment:
这个函数跟preferred_block_size_bytes 有啥区别啊
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-6330383184
We're closing this PR because it hasn't been updated in a while.
This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
If you'd like to revive this PR, please reopen it and feel free a maintainer to remove the Stale tag!
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4200374169
# FE UT Coverage Report
Increment line coverage ` 100.00% (6/6)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_f7f15913424959d5a9e7632178783172243b61b9/fe_increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_f7f15913424959d5a9e7632178783172243b61b9/fe_report/index.html)
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4205617136
run buildall
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3078811534
##########
be/src/format/json/new_json_reader.cpp:
##########
@@ -196,20 +196,21 @@ Status NewJsonReader::init_reader(
return Status::OK();
}
+void NewJsonReader::set_batch_size(size_t batch_size) {
+ _batch_size = batch_size;
+}
+
Status NewJsonReader::get_next_block(Block* block, size_t* read_rows, bool* eof) {
if (_reader_eof) {
*eof = true;
return Status::OK();
}
- const int batch_size = std::max(_state->batch_size(), (int)_MIN_BATCH_SIZE);
- const int64_t max_block_bytes =
- (_state->query_type() == TQueryType::LOAD && config::load_reader_max_block_bytes > 0)
- ? config::load_reader_max_block_bytes
- : 0;
+ const auto batch_size = _state->batch_size();
+ const auto max_block_bytes = _state->preferred_block_size_bytes();
Review Comment:
Same issue as the CSV reader: `FileScanner` updates this reader through `set_batch_size(...)`, but `get_next_block()` still uses `_state->batch_size()` as its row cap. So the new predictor does not actually control JSON batch size, and the adaptive path for wide/narrow JSON files is effectively bypassed here.
##########
be/src/format/csv/csv_reader.cpp:
##########
@@ -307,26 +308,25 @@ Status CsvReader::init_reader(bool is_load) {
return Status::OK();
}
+void CsvReader::set_batch_size(size_t batch_size) {
+ _batch_size = batch_size;
+}
+
// !FIXME: Here we should use MutableBlock
Status CsvReader::get_next_block(Block* block, size_t* read_rows, bool* eof) {
if (_line_reader_eof) {
*eof = true;
return Status::OK();
}
- const int batch_size = std::max(_state->batch_size(), (int)_MIN_BATCH_SIZE);
- const int64_t max_block_bytes =
- (_state->query_type() == TQueryType::LOAD && config::load_reader_max_block_bytes > 0)
- ? config::load_reader_max_block_bytes
- : 0;
+ const size_t batch_size = _state->batch_size();
+ const auto max_block_bytes = _state->preferred_block_size_bytes();
Review Comment:
`FileScanner` now calls `set_batch_size(_predict_reader_batch_rows())`, but this loop still caps on `_state->batch_size()` instead of the reader-local `_batch_size`. As a result the EWMA predictor never actually changes the row count for CSV scans; the reader only uses the sampled byte cutoff after rows have already been appended. That leaves adaptive batch sizing ineffective for CSV inputs.
##########
be/src/runtime/runtime_state.h:
##########
@@ -138,7 +138,38 @@ class RuntimeState {
const DescriptorTbl& desc_tbl() const { return *_desc_tbl; }
void set_desc_tbl(const DescriptorTbl* desc_tbl) { _desc_tbl = desc_tbl; }
- MOCK_FUNCTION int batch_size() const { return _query_options.batch_size; }
+
+ // Row-count limit for output blocks (default 65535, range [1, 65535]).
+ // Consistent with SessionVariable.batchSize on FE side.
+ MOCK_FUNCTION int batch_size() const {
+ static constexpr int kDefault = 65535;
+ auto v = _query_options.batch_size;
+ return std::min(std::max(1, v), kDefault);
+ }
+
+ // Target byte budget per output block (default 8MB).
+ // FE validates the range [1MB, 512MB] in SessionVariable; BE trusts that
+ // but applies a default when the field is unset or zero.
+ MOCK_FUNCTION size_t preferred_block_size_bytes() const {
+ static constexpr int64_t kDefault = 8388608L; // 8MB
+ if (_query_options.__isset.preferred_block_size_bytes &&
+ _query_options.preferred_block_size_bytes > 0) {
+ return _query_options.preferred_block_size_bytes;
+ }
+ return kDefault;
+ }
Review Comment:
`preferred_block_size_bytes = 0` is documented as the way to disable adaptive sizing, but this accessor maps both `unset` and explicit `0` back to the 8MB default. That means every caller still sees byte-budget mode as enabled, and FE also rejects `0` in `checkPreferredBlockSizeBytes()`. Concretely, the advertised `SET preferred_block_size_bytes = 0` opt-out cannot work end to end. Please preserve an explicit zero here (and allow FE to send it) if zero is meant to disable the feature.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3123414266
##########
be/src/exec/exchange/vdata_stream_sender.cpp:
##########
@@ -288,7 +288,10 @@ Status Channel::close(RuntimeState* state) {
}
BlockSerializer::BlockSerializer(ExchangeSinkLocalState* parent, bool is_local)
- : _parent(parent), _is_local(is_local), _batch_size(parent->state()->batch_size()) {}
+ : _parent(parent),
+ _is_local(is_local),
+ _batch_size(parent->state()->batch_size()),
Review Comment:
这个也放到buget 里
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4248542715
run buildall
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4256409112
# Cloud UT Coverage Report
Increment line coverage ` ` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/d4d5d5f9628109e8fd7fc00ceaf529d5bf8dd0c6_d4d5d5f9628109e8fd7fc00ceaf529d5bf8dd0c6_cloud/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/d4d5d5f9628109e8fd7fc00ceaf529d5bf8dd0c6_d4d5d5f9628109e8fd7fc00ceaf529d5bf8dd0c6_cloud/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 78.48% (1798/2291) |
| Line Coverage | 64.13% (32287/50345) |
| Region Coverage | 65.07% (16246/24967) |
| Branch Coverage | 55.61% (8687/15620) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3123125119
##########
be/src/exec/exchange/local_exchanger.cpp:
##########
@@ -148,14 +149,20 @@ Status ShuffleExchanger::get_block(RuntimeState* state, Block* block, bool* eos,
PartitionedBlock partitioned_block;
MutableBlock mutable_block;
+ const auto max_batch_size = state->batch_size();
+ const auto max_block_bytes = state->preferred_block_size_bytes();
+
auto get_data = [&]() -> Status {
do {
const auto* offset_start = partitioned_block.second.row_idxs->data() +
partitioned_block.second.offset_start;
auto block_wrapper = partitioned_block.first;
RETURN_IF_ERROR(mutable_block.add_rows(&block_wrapper->_data_block, offset_start,
offset_start + partitioned_block.second.length));
- } while (mutable_block.rows() < state->batch_size() && !*eos &&
+ if (max_block_bytes > 0 && mutable_block.bytes() >= max_block_bytes) {
Review Comment:
我感觉,我们一个统一的写法:
1. 在operator 里放budget,把state 里的这两个变量放进去。
2. 把estimated row bytes 这些都放到budget 里,这样统一维护所有的状态
3. 其他地方如果想直接诶访问 这些状态,就从budget 里拿
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3123049942
##########
be/src/exec/operator/nested_loop_join_probe_operator.cpp:
##########
@@ -387,23 +411,34 @@ Status NestedLoopJoinProbeLocalState::generate_other_join_block_data(RuntimeStat
if (_matched_rows_done &&
_output_null_idx_build_side < _shared_state->build_blocks.size()) {
_finalize_current_phase<true, JoinOpType::value == TJoinOp::RIGHT_SEMI_JOIN>(
- _join_block, state->batch_size());
+ _join_block, state->batch_size(), state->preferred_block_size_bytes());
}
}
return Status::OK();
}
template <bool BuildSide, bool IsSemi>
-void NestedLoopJoinProbeLocalState::_finalize_current_phase(Block& block, size_t batch_size) {
+void NestedLoopJoinProbeLocalState::_finalize_current_phase(Block& block, size_t batch_size,
+ size_t block_max_bytes) {
auto& p = _parent->cast<NestedLoopJoinProbeOperatorX>();
auto dst_columns = block.mutate_columns();
DCHECK_GT(dst_columns.size(), 0);
auto column_size = dst_columns[0]->size();
+ // Precompute effective batch size from estimated bytes per row to avoid per-iteration byte sum
+ size_t effective_batch_size = batch_size;
+ if (column_size > 0) {
+ size_t current_bytes = 0;
Review Comment:
这种逻辑,在block 中没有公共的util 方法吗?
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4243142493
/review
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3132027575
##########
be/src/exec/operator/table_function_operator.cpp:
##########
@@ -256,12 +256,31 @@ Status TableFunctionLocalState::_get_expanded_block_block_fast_path(
DCHECK(_block_fast_path_prepared);
DCHECK(_block_fast_path_enabled);
- const auto remaining_capacity =
+ auto remaining_capacity =
state->batch_size() - cast_set<int>(columns[p._child_slots.size()]->size());
if (remaining_capacity <= 0) {
return Status::OK();
}
+ // Reduce capacity based on block_max_bytes using estimated bytes per output row.
+ const auto block_max_bytes = state->preferred_block_size_bytes();
+ if (_child_block->rows() > 0) {
+ size_t estimated_bytes_per_row = _child_block->bytes() / _child_block->rows();
+ if (estimated_bytes_per_row > 0) {
+ size_t current_bytes = 0;
+ for (const auto& col : columns) {
+ current_bytes += col->byte_size();
+ }
+ if (current_bytes >= block_max_bytes) {
Review Comment:
**[Blocking]** This fast path has the same zero-budget problem once `preferred_block_size_bytes()` correctly returns `0` for the disabled state. `current_bytes >= block_max_bytes` becomes `current_bytes >= 0`, so `_get_expanded_block_block_fast_path()` returns without consuming any child rows. `get_expanded_block()` then returns an empty non-`eos` block while `_cur_child_offset` still points at the same row, so block-fast-path `explode`/`posexplode` queries can loop forever when adaptive sizing is disabled.
This is a genuinely different instance from the existing disable-path comments on `RuntimeState`/`UnionSink`: here the zero sentinel causes a no-progress bug in the table-function fast path itself. The byte-budget branch needs to be skipped entirely when `block_max_bytes == 0`.
##########
be/src/exec/scan/scanner.cpp:
##########
@@ -87,24 +87,16 @@ Status Scanner::get_block_after_projects(RuntimeState* state, Block* block, bool
} else {
_origin_block.clear_column_data(row_descriptor.num_materialized_slots());
const auto min_batch_size = std::max(state->batch_size() / 2, 1);
- // For LOAD queries, use load_reader_max_block_bytes as the byte-based
- // upper bound for block accumulation, so small blocks can still be
- // merged to a reasonable size without exceeding the memory limit.
- const int64_t load_max_bytes = (state->query_type() == TQueryType::LOAD &&
- config::load_reader_max_block_bytes > 0)
- ? config::load_reader_max_block_bytes
- : 0;
- while (_padding_block.rows() < min_batch_size && !*eos) {
- if (load_max_bytes > 0 &&
- static_cast<int64_t>(_padding_block.bytes()) >= load_max_bytes) {
- break;
- }
+ const auto block_max_bytes = state->preferred_block_size_bytes();
+ while (_padding_block.rows() < min_batch_size &&
Review Comment:
**[Blocking]** `preferred_block_size_bytes()` now returns `0` in the disabled state, but this new loop treats `0` as "no bytes allowed" instead of "no byte cap". When a scan goes through the projection path (`_output_row_descriptor != nullptr`), `_padding_block.bytes() < block_max_bytes` is false from the start, so `get_block()` is never called and `get_block_after_projects()` returns an empty non-`eos` block. The scanner scheduler then caches that empty block and marks the task completed, so projected scans can spin without making progress when adaptive sizing is disabled by config or session.
This is distinct from the existing `RuntimeState`/config-gating threads: those were about callers still enforcing the byte budget when disabled; this path stops reading entirely once `0` is propagated. Please keep the legacy row-only behavior when `block_max_bytes == 0` in both the loop condition and the merge check below.
##########
regression-test/suites/query_p0/adaptive_batch_size/adaptive_batch_size.groovy:
##########
@@ -0,0 +1,211 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// Regression tests for the Adaptive Batch Size feature.
+//
+// Design notes:
+// - Each case runs the same query with the feature enabled and disabled, and
+// asserts that results are identical (correctness check).
+// - We do NOT directly assert internal block byte sizes, because the storage
+// layer does not expose them via SQL result columns. Correctness is the
+// primary requirement; performance / memory reduction is verified manually
+// or via profile counters in a separate benchmark.
+
+suite("adaptive_batch_size") {
+
+ // ── helpers ────────────────────────────────────────────────────────────────
+
+ def set_adaptive = { enabled ->
+ if (enabled) {
+ set_be_param("enable_adaptive_batch_size", "true")
+ sql "set preferred_block_size_bytes = 8388608" // 8 MB (default)
+ sql "set batch_size = 4096"
+ sql "set preferred_max_column_in_block_size_bytes = 1048576" // 1 MB
+ } else {
+ set_be_param("enable_adaptive_batch_size", "false")
Review Comment:
**[High]** This "disabled" branch only flips the BE config and leaves the session knobs at nonzero values, so the new regression suite never exercises the documented per-query opt-out (`SET preferred_block_size_bytes = 0` and `SET preferred_max_column_in_block_size_bytes = 0`). The existing FE/BE threads already show that the zero-sentinel path is easy to break; as written, this suite would still pass even if that user-visible disable contract stayed broken end to end.
Please add at least one case that keeps `enable_adaptive_batch_size` enabled and disables the feature through the session variables themselves.
##########
be/src/exec/operator/table_function_operator.cpp:
##########
@@ -511,7 +530,7 @@ Status TableFunctionLocalState::get_expanded_block(RuntimeState* state, Block* o
if (use_slow_path) {
bool skip_child_row = false;
- while (columns[p._child_slots.size()]->size() < state->batch_size()) {
Review Comment:
**[High]** The new byte-budget enforcement is still too late for wide table-function outputs. `_budget.within_budget(...)` is checked only at the top of the loop, but the subsequent `TableFunction::get_value()` call can append up to the full remaining row cap in one shot (`state->batch_size() - current_rows` here, `_budget.max_rows - output_row_count` in `_get_expanded_block_for_outer_conjuncts()`). Real implementations such as `VExplodeTableFunction`, `VJsonEachTableFunction`, and `UDFTableFunction` bulk-insert `max_step` elements via `insert_range_from`, so a single wide child row can still materialize a block far above `preferred_block_size_bytes` before the next loop condition runs.
This is distinct from the existing late-budget comments on storage/sort paths: it is the UDTF expansion path, and the new table-function test only covers a tiny fast-path case.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "velodb-robyang (via GitHub)" <gi...@apache.org>.
velodb-robyang commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3071093557
##########
be/src/common/block_budget.h:
##########
@@ -0,0 +1,93 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include <algorithm>
+#include <cstddef>
+
+namespace doris {
+
+// Lightweight value type that captures the dual row+byte budget for block
+// output sizing. Every operator that needs to respect the adaptive batch
+// size feature can construct a BlockBudget from RuntimeState and use the
+// helper methods instead of reimplementing the same row/byte logic inline.
+//
+// Typical usage:
+// BlockBudget budget(state->block_max_rows(), state->block_max_bytes());
+// size_t eff = budget.effective_max_rows(estimated_row_bytes);
+// while (budget.within_budget(block.rows(), block.bytes())) { ... }
+//
+struct BlockBudget {
Review Comment:
move to util
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "velodb-robyang (via GitHub)" <gi...@apache.org>.
velodb-robyang commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3071122022
##########
be/src/exec/operator/distinct_streaming_aggregation_operator.cpp:
##########
@@ -207,16 +209,19 @@ Status DistinctStreamingAggLocalState::_distinct_pre_agg_with_serialized_key(
}
} else {
DCHECK_EQ(_cache_block.rows(), 0);
- // is output row > batch_size, split some to cache_block
- if (out_block->rows() + _distinct_row.size() > batch_size) {
- size_t split_size = batch_size - out_block->rows();
+ // Compute maximum additional rows for out_block respecting both
+ // row limit (batch_size) and byte budget (block_max_bytes).
+ const BlockBudget budget(batch_size, block_max_bytes);
+ const size_t max_rows_to_add =
+ budget.remaining_rows(out_block->rows(), out_block->bytes());
+ if (_distinct_row.size() > max_rows_to_add) {
for (int i = 0; i < key_size; ++i) {
auto output_dst = out_block->get_by_position(i).column->assume_mutable();
key_columns[i]->append_data_by_selector(output_dst, _distinct_row, 0,
Review Comment:
在profile 中,每个operator 需要增加一个counter,表示min max block 的byte size,还有每个operator 处理了多少个block,所有的block 的bytes 加起来有多大,这个可以帮助我们定位一些问题:
1. 比如我们代码写错了,block 每次弄的特别小,导致性能特别差。
2. 我们有一些代码有问题,没处理block bytes size
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r2963550638
##########
be/src/storage/segment/adaptive_block_size_predictor.cpp:
##########
@@ -0,0 +1,171 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "storage/segment/adaptive_block_size_predictor.h"
+
+#include <gen_cpp/segment_v2.pb.h>
+
+#include <algorithm>
+#include <cstddef>
+#include <unordered_set>
+
+#include "core/block/block.h"
+#include "storage/segment/segment.h"
+#include "storage/tablet/tablet_schema.h"
+
+namespace doris::segment_v2 {
+
+AdaptiveBlockSizePredictor::AdaptiveBlockSizePredictor(size_t preferred_block_size_bytes,
+ size_t preferred_max_col_bytes)
+ : _block_size_bytes(preferred_block_size_bytes), _max_col_bytes(preferred_max_col_bytes) {}
+
+void AdaptiveBlockSizePredictor::update(const Block& block,
+ const std::vector<ColumnId>& output_columns) {
+ size_t rows = block.rows();
+ if (rows == 0) {
+ return;
+ }
+ double cur = static_cast<double>(block.bytes()) / static_cast<double>(rows);
+
+ if (!_has_history) {
+ _bytes_per_row = cur;
+ _has_history = true;
+ } else {
+ _bytes_per_row = kAlpha * _bytes_per_row + kBeta * cur;
+ }
+
+ // Per-column EWMA sampling.
+ // output_columns[i] corresponds to block column position i (caller's guarantee).
+ size_t ncols = std::min(output_columns.size(), size_t(block.columns()));
+ for (size_t i = 0; i < ncols; ++i) {
+ ColumnId cid = output_columns[i];
+ double col_cur = static_cast<double>(block.get_by_position(i).column->byte_size()) /
+ static_cast<double>(rows);
+ auto it = _col_bytes_per_row.find(cid);
+ if (it == _col_bytes_per_row.end()) {
+ _col_bytes_per_row[cid] = col_cur;
+ } else {
+ it->second = kAlpha * it->second + kBeta * col_cur;
+ }
+ }
+}
+
+size_t AdaptiveBlockSizePredictor::predict_next_rows(size_t max_rows, Segment& segment,
+ const std::vector<ColumnId>& output_columns) {
+ if (_block_size_bytes == 0) {
+ return max_rows;
+ }
+
+ auto clamp_predicted_rows = [&](size_t predicted_rows) {
+ size_t clamped_rows = std::min(predicted_rows, max_rows);
+ if (!_has_history) {
+ clamped_rows = std::min(clamped_rows, kSafetyBatchRowThreshold);
+ }
+ return std::max(size_t(1), clamped_rows);
+ };
+
+ double estimated_bytes_per_row = 0.0;
+
+ if (!_has_history) {
+ // First-call path: use cached metadata hint or compute it once.
+ if (_metadata_hint_bytes_per_row == 0.0) {
+ uint32_t seg_rows = segment.num_rows();
+ if (seg_rows > 0) {
+ // Build a set of unique_ids we care about for fast lookup.
+ // We need the TabletSchema to map ColumnId -> unique_id.
+ // Use the segment's tablet_schema if available via traverse_column_meta_pbs.
+ // We collect raw data bytes only for columns in output_columns.
+ // To map output ColumnId to unique_id we need the schema; the segment
+ // exposes traverse_column_meta_pbs which visits every ColumnMetaPB.
+ // We accumulate bytes for all top-level columns and divide by segment rows.
+ // We use a conservative 1.2x factor to avoid over-shrinking the first batch.
+ double total_bytes = 0.0;
+ uint64_t matched_cols = 0;
+
+ // Build a set of unique_ids corresponding to output_columns using the
+ // segment's tablet_schema.
+ const TabletSchemaSPtr& ts = segment.tablet_schema();
+ std::unordered_set<int32_t> wanted_uids;
+ if (ts) {
+ for (ColumnId cid : output_columns) {
+ if (static_cast<size_t>(cid) < ts->num_columns()) {
+ int32_t uid = ts->column(cid).unique_id();
+ if (uid >= 0) {
+ wanted_uids.insert(uid);
+ }
+ }
+ }
+ }
+
+ if (!wanted_uids.empty()) {
+ // traverse_column_meta_pbs visits all ColumnMetaPB entries in the footer.
+ auto collector = [&](const ColumnMetaPB& meta) {
+ if (meta.has_unique_id() && wanted_uids.contains(meta.unique_id()) &&
+ meta.has_raw_data_bytes()) {
+ total_bytes += static_cast<double>(meta.raw_data_bytes());
+ matched_cols++;
+ }
+ };
+ // Ignore error: if traversal fails, total_bytes stays 0 and we fall through.
+ auto st = segment.traverse_column_meta_pbs(collector);
+ if (!st.ok()) {
+ LOG(WARNING) << "Failed to traverse column metadata: " << st.to_string();
+ return clamp_predicted_rows(max_rows);
+ }
+ }
+
+ if (matched_cols > 0 && total_bytes > 0.0) {
+ _metadata_hint_bytes_per_row =
+ (total_bytes / static_cast<double>(seg_rows)) * 1.2;
+ }
+ }
+ }
+
+ if (_metadata_hint_bytes_per_row > 0.0) {
+ estimated_bytes_per_row = _metadata_hint_bytes_per_row;
+ } else {
+ // No metadata or empty segment — fall back to max_rows.
+ return clamp_predicted_rows(max_rows);
+ }
+ } else {
+ estimated_bytes_per_row = _bytes_per_row;
+ }
+
+ if (estimated_bytes_per_row <= 0.0) {
+ return clamp_predicted_rows(max_rows);
+ }
+
+ auto predicted =
+ static_cast<size_t>(static_cast<double>(_block_size_bytes) / estimated_bytes_per_row);
+ LOG(INFO) << "****** predicted rows: " << predicted
+ << ", estimated_bytes_per_row: " << estimated_bytes_per_row
+ << ", _block_size_bytes: " << _block_size_bytes;
Review Comment:
**[Bug/High]** This `LOG(INFO)` with `******` prefix is called on **every** `predict_next_rows()` invocation — i.e., every batch in every segment scan. This will generate massive log spam in production.
This should be changed to `VLOG_DEBUG` or removed entirely. At minimum, this is clearly a debug statement accidentally left in:
```cpp
VLOG_DEBUG << "predicted rows: " << predicted
<< ", estimated_bytes_per_row: " << estimated_bytes_per_row
<< ", _block_size_bytes: " << _block_size_bytes;
```
##########
be/src/storage/iterator/block_reader.cpp:
##########
@@ -386,6 +387,13 @@ Status BlockReader::_replace_key_next_block(Block* block, bool* eof) {
break;
}
}
+ // Byte-budget check: after the inner loop _next_row is either EOF or the next different
+ // key, so it is safe to stop accumulating here without repeating any row.
+ if (config::enable_adaptive_batch_size && _reader_context.preferred_block_size_bytes > 0 &&
+ Block::columns_byte_size(target_columns) >=
+ _reader_context.preferred_block_size_bytes) {
+ break;
+ }
Review Comment:
**[Bug]** When `record_rowids` is enabled, this byte-budget `break` exits the outer `while` loop without resizing `_block_row_locations` to `target_block_row`. At line 349, `_block_row_locations` was resized to `batch_size()`, so after this break it will still have `batch_size()` entries instead of `target_block_row` entries.
The EOF path at lines 372-374 correctly does `_block_row_locations.resize(target_block_row)`. This break path needs the same treatment:
```cpp
if (config::enable_adaptive_batch_size && _reader_context.preferred_block_size_bytes > 0 &&
Block::columns_byte_size(target_columns) >=
_reader_context.preferred_block_size_bytes) {
if (UNLIKELY(_reader_context.record_rowids)) {
_block_row_locations.resize(target_block_row);
}
break;
}
```
Without this fix, `current_block_row_locations()` returns a vector with stale entries, and the DCHECK at line 604 (`DCHECK_EQ(_block_row_locations.size(), block->rows() + delete_count)`) will fail.
##########
be/src/storage/iterator/block_reader.cpp:
##########
@@ -539,6 +555,12 @@ Status BlockReader::_unique_key_next_block(Block* block, bool* eof) {
LOG(WARNING) << "next failed: " << res;
return res;
}
+ // Byte-budget check: _next_row is already saved so stopping here is safe.
+ if (config::enable_adaptive_batch_size && _reader_context.preferred_block_size_bytes > 0 &&
+ Block::columns_byte_size(target_columns) >=
+ _reader_context.preferred_block_size_bytes) {
+ break;
+ }
Review Comment:
**[Bug]** Same issue as in `_replace_key_next_block`: when `record_rowids` is enabled, this byte-budget `break` exits without resizing `_block_row_locations` to `target_block_row`. At line 530, `_block_row_locations` was resized to `_reader_context.batch_size`. The EOF path at lines 548-550 correctly resizes.
Fix:
```cpp
if (config::enable_adaptive_batch_size && _reader_context.preferred_block_size_bytes > 0 &&
Block::columns_byte_size(target_columns) >=
_reader_context.preferred_block_size_bytes) {
if (UNLIKELY(_reader_context.record_rowids)) {
_block_row_locations.resize(target_block_row);
}
break;
}
```
Note: in `_unique_key_next_block`, there is also the `_delete_sign_available` filtering path (starting at line 566) that uses `target_block_row` and `_block_row_locations`. An incorrectly-sized `_block_row_locations` could corrupt the filter logic.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4101650695
# BE Regression && UT Coverage Report
Increment line coverage `100% (0/0)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_ae43fe96d6a20040c16d54f6ee49141576a11c2a_merge/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_ae43fe96d6a20040c16d54f6ee49141576a11c2a_merge/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 73.19% (26943/36811) |
| Line Coverage | 56.69% (288618/509150) |
| Region Coverage | 54.00% (240384/445189) |
| Branch Coverage | 55.67% (103990/186813) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4102423475
# BE Regression && UT Coverage Report
Increment line coverage `100% (0/0)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_ae43fe96d6a20040c16d54f6ee49141576a11c2a_merge/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_ae43fe96d6a20040c16d54f6ee49141576a11c2a_merge/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 73.19% (26941/36811) |
| Line Coverage | 56.68% (288599/509150) |
| Region Coverage | 53.98% (240297/445189) |
| Branch Coverage | 55.66% (103987/186813) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4096128176
run buildall
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4096365287
# Cloud UT Coverage Report
Increment line coverage ` ` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/f404b067c8aa7622413fd7d269235aaccd195121_f404b067c8aa7622413fd7d269235aaccd195121_cloud/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/f404b067c8aa7622413fd7d269235aaccd195121_f404b067c8aa7622413fd7d269235aaccd195121_cloud/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 78.63% (1796/2284) |
| Line Coverage | 64.38% (32274/50130) |
| Region Coverage | 65.27% (16162/24760) |
| Branch Coverage | 55.71% (8611/15456) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4134463066
<details>
<summary>TPC-DS: <b>Total hot run time: 169676 ms</b></summary>
```
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 841c2a7248322bd5f241495adbc38da11aecef50, data reload: false
query5 4320 674 502 502
query6 331 234 213 213
query7 4225 479 273 273
query8 367 253 257 253
query9 8751 2770 2772 2770
query10 498 388 328 328
query11 7016 5103 4868 4868
query12 185 130 123 123
query13 1323 479 355 355
query14 5740 3787 3482 3482
query14_1 2876 2837 2840 2837
query15 204 195 179 179
query16 975 493 474 474
query17 900 744 634 634
query18 2449 466 361 361
query19 224 218 184 184
query20 135 130 131 130
query21 213 134 111 111
query22 13434 14138 14435 14138
query23 17022 16529 16062 16062
query23_1 16286 16061 15757 15757
query24 7155 1640 1253 1253
query24_1 1232 1241 1248 1241
query25 633 460 404 404
query26 1250 284 146 146
query27 2769 490 293 293
query28 4488 1885 1876 1876
query29 838 583 471 471
query30 299 225 192 192
query31 1023 950 886 886
query32 77 72 71 71
query33 526 332 289 289
query34 894 895 518 518
query35 638 678 602 602
query36 1105 1169 978 978
query37 139 95 88 88
query38 2959 2975 2909 2909
query39 873 841 814 814
query39_1 792 793 823 793
query40 277 165 136 136
query41 65 67 59 59
query42 267 271 261 261
query43 247 256 226 226
query44
query45 208 196 189 189
query46 943 1039 619 619
query47 2133 2174 2055 2055
query48 322 341 239 239
query49 634 466 391 391
query50 721 289 218 218
query51 4145 4144 4044 4044
query52 270 276 263 263
query53 308 344 295 295
query54 299 282 271 271
query55 91 87 83 83
query56 326 334 298 298
query57 1936 1736 1735 1735
query58 291 281 271 271
query59 2801 2953 2763 2763
query60 333 341 327 327
query61 171 157 153 153
query62 608 569 524 524
query63 317 287 276 276
query64 5074 1312 1025 1025
query65
query66 1473 482 356 356
query67 24393 24373 24194 24194
query68
query69 403 327 298 298
query70 964 989 958 958
query71 344 308 314 308
query72 2874 2670 2515 2515
query73 556 562 327 327
query74 9581 9606 9431 9431
query75 2872 2749 2458 2458
query76 2310 1035 712 712
query77 386 388 318 318
query78 10960 11097 10537 10537
query79 3255 779 580 580
query80 1796 645 537 537
query81 579 258 229 229
query82 938 157 119 119
query83 343 266 255 255
query84 309 128 106 106
query85 918 499 447 447
query86 490 298 288 288
query87 3195 3116 2995 2995
query88 3600 2686 2686 2686
query89 428 382 339 339
query90 2188 185 187 185
query91 175 165 137 137
query92 86 77 76 76
query93 1872 849 507 507
query94 641 325 311 311
query95 603 403 322 322
query96 648 536 230 230
query97 2490 2517 2371 2371
query98 242 220 222 220
query99 1018 998 911 911
Total cold run time: 255106 ms
Total hot run time: 169676 ms
```
</details>
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4128307104
# FE UT Coverage Report
Increment line coverage ` 100.00% (4/4)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_841c2a7248322bd5f241495adbc38da11aecef50/fe_increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_841c2a7248322bd5f241495adbc38da11aecef50/fe_report/index.html)
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4169190130
/review
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3025519977
##########
be/src/storage/iterator/vcollect_iterator.cpp:
##########
@@ -913,6 +955,24 @@ Status VCollectIterator::Level1Iterator::_merge_next(Block* block) {
continuous_row_in_block = 0;
pre_row_ref = cur_row;
Review Comment:
`Level1Iterator::_merge_next()` now honors `preferred_block_size_bytes`, but `VCollectIterator::next(Block*)` can also route ordered storage reads through `_topn_next()` when `read_orderby_key_limit > 0` (for `DUP_KEYS` and `UNIQUE_KEYS` with MOW). That path still accumulates up to `_topn_limit` rows into one `MutableBlock` and returns it directly at the end, without consulting the new byte budget.
A concrete case is `ORDER BY key LIMIT 100000` on wide rows: `rs_reader->next_batch(block)` may now produce smaller chunks, but `_topn_next()` keeps copying them into `mutable_block` until it has `_topn_limit` candidates, so the final returned block can still be far above `preferred_block_size_bytes`. This means the PR's new invariant does not hold on this parallel storage path yet.
Please either add the same byte-budget enforcement here (and return partial TopN results across multiple calls), or explicitly scope the feature away from the ordered TopN path and add tests/documentation for that exception.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4205794610
# Cloud UT Coverage Report
Increment line coverage ` ` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/d8bccbf45af9d4a40148ae7511fb7eb2ccb34b36_d8bccbf45af9d4a40148ae7511fb7eb2ccb34b36_cloud/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/d8bccbf45af9d4a40148ae7511fb7eb2ccb34b36_d8bccbf45af9d4a40148ae7511fb7eb2ccb34b36_cloud/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 78.48% (1798/2291) |
| Line Coverage | 64.15% (32276/50312) |
| Region Coverage | 65.07% (16237/24954) |
| Branch Coverage | 55.61% (8680/15610) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4096768421
<details>
<summary>TPC-H: <b>Total hot run time: 27323 ms</b></summary>
```
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit f404b067c8aa7622413fd7d269235aaccd195121, data reload: false
------ Round 1 ----------------------------------
orders Doris NULL NULL 0 0 0 NULL 0 NULL NULL 2023-12-26 18:27:23 2023-12-26 18:42:55 NULL utf-8 NULL NULL
============================================
q1 17655 4402 4359 4359
q2 q3 11076 846 550 550
q4 5270 389 259 259
q5 9358 1253 1020 1020
q6 252 179 151 151
q7 833 892 691 691
q8 10989 1566 1438 1438
q9 6834 4874 4905 4874
q10 6372 1930 1703 1703
q11 471 255 242 242
q12 746 586 471 471
q13 18060 2948 2210 2210
q14 231 236 205 205
q15 q16 747 763 684 684
q17 743 876 469 469
q18 6012 5388 5145 5145
q19 1117 997 638 638
q20 543 482 377 377
q21 4650 2002 1555 1555
q22 371 327 282 282
Total cold run time: 102330 ms
Total hot run time: 27323 ms
----- Round 2, with runtime_filter_mode=off -----
orders Doris NULL NULL 150000000 42 6422171781 NULL 22778155 NULL NULL 2023-12-26 18:27:23 2023-12-26 18:42:55 NULL utf-8 NULL NULL
============================================
q1 4645 4569 4703 4569
q2 q3 3992 4406 3881 3881
q4 943 1227 847 847
q5 4215 4459 4331 4331
q6 197 191 150 150
q7 1868 1676 1584 1584
q8 2544 2745 2608 2608
q9 7604 7456 7373 7373
q10 3857 4110 3620 3620
q11 564 515 484 484
q12 508 607 501 501
q13 2764 3188 2341 2341
q14 300 306 282 282
q15 q16 739 793 832 793
q17 1375 1433 1422 1422
q18 7227 6874 6555 6555
q19 1041 989 989 989
q20 2113 2190 2015 2015
q21 4021 3561 3439 3439
q22 452 426 397 397
Total cold run time: 50969 ms
Total hot run time: 48181 ms
```
</details>
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3078796453
##########
be/src/runtime/runtime_state.h:
##########
@@ -138,7 +138,38 @@ class RuntimeState {
const DescriptorTbl& desc_tbl() const { return *_desc_tbl; }
void set_desc_tbl(const DescriptorTbl* desc_tbl) { _desc_tbl = desc_tbl; }
- MOCK_FUNCTION int batch_size() const { return _query_options.batch_size; }
+
+ // Row-count limit for output blocks (default 65535, range [1, 65535]).
+ // Consistent with SessionVariable.batchSize on FE side.
+ MOCK_FUNCTION int batch_size() const {
+ static constexpr int kDefault = 65535;
+ auto v = _query_options.batch_size;
+ return std::min(std::max(1, v), kDefault);
+ }
+
+ // Target byte budget per output block (default 8MB).
+ // FE validates the range [1MB, 512MB] in SessionVariable; BE trusts that
+ // but applies a default when the field is unset or zero.
+ MOCK_FUNCTION size_t preferred_block_size_bytes() const {
Review Comment:
This accessor is the root of the disable-path regression. It always returns `8MB` when the session field is unset or zero, and it does not consult `config::enable_adaptive_batch_size`. All of the newly converted callers then keep enforcing byte budgets even when the BE config says the feature is off, and the documented `SET preferred_block_size_bytes = 0` path can never work here. Please return `0` for the disabled state (or gate every caller, but that is much easier to miss).
##########
be/src/exec/operator/union_sink_operator.cpp:
##########
@@ -133,7 +133,10 @@ Status UnionSinkOperatorX::sink(RuntimeState* state, Block* in_block, bool eos)
return Status::OK();
}
// not eos and block rows is enough to output,so push block
- if (local_state._output_block && (local_state._output_block->rows() >= state->batch_size())) {
+ const auto block_max_bytes = state->preferred_block_size_bytes();
+ if (local_state._output_block &&
Review Comment:
This new flush condition needs the usual `block_max_bytes > 0` guard. Otherwise, once the byte budget is correctly represented as `0` for the disabled state, every non-empty block will satisfy `bytes() >= block_max_bytes` and `UNION` will flush every partial block immediately instead of batching by rows.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4174655833
<details>
<summary>TPC-DS: <b>Total hot run time: 180053 ms</b></summary>
```
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit eee985b7d8c909cb70ddac3af54a70d35d76ba9a, data reload: false
query5 4330 668 528 528
query6 361 239 205 205
query7 4320 599 337 337
query8 348 244 221 221
query9 8725 3952 3962 3952
query10 511 429 364 364
query11 6680 5500 5128 5128
query12 191 139 131 131
query13 1334 627 469 469
query14 5793 5248 4793 4793
query14_1 4210 4141 4152 4141
query15 217 211 185 185
query16 1018 504 459 459
query17 1169 811 657 657
query18 2804 537 380 380
query19 259 237 201 201
query20 144 135 130 130
query21 241 148 126 126
query22 14109 15438 14338 14338
query23 18127 17207 16554 16554
query23_1 17303 16676 16828 16676
query24 7825 1913 1415 1415
query24_1 1379 1396 1357 1357
query25 649 486 440 440
query26 1257 329 182 182
query27 2650 654 371 371
query28 4393 1942 1911 1911
query29 975 658 564 564
query30 304 235 198 198
query31 1104 1046 938 938
query32 90 70 70 70
query33 537 365 290 290
query34 1191 1200 677 677
query35 773 801 671 671
query36 1243 1216 1086 1086
query37 162 99 84 84
query38 3128 3072 2965 2965
query39 911 887 856 856
query39_1 829 818 827 818
query40 235 158 138 138
query41 61 60 59 59
query42 278 271 274 271
query43 322 323 276 276
query44
query45 205 198 187 187
query46 1151 1328 788 788
query47 2338 2351 2201 2201
query48 414 418 316 316
query49 646 528 434 434
query50 725 287 216 216
query51 4381 4234 4233 4233
query52 279 282 269 269
query53 333 348 284 284
query54 334 293 274 274
query55 104 96 98 96
query56 325 331 324 324
query57 1779 1651 1713 1651
query58 305 286 276 276
query59 2925 3025 2769 2769
query60 340 356 322 322
query61 158 158 157 157
query62 682 618 545 545
query63 318 271 301 271
query64 5264 1430 1112 1112
query65
query66 1410 496 372 372
query67 24299 24270 24146 24146
query68
query69 459 342 319 319
query70 1012 992 974 974
query71 367 334 314 314
query72 3056 2754 2469 2469
query73 856 820 477 477
query74 9873 9699 9484 9484
query75 3538 3341 2953 2953
query76 2313 1148 808 808
query77 414 404 352 352
query78 11272 11493 10709 10709
query79 1567 1118 863 863
query80 1371 759 669 669
query81 524 279 238 238
query82 1225 169 121 121
query83 344 300 265 265
query84 265 141 121 121
query85 953 550 469 469
query86 447 317 313 313
query87 3303 3222 3105 3105
query88 3727 2765 2719 2719
query89 493 441 382 382
query90 2073 196 184 184
query91 178 176 142 142
query92 83 73 74 73
query93 941 904 531 531
query94 719 350 316 316
query95 679 474 350 350
query96 1037 762 351 351
query97 2689 2692 2565 2565
query98 253 228 229 228
query99 1087 1079 960 960
Total cold run time: 261376 ms
Total hot run time: 180053 ms
```
</details>
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4175000980
# BE UT Coverage Report
Increment line coverage ` ` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/eee985b7d8c909cb70ddac3af54a70d35d76ba9a_eee985b7d8c909cb70ddac3af54a70d35d76ba9a/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/eee985b7d8c909cb70ddac3af54a70d35d76ba9a_eee985b7d8c909cb70ddac3af54a70d35d76ba9a/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 52.92% (20065/37916) |
| Line Coverage | 36.51% (188297/515675) |
| Region Coverage | 32.72% (145891/445943) |
| Branch Coverage | 33.90% (63950/188662) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4189832630
run buildall
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4189947881
<details>
<summary>TPC-H: <b>Total hot run time: 36837 ms</b></summary>
```
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit a6852d1b3244bc2b4b0e0ed25aad98b25f80599e, data reload: false
------ Round 1 ----------------------------------
orders Doris NULL NULL 0 0 0 NULL 0 NULL NULL 2023-12-26 18:27:23 2023-12-26 18:42:55 NULL utf-8 NULL NULL
============================================
q1 17760 9386 9498 9386
q2 q3 10667 852 599 599
q4 4672 417 310 310
q5 7589 1348 1156 1156
q6 222 194 168 168
q7 934 976 789 789
q8 9928 1467 1364 1364
q9 5460 5227 5195 5195
q10 6309 2371 2104 2104
q11 484 295 294 294
q12 649 391 245 245
q13 18242 3650 3055 3055
q14 315 328 296 296
q15 q16 1074 1043 989 989
q17 956 1174 752 752
q18 7221 7025 6714 6714
q19 1396 1311 1084 1084
q20 578 446 281 281
q21 4815 2182 1724 1724
q22 462 384 332 332
Total cold run time: 99733 ms
Total hot run time: 36837 ms
----- Round 2, with runtime_filter_mode=off -----
orders Doris NULL NULL 150000000 42 6422171781 NULL 22778155 NULL NULL 2023-12-26 18:27:23 2023-12-26 18:42:55 NULL utf-8 NULL NULL
============================================
q1 10217 10202 10009 10009
q2 q3 5971 6426 5729 5729
q4 1618 1995 1303 1303
q5 5738 5869 6253 5869
q6 294 208 167 167
q7 2566 2433 2187 2187
q8 4803 4727 4784 4727
q9 10611 10619 10522 10522
q10 5231 5227 5101 5101
q11 912 682 630 630
q12 680 790 582 582
q13 3580 3914 3219 3219
q14 378 392 357 357
q15 q16 1041 1125 1020 1020
q17 1361 1431 1403 1403
q18 9599 9011 8803 8803
q19 1119 1212 1101 1101
q20 2764 2922 2704 2704
q21 6328 5839 5385 5385
q22 482 450 394 394
Total cold run time: 75293 ms
Total hot run time: 71212 ms
```
</details>
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4183870643
/review
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4206001784
# FE UT Coverage Report
Increment line coverage ` 100.00% (6/6)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_d8bccbf45af9d4a40148ae7511fb7eb2ccb34b36/fe_increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_d8bccbf45af9d4a40148ae7511fb7eb2ccb34b36/fe_report/index.html)
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4248723642
# Cloud UT Coverage Report
Increment line coverage ` ` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/25b25c07c01b606be38d8cb16601a25f8a559167_25b25c07c01b606be38d8cb16601a25f8a559167_cloud/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/25b25c07c01b606be38d8cb16601a25f8a559167_25b25c07c01b606be38d8cb16601a25f8a559167_cloud/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 78.48% (1798/2291) |
| Line Coverage | 64.16% (32300/50345) |
| Region Coverage | 65.09% (16250/24967) |
| Branch Coverage | 55.60% (8684/15620) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4248862767
# FE UT Coverage Report
Increment line coverage ` 28.57% (4/14)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_25b25c07c01b606be38d8cb16601a25f8a559167/fe_increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_25b25c07c01b606be38d8cb16601a25f8a559167/fe_report/index.html)
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "velodb-robyang (via GitHub)" <gi...@apache.org>.
velodb-robyang commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3071322529
##########
be/src/format/json/new_json_reader.h:
##########
@@ -81,6 +81,8 @@ class NewJsonReader : public GenericReader {
const std::unordered_map<std::string, VExprContextSPtr>& col_default_value_ctx,
bool is_load);
Status get_next_block(Block* block, size_t* read_rows, bool* eof) override;
+ void set_batch_size(size_t batch_size) override;
Review Comment:
这种行式的reader,为啥是感知batch size,而不是感知 batch bytes?
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3122985499
##########
be/src/exec/operator/distinct_streaming_aggregation_operator.cpp:
##########
@@ -391,9 +396,11 @@ Status DistinctStreamingAggOperatorX::pull(RuntimeState* state, Block* block, bo
bool DistinctStreamingAggOperatorX::need_more_input_data(RuntimeState* state) const {
auto& local_state = get_local_state(state);
+ const BlockBudget budget(state->batch_size(), state->preferred_block_size_bytes());
Review Comment:
这个budget 是不是放到统一的operator 里比较好?
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3123016461
##########
be/src/exec/exchange/vdata_stream_sender.cpp:
##########
@@ -288,7 +288,10 @@ Status Channel::close(RuntimeState* state) {
}
BlockSerializer::BlockSerializer(ExchangeSinkLocalState* parent, bool is_local)
- : _parent(parent), _is_local(is_local), _batch_size(parent->state()->batch_size()) {}
+ : _parent(parent),
+ _is_local(is_local),
+ _batch_size(parent->state()->batch_size()),
+ _block_max_bytes(parent->state()->preferred_block_size_bytes()) {}
Review Comment:
这个变量的名字,我看代码里,大量的都是 block_max_bytes 但是我们配置里又是preferred_block_size_bytes,为什么不用同样的名字,是有设么特殊考虑吗?
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3123112294
##########
be/src/exec/exchange/local_exchanger.cpp:
##########
@@ -148,14 +149,20 @@ Status ShuffleExchanger::get_block(RuntimeState* state, Block* block, bool* eos,
PartitionedBlock partitioned_block;
MutableBlock mutable_block;
+ const auto max_batch_size = state->batch_size();
+ const auto max_block_bytes = state->preferred_block_size_bytes();
Review Comment:
这里为什么不用budget?
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4309636673
/review
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4094762677
Thank you for your contribution to Apache Doris.
Don't know what should be done next? See [How to process your PR](https://cwiki.apache.org/confluence/display/DORIS/How+to+process+your+PR).
Please clearly describe your PR:
1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
3. What features were added. Why was this function added?
4. Which code was refactored and why was this part of the code refactored?
5. Which functions were optimized and what is the difference before and after the optimization?
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "Gabriel39 (via GitHub)" <gi...@apache.org>.
Gabriel39 commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r2985512147
##########
be/src/exec/operator/olap_scan_operator.h:
##########
@@ -309,6 +309,9 @@ class OlapScanLocalState final : public ScanLocalState<OlapScanLocalState> {
// Variant subtree: times selecting doc snapshot all iterator (merge doc snapshot into root)
RuntimeProfile::Counter* _variant_doc_value_column_iter_count = nullptr;
+ RuntimeProfile::Counter* _adaptive_batch_predict_min_rows_counter = nullptr;
+ RuntimeProfile::Counter* _adaptive_batch_predict_max_rows_counter = nullptr;
Review Comment:
Use `HighWaterMarkCounter`
##########
be/src/storage/rowset/rowset_reader_context.h:
##########
@@ -73,6 +73,13 @@ struct RowsetReaderContext {
bool use_page_cache = false;
int sequence_id_idx = -1;
int batch_size = 1024;
+ // Adaptive batch size: target output block byte budget. 0 = disabled.
+ size_t preferred_block_size_bytes = 0;
+ // Per-column byte limit for the adaptive predictor. 0 = no column limit.
+ size_t preferred_max_col_bytes = 1048576;
Review Comment:
0 by default?
##########
be/src/runtime/runtime_state.h:
##########
@@ -139,6 +139,20 @@ class RuntimeState {
const DescriptorTbl& desc_tbl() const { return *_desc_tbl; }
void set_desc_tbl(const DescriptorTbl* desc_tbl) { _desc_tbl = desc_tbl; }
MOCK_FUNCTION int batch_size() const { return _query_options.batch_size; }
+ MOCK_FUNCTION size_t preferred_block_size_bytes() const {
+ if (_query_options.__isset.preferred_block_size_bytes) {
+ auto v = _query_options.preferred_block_size_bytes;
+ return v > 0 ? static_cast<size_t>(v) : 0;
+ }
+ return 8388608UL; // 8MB default
Review Comment:
Maybe we should not enable this feature by default
##########
be/src/common/config.cpp:
##########
@@ -433,6 +433,8 @@ DEFINE_mInt32(pk_index_page_cache_stale_sweep_time_sec, "600");
DEFINE_mBool(enable_low_cardinality_optimize, "true");
DEFINE_Bool(enable_low_cardinality_cache_code, "true");
+DEFINE_mBool(enable_adaptive_batch_size, "true");
Review Comment:
Could we use a session variable instead ?
##########
be/src/storage/iterator/block_reader.cpp:
##########
@@ -386,6 +387,16 @@ Status BlockReader::_replace_key_next_block(Block* block, bool* eof) {
break;
}
}
+ // Byte-budget check: after the inner loop _next_row is either EOF or the next different
+ // key, so it is safe to stop accumulating here without repeating any row.
+ if (config::enable_adaptive_batch_size && _reader_context.preferred_block_size_bytes > 0 &&
Review Comment:
Extract a common function to do this checking
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4134368428
<details>
<summary>TPC-H: <b>Total hot run time: 26571 ms</b></summary>
```
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 841c2a7248322bd5f241495adbc38da11aecef50, data reload: false
------ Round 1 ----------------------------------
orders Doris NULL NULL 0 0 0 NULL 0 NULL NULL 2023-12-26 18:27:23 2023-12-26 18:42:55 NULL utf-8 NULL NULL
============================================
q1 17638 4541 4320 4320
q2 q3 10749 823 531 531
q4 4713 362 248 248
q5 8127 1240 1040 1040
q6 225 174 146 146
q7 813 857 667 667
q8 10822 1662 1342 1342
q9 6232 4802 4673 4673
q10 6309 1927 1633 1633
q11 452 267 241 241
q12 736 600 473 473
q13 18074 2750 1973 1973
q14 236 240 213 213
q15 q16 723 751 662 662
q17 772 861 444 444
q18 5981 5538 5185 5185
q19 1106 988 613 613
q20 573 500 382 382
q21 4338 2193 1494 1494
q22 396 338 291 291
Total cold run time: 99015 ms
Total hot run time: 26571 ms
----- Round 2, with runtime_filter_mode=off -----
orders Doris NULL NULL 150000000 42 6422171781 NULL 22778155 NULL NULL 2023-12-26 18:27:23 2023-12-26 18:42:55 NULL utf-8 NULL NULL
============================================
q1 4789 4651 4671 4651
q2 q3 3964 4466 3937 3937
q4 897 1233 795 795
q5 4094 4347 4406 4347
q6 182 174 142 142
q7 1782 1677 1535 1535
q8 2531 2729 2598 2598
q9 7535 7400 7373 7373
q10 3948 4029 3658 3658
q11 584 438 455 438
q12 602 618 464 464
q13 2489 2907 2154 2154
q14 303 297 273 273
q15 q16 721 762 702 702
q17 1197 1429 1427 1427
q18 7399 7198 6797 6797
q19 958 981 912 912
q20 2064 2258 2092 2092
q21 4077 3548 3360 3360
q22 445 424 387 387
Total cold run time: 50561 ms
Total hot run time: 48042 ms
```
</details>
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4135551316
# BE Regression && UT Coverage Report
Increment line coverage `100% (0/0)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_841c2a7248322bd5f241495adbc38da11aecef50_merge/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_841c2a7248322bd5f241495adbc38da11aecef50_merge/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 71.81% (26497/36898) |
| Line Coverage | 54.67% (279479/511188) |
| Region Coverage | 51.81% (231734/447244) |
| Branch Coverage | 53.31% (100222/187989) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4135080505
# BE Regression && UT Coverage Report
Increment line coverage `100% (0/0)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_841c2a7248322bd5f241495adbc38da11aecef50_merge/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_841c2a7248322bd5f241495adbc38da11aecef50_merge/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 71.61% (26421/36896) |
| Line Coverage | 54.43% (278228/511194) |
| Region Coverage | 51.57% (230636/447242) |
| Branch Coverage | 53.00% (99642/187989) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4136858537
# BE Regression && UT Coverage Report
Increment line coverage `100% (0/0)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_841c2a7248322bd5f241495adbc38da11aecef50_merge/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_841c2a7248322bd5f241495adbc38da11aecef50_merge/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 71.77% (26483/36898) |
| Line Coverage | 54.64% (279292/511188) |
| Region Coverage | 51.77% (231527/447244) |
| Branch Coverage | 53.27% (100144/187989) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3021487433
##########
gensrc/thrift/PaloInternalService.thrift:
##########
@@ -470,6 +470,16 @@ struct TQueryOptions {
// session variable `spill_repartition_max_depth` in FE. Default is 8.
209: optional i32 spill_repartition_max_depth = 8
+ // Adaptive batch size: target output block size in bytes. 0 means disabled (fixed row count only).
+ // Default 8MB. Sent by FE session variable preferred_block_size_bytes.
+ 210: optional i64 preferred_block_size_bytes = 8388608
+
+ // Per-column byte limit for adaptive batch size. 0 means no per-column limit. Default 1MB.
+ 211: optional i64 preferred_max_column_in_block_size_bytes = 1048576
+
+ // Adaptive batch size: target output block row count limit. Default 65535.
+ // Sent by FE session variable preferred_block_size_rows.
+ 212: optional i64 preferred_block_size_rows = 65535
210: optional double max_scan_mem_ratio = 0.3;
211: optional bool enable_adaptive_scan = false;
Review Comment:
`TQueryOptions` already uses field ids `210` and `211` immediately below for `max_scan_mem_ratio` / `enable_adaptive_scan`, so reusing `210`/`211`/`212` here breaks thrift compatibility instead of extending it.
Concrete failure mode: FE now writes `preferred_block_size_bytes` at id 210, but an older BE will deserialize id 210 as `max_scan_mem_ratio`; similarly id 211 will be read as `enable_adaptive_scan`. Even on same-version builds, duplicate field ids in one thrift struct are unsafe and codegen-dependent.
Please move the new adaptive-batch fields to fresh ids greater than the current maximum and keep the existing ids stable.
##########
be/src/storage/iterator/vcollect_iterator.cpp:
##########
@@ -913,6 +914,25 @@ Status VCollectIterator::Level1Iterator::_merge_next(Block* block) {
continuous_row_in_block = 0;
pre_row_ref = cur_row;
}
+
+ // Byte-budget check: _merge_next() has already advanced _ref to the next unread row,
+ // so it is safe to stop here without duplicating any data.
+ if (config::enable_adaptive_batch_size && _reader->preferred_block_size_bytes() > 0 &&
+ Block::columns_byte_size(target_columns) >= _reader->preferred_block_size_bytes()) {
+ if (continuous_row_in_block > 0) {
Review Comment:
This byte-budget check runs **before** the pending `continuous_row_in_block` slice is flushed into `target_columns`, so on the merge path it measures only a partial block.
Concrete scenario: if a child block contributes a long contiguous run (for example a wide string column from overlapping rowsets), `target_columns` can still be below the threshold here while `continuous_row_in_block` already holds many unread bytes. The code then flushes that run only after the check and can return a block far above `preferred_block_size_bytes`.
Because the PR description promises that `VCollectIterator` also bounds the final output block size, I think the budget should be checked **after** accounting for the buffered run (or the buffered bytes should be included in the estimate) before deciding whether to stop. Otherwise overlapping-rowset reads keep the old oversized-block behavior on this path.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4174208431
run buildall
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4252065492
# FE Regression Coverage Report
Increment line coverage ` 71.43% (10/14)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_d4d5d5f9628109e8fd7fc00ceaf529d5bf8dd0c6_merge_fe/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_d4d5d5f9628109e8fd7fc00ceaf529d5bf8dd0c6_merge_fe/report/index.html)
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4256534341
# FE UT Coverage Report
Increment line coverage ` 28.57% (4/14)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_d4d5d5f9628109e8fd7fc00ceaf529d5bf8dd0c6/fe_increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_d4d5d5f9628109e8fd7fc00ceaf529d5bf8dd0c6/fe_report/index.html)
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3122460908
##########
be/src/exec/common/hash_table/join_hash_table.h:
##########
@@ -178,27 +187,28 @@ class JoinHashTable {
* select 'a' not in ('b', null) => null => 'a' != 'b' and 'a' != null => true and null => null
* select 'a' not in ('a', 'b', null) => false
*/
- auto find_null_aware_with_other_conjuncts(const Key* __restrict keys,
- const uint32_t* __restrict build_idx_map,
- int probe_idx, uint32_t build_idx, int probe_rows,
- uint32_t* __restrict probe_idxs,
- uint32_t* __restrict build_idxs,
- uint8_t* __restrict null_flags,
- bool picking_null_keys, const uint8_t* null_map) {
+ auto find_null_aware_with_other_conjuncts(
+ const Key* __restrict keys, const uint32_t* __restrict build_idx_map, int probe_idx,
+ uint32_t build_idx, int probe_rows, uint32_t* __restrict probe_idxs,
+ uint32_t* __restrict build_idxs, uint8_t* __restrict null_flags, bool picking_null_keys,
+ const uint8_t* null_map, int batch_size_limit = 0) {
Review Comment:
why set a default value here?
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3123053235
##########
be/src/exec/operator/olap_scan_operator.h:
##########
@@ -313,6 +313,9 @@ class OlapScanLocalState final : public ScanLocalState<OlapScanLocalState> {
// Variant subtree: times selecting doc snapshot all iterator (merge doc snapshot into root)
RuntimeProfile::Counter* _variant_doc_value_column_iter_count = nullptr;
+ RuntimeProfile::HighWaterMarkCounter* _adaptive_batch_predict_min_rows_counter = nullptr;
Review Comment:
既然我们所有的operator 都在adptive batch size,这种统计的counter 应该放到operator 里才可以
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3123029685
##########
be/src/exec/exchange/vdata_stream_sender.cpp:
##########
@@ -310,7 +313,8 @@ Status BlockSerializer::next_serialized_block(Block* block, PBlock* dest, size_t
}
if (_mutable_block->rows() >= _batch_size || eos ||
- (_mutable_block->rows() > 0 && _mutable_block->allocated_bytes() > _buffer_mem_limit)) {
+ (_mutable_block->rows() > 0 && _mutable_block->allocated_bytes() > _buffer_mem_limit) ||
Review Comment:
这个条件里,为什么要_mutable_block->rows() > 0? 但是 _mutable_block->bytes() 这个就不需要?
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "velodb-robyang (via GitHub)" <gi...@apache.org>.
velodb-robyang commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3071373957
##########
fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java:
##########
@@ -1289,6 +1293,26 @@ public void checkQuerySlotCount(String slotCnt) {
@VarAttrDef.VarAttr(name = BROKER_LOAD_BATCH_SIZE, fuzzy = true, checker = "checkBatchSize")
public int brokerLoadBatchSize = 16352;
+ // Target output block size in bytes for adaptive batch size. 0 disables the byte limit.
+ // Default 8MB. Passed to storage layer to control how many rows each SegmentIterator chunk
+ // should contain so the final Block stays near this size.
+ @VarAttrDef.VarAttr(name = PREFERRED_BLOCK_SIZE_BYTES, needForward = true,
+ description = {"目标输出 Block 字节数上限,自适应 batch size 功能使用,0 表示不限制,默认 8MB",
+ "Target output block size in bytes for adaptive batch size. 0 disables the limit. Default 8MB."})
+ public long preferredBlockSizeBytes = 8388608L; // 8MB
+
+ // Target output block row count limit for adaptive batch size. Default 65535.
+ @VarAttrDef.VarAttr(name = PREFERRED_BLOCK_SIZE_ROWS, needForward = true,
+ description = {"目标输出 Block 行数上限,自适应 batch size 功能使用,默认 65535",
+ "Target output block row count limit for adaptive batch size. Default 65535."})
+ public long preferredBlockSizeRows = 65535L;
Review Comment:
这个跟batch size 是啥关系?
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4189925823
# Cloud UT Coverage Report
Increment line coverage ` ` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/a6852d1b3244bc2b4b0e0ed25aad98b25f80599e_a6852d1b3244bc2b4b0e0ed25aad98b25f80599e_cloud/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/a6852d1b3244bc2b4b0e0ed25aad98b25f80599e_a6852d1b3244bc2b4b0e0ed25aad98b25f80599e_cloud/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 78.48% (1798/2291) |
| Line Coverage | 64.16% (32277/50310) |
| Region Coverage | 65.04% (16186/24886) |
| Branch Coverage | 55.51% (8627/15542) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4100098770
# BE UT Coverage Report
Increment line coverage ` ` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/ae43fe96d6a20040c16d54f6ee49141576a11c2a_ae43fe96d6a20040c16d54f6ee49141576a11c2a/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/ae43fe96d6a20040c16d54f6ee49141576a11c2a_ae43fe96d6a20040c16d54f6ee49141576a11c2a/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 52.80% (19860/37616) |
| Line Coverage | 36.28% (185340/510878) |
| Region Coverage | 32.54% (143556/441152) |
| Branch Coverage | 33.73% (62850/186327) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4101451182
<details>
<summary>TPC-H: <b>Total hot run time: 26528 ms</b></summary>
```
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit ae43fe96d6a20040c16d54f6ee49141576a11c2a, data reload: false
------ Round 1 ----------------------------------
orders Doris NULL NULL 0 0 0 NULL 0 NULL NULL 2023-12-26 18:27:23 2023-12-26 18:42:55 NULL utf-8 NULL NULL
============================================
q1 16921 4568 4330 4330
q2 q3 10395 787 521 521
q4 4687 356 257 257
q5 7572 1217 995 995
q6 168 172 146 146
q7 785 852 673 673
q8 9335 1455 1313 1313
q9 4828 4768 4620 4620
q10 6236 1918 1617 1617
q11 448 265 243 243
q12 694 582 468 468
q13 18037 2983 2184 2184
q14 234 234 216 216
q15 q16 735 745 689 689
q17 724 844 427 427
q18 5822 5439 5196 5196
q19 1115 981 617 617
q20 528 495 365 365
q21 4411 1855 1413 1413
q22 335 297 238 238
Total cold run time: 94010 ms
Total hot run time: 26528 ms
----- Round 2, with runtime_filter_mode=off -----
orders Doris NULL NULL 150000000 42 6422171781 NULL 22778155 NULL NULL 2023-12-26 18:27:23 2023-12-26 18:42:55 NULL utf-8 NULL NULL
============================================
q1 4890 4658 4594 4594
q2 q3 3900 4490 3870 3870
q4 905 1212 779 779
q5 4058 4350 4343 4343
q6 193 181 145 145
q7 1775 1660 1651 1651
q8 2575 2705 2561 2561
q9 7498 7300 7357 7300
q10 3737 3983 3606 3606
q11 510 450 449 449
q12 503 635 475 475
q13 2721 3157 2469 2469
q14 295 303 282 282
q15 q16 739 836 742 742
q17 1217 1318 1415 1318
q18 7172 6692 6694 6692
q19 896 876 896 876
q20 2061 2130 2011 2011
q21 3995 3533 3365 3365
q22 494 438 391 391
Total cold run time: 50134 ms
Total hot run time: 47919 ms
```
</details>
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4097304479
# BE Regression && UT Coverage Report
Increment line coverage `100% (0/0)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_f404b067c8aa7622413fd7d269235aaccd195121_merge/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_f404b067c8aa7622413fd7d269235aaccd195121_merge/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 73.32% (26985/36806) |
| Line Coverage | 56.83% (289314/509111) |
| Region Coverage | 54.07% (240723/445178) |
| Branch Coverage | 55.85% (104336/186800) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "Gabriel39 (via GitHub)" <gi...@apache.org>.
Gabriel39 commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r2986062897
##########
be/src/storage/segment/adaptive_block_size_predictor.cpp:
##########
@@ -0,0 +1,138 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "storage/segment/adaptive_block_size_predictor.h"
+
+#include <algorithm>
+#include <cstddef>
+
+#include "core/block/block.h"
+#include "storage/segment/segment.h"
+#include "storage/tablet/tablet_schema.h"
+
+namespace doris::segment_v2 {
+
+AdaptiveBlockSizePredictor::AdaptiveBlockSizePredictor(size_t preferred_block_size_bytes,
+ size_t preferred_max_col_bytes,
+ const Segment& segment,
+ const std::vector<ColumnId>& output_columns)
+ : _block_size_bytes(preferred_block_size_bytes), _max_col_bytes(preferred_max_col_bytes) {
+ // Compute metadata hint from cached per-column raw_data_bytes in Segment.
+ // Segment::column_raw_data_bytes() is a read-only map lookup, thread-safe.
+ uint32_t seg_rows = segment.num_rows();
+ if (seg_rows > 0) {
+ const auto& ts = segment.tablet_schema();
+ if (ts) {
+ double total_bytes = 0.0;
+ uint64_t matched_cols = 0;
+ for (ColumnId cid : output_columns) {
+ if (static_cast<size_t>(cid) < ts->num_columns()) {
+ int32_t uid = ts->column(cid).unique_id();
+ uint64_t raw_bytes = segment.column_raw_data_bytes(uid);
+ if (uid >= 0 && raw_bytes > 0) {
+ double col_bpr =
+ static_cast<double>(raw_bytes) / static_cast<double>(seg_rows);
+ _col_bytes_per_row[cid] = col_bpr;
+ total_bytes += static_cast<double>(raw_bytes);
+ matched_cols++;
+ }
+ }
+ }
+ if (matched_cols > 0 && total_bytes > 0.0) {
+ _metadata_hint_bytes_per_row = (total_bytes / static_cast<double>(seg_rows)) * 1.2;
Review Comment:
What does `1.2` mean?
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4174328748
# Cloud UT Coverage Report
Increment line coverage ` ` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/eee985b7d8c909cb70ddac3af54a70d35d76ba9a_eee985b7d8c909cb70ddac3af54a70d35d76ba9a_cloud/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/eee985b7d8c909cb70ddac3af54a70d35d76ba9a_eee985b7d8c909cb70ddac3af54a70d35d76ba9a_cloud/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 78.48% (1798/2291) |
| Line Coverage | 64.15% (32273/50310) |
| Region Coverage | 64.99% (16173/24886) |
| Branch Coverage | 55.46% (8619/15542) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3044480697
##########
be/src/storage/iterator/vcollect_iterator.cpp:
##########
@@ -490,10 +497,56 @@ Status VCollectIterator::_topn_next(Block* block) {
<< " mutable_block.rows()=" << mutable_block.rows();
*block = mutable_block.to_block();
+ // If byte budget is active and the result exceeds it, split into chunks.
+ size_t preferred_bytes = _reader->preferred_block_size_bytes();
+ if (preferred_bytes > 0 && block->rows() > 1 && block->bytes() > preferred_bytes) {
+ _topn_result_block = std::move(*block);
+ _topn_result_offset = 0;
+ return _topn_next_chunk(block);
+ }
+
_topn_eof = true;
return block->rows() > 0 ? Status::OK() : Status::Error<END_OF_FILE>("");
}
+Status VCollectIterator::_topn_next_chunk(Block* block) {
+ size_t total_rows = _topn_result_block.rows();
+ if (_topn_result_offset >= total_rows) {
+ _topn_result_block.clear();
+ _topn_eof = true;
+ return Status::Error<END_OF_FILE>("");
+ }
+
+ size_t remaining = total_rows - _topn_result_offset;
+ size_t chunk_rows = remaining;
+
+ // Cap by batch_max_rows.
+ chunk_rows = std::min(chunk_rows, (size_t)_reader->batch_max_rows());
+
+ // Cap by byte budget.
Review Comment:
This still does not guarantee the chunk respects preferred_block_size_bytes. chunk_rows is derived from the full result average row size, so a skewed TopN result, for example a few very wide rows followed by many narrow rows, can produce a first chunk whose real bytes are far above the budget even though the average says it is safe. If this path is supposed to enforce the byte cap, it needs a byte-aware cut over the actual rows being copied, not a global average.
##########
be/src/exec/operator/nested_loop_join_probe_operator.cpp:
##########
@@ -194,7 +194,10 @@ void NestedLoopJoinProbeLocalState::_generate_block_base_probe(RuntimeState* sta
return build_blocks[_current_build_pos].rows();
};
- while (_join_block.rows() + add_rows() <= state->batch_size()) {
+ const auto block_max_bytes = state->block_max_bytes();
+ size_t effective_max_rows = state->block_max_rows();
+ bool bytes_estimated = false;
Review Comment:
effective_max_rows only becomes byte-aware after the first process_probe_block() or process_build_block() append. That means the first iteration can still materialize a full build or probe chunk based only on row count and blow far past preferred_block_size_bytes on wide rows. The same late adjustment pattern is duplicated in _generate_block_base_build(), so this is still not a real byte-budget bound for nested-loop join output.
##########
be/src/exec/operator/distinct_streaming_aggregation_operator.cpp:
##########
@@ -207,16 +208,31 @@ Status DistinctStreamingAggLocalState::_distinct_pre_agg_with_serialized_key(
}
} else {
DCHECK_EQ(_cache_block.rows(), 0);
- // is output row > batch_size, split some to cache_block
- if (out_block->rows() + _distinct_row.size() > batch_size) {
- size_t split_size = batch_size - out_block->rows();
+ // Compute maximum additional rows for out_block respecting both
+ // row limit (batch_size) and byte budget (block_max_bytes).
+ size_t max_rows_to_add = (out_block->rows() < (size_t)batch_size)
+ ? ((size_t)batch_size - out_block->rows())
+ : 0;
+ if (block_max_bytes > 0 && out_block->rows() > 0) {
+ size_t current_bytes = out_block->bytes();
+ if (current_bytes >= block_max_bytes) {
+ max_rows_to_add = 0;
+ } else {
+ size_t avg_row_bytes = current_bytes / out_block->rows();
+ if (avg_row_bytes > 0) {
+ size_t rows_for_budget = (block_max_bytes - current_bytes) / avg_row_bytes;
Review Comment:
Using out_block->bytes() / out_block->rows() here does not actually bound the bytes added by the rows in _distinct_row. If the buffered rows are narrow but the next distinct key is wide, such as large STRING, JSON, or VARIANT values, rows_for_budget can still be at least 1 and this push emits a block far above preferred_block_size_bytes. To preserve the new contract, this split needs to account for the candidate rows bytes themselves, not just the historical average of the already-buffered rows.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3044497622
##########
be/src/runtime/runtime_state.h:
##########
@@ -138,7 +138,42 @@ class RuntimeState {
const DescriptorTbl& desc_tbl() const { return *_desc_tbl; }
void set_desc_tbl(const DescriptorTbl* desc_tbl) { _desc_tbl = desc_tbl; }
+
+ MOCK_FUNCTION int block_max_rows() const {
+ if (config::enable_adaptive_batch_size && preferred_block_size_bytes() > 0) {
+ auto rows = preferred_block_size_rows();
+ return static_cast<int>(std::min(rows, static_cast<size_t>(INT32_MAX)));
+ }
+ return _query_options.batch_size;
+ }
+
+ MOCK_FUNCTION size_t block_max_bytes() const {
+ return config::enable_adaptive_batch_size ? preferred_block_size_bytes() : 0;
+ }
+
MOCK_FUNCTION int batch_size() const { return _query_options.batch_size; }
+ MOCK_FUNCTION size_t preferred_block_size_bytes() const {
+ if (_query_options.__isset.preferred_block_size_bytes) {
+ auto v = _query_options.preferred_block_size_bytes;
+ return v > 0 ? static_cast<size_t>(v) : 0;
+ }
+ return 0;
+ }
Review Comment:
RuntimeState::preferred_block_size_bytes() returns 0 when the query option is not explicitly set (__isset is false). This makes adaptive batch sizing effectively disabled by default, which is inconsistent with the stated default of 8MB (and also inconsistent with preferred_block_size_rows()/preferred_max_column_in_block_size_bytes(), which do return defaults when unset). Consider returning 8MB when __isset is false (similar to spill_buffer_size_bytes()), so the BE-side default behavior matches the documented defaults even if an older FE doesn’t forward the new field.
##########
regression-test/suites/query_p0/adaptive_batch_size/adaptive_batch_size.groovy:
##########
@@ -0,0 +1,212 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// Regression tests for the Adaptive Batch Size feature.
+//
+// Design notes:
+// - Each case runs the same query with the feature enabled and disabled, and
+// asserts that results are identical (correctness check).
+// - We do NOT directly assert internal block byte sizes, because the storage
+// layer does not expose them via SQL result columns. Correctness is the
+// primary requirement; performance / memory reduction is verified manually
+// or via profile counters in a separate benchmark.
+
+suite("adaptive_batch_size") {
+
+ // ── helpers ────────────────────────────────────────────────────────────────
+
+ def set_adaptive = { enabled ->
+ // preferred_block_size_bytes controls the feature end-to-end.
+ // Setting it to a very small value (e.g. 1 byte) forces the predictor to
+ // return row count = 1 every time, which is a good stress test.
+ if (enabled) {
+ sql "set preferred_block_size_bytes = 8388608" // 8 MB (default)
+ sql "set batch_size = 65535"
+ sql "set preferred_max_column_in_block_size_bytes = 1048576" // 1 MB
+ } else {
+ // Setting to 0 disables the byte-limit path at the accumulation layer.
+ sql "set preferred_block_size_bytes = 0"
+ sql "set batch_size = 4096"
+ sql "set preferred_max_column_in_block_size_bytes = 0"
+ }
+ }
+
+ // ── Test 1: wide table (VARCHAR columns) ──────────────────────────────────
+ // Each row is ~10 KB; with 4096 rows that is ~40 MB/batch which OOM-risks.
+ // With adaptive=on the batch is trimmed to ~8 MB worth of rows.
+
+ sql "drop table if exists abs_wide_table"
+ sql """
+ create table abs_wide_table (
+ id int not null,
+ c1 varchar(4096),
+ c2 varchar(4096),
+ c3 varchar(4096)
+ )
+ ENGINE=OLAP
+ DUPLICATE KEY(id)
+ DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES ("replication_allocation" = "tag.location.default: 1")
+ """
+
+ // Insert 1000 rows with ~3 KB data each.
+ def wide_rows = (1..1000).collect { i ->
+ "(${i}, '${('a' * 1000)}', '${('b' * 1000)}', '${('c' * 1000)}')"
+ }
+ sql "insert into abs_wide_table values ${wide_rows.join(',')}"
+
Review Comment:
The wide-table data load builds a single INSERT statement with 1000 rows of ~3KB string literals (wide_rows.join(',')), which can produce a multi‑MB SQL string. This risks exceeding max query length / max_packet limits in some CI environments and can make the regression suite flaky/slow. Prefer generating the data on the BE side (e.g., INSERT…SELECT from numbers() with repeat()/lpad(), or inserting in smaller batches) to keep the statement size bounded.
##########
be/src/storage/iterator/vcollect_iterator.cpp:
##########
@@ -913,6 +1006,24 @@ Status VCollectIterator::Level1Iterator::_merge_next(Block* block) {
continuous_row_in_block = 0;
pre_row_ref = cur_row;
}
+
+ // Byte-budget check: _merge_next() has already advanced _ref to the next unread row,
+ // so it is safe to stop here without duplicating any data.
+ if (collected_enough_rows(target_columns, continuous_row_in_block)) {
+ if (continuous_row_in_block > 0) {
Review Comment:
In Level1Iterator::_merge_next(), collected_enough_rows() is evaluated on every loop iteration. That call recomputes Block::columns_byte_size(columns) by summing byte_size() across all columns each time, which makes the merge loop O(rows * columns) and can be a noticeable CPU regression on wide schemas. Consider checking the byte budget only every N rows (similar to BlockReader’s interval checks), or maintaining an incremental byte counter updated when ranges are inserted, so you avoid rescanning all columns per row.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3043610154
##########
be/src/storage/tablet/tablet_reader.h:
##########
@@ -251,6 +252,31 @@ class TabletReader {
int batch_size() const { return _reader_context.batch_size; }
+ // Return the effective maximum row count for output blocks.
+ // When adaptive batch sizing is enabled, prefer preferred_block_size_rows;
+ // otherwise fall back to the traditional batch_size.
+ size_t batch_max_rows() const {
+ if (config::enable_adaptive_batch_size && _reader_context.preferred_block_size_rows > 0) {
+ return _reader_context.preferred_block_size_rows;
+ }
+ return _reader_context.batch_size;
+ }
Review Comment:
batch_max_rows() switches to preferred_block_size_rows whenever enable_adaptive_batch_size is true, regardless of whether preferred_block_size_bytes is 0. If `preferred_block_size_bytes=0` is intended to fully disable adaptive sizing (per PR description), this still changes behavior vs the legacy fixed batch_size row cap. Consider also gating the preferred_block_size_rows branch on preferred_block_size_bytes>0 (or explicitly documenting that rows-only expansion remains enabled when bytes is 0).
##########
regression-test/suites/query_p0/adaptive_batch_size/adaptive_batch_size.groovy:
##########
@@ -0,0 +1,220 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// Regression tests for the Adaptive Batch Size feature.
+//
+// Design notes:
+// - Each case runs the same query with the feature enabled and disabled, and
+// asserts that results are identical (correctness check).
+// - We do NOT directly assert internal block byte sizes, because the storage
+// layer does not expose them via SQL result columns. Correctness is the
+// primary requirement; performance / memory reduction is verified manually
+// or via profile counters in a separate benchmark.
+
+suite("adaptive_batch_size") {
+
+ // ── helpers ────────────────────────────────────────────────────────────────
+
+ def set_adaptive = { enabled ->
+ // preferred_block_size_bytes controls the feature end-to-end.
+ // Setting it to a very small value (e.g. 1 byte) forces the predictor to
+ // return row count = 1 every time, which is a good stress test.
+ if (enabled) {
+ sql "set preferred_block_size_bytes = 8388608" // 8 MB (default)
+ sql "set batch_size = 65535"
+ sql "set preferred_max_column_in_block_size_bytes = 1048576" // 1 MB
+ } else {
+ // Setting to 0 disables the byte-limit path at the accumulation layer.
+ sql "set preferred_block_size_bytes = 0"
+ sql "set batch_size = 4096"
+ sql "set preferred_max_column_in_block_size_bytes = 0"
+ }
+ }
+
+ // ── Test 1: wide table (VARCHAR columns) ──────────────────────────────────
+ // Each row is ~10 KB; with 4096 rows that is ~40 MB/batch which OOM-risks.
+ // With adaptive=on the batch is trimmed to ~8 MB worth of rows.
+
+ sql "drop table if exists abs_wide_table"
+ sql """
+ create table abs_wide_table (
+ id int not null,
+ c1 varchar(4096),
+ c2 varchar(4096),
+ c3 varchar(4096)
+ )
+ ENGINE=OLAP
+ DUPLICATE KEY(id)
+ DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES ("replication_allocation" = "tag.location.default: 1")
+ """
+
+ // Insert 1000 rows with ~3 KB data each.
+ def wide_rows = (1..1000).collect { i ->
+ "(${i}, '${('a' * 1000)}', '${('b' * 1000)}', '${('c' * 1000)}')"
+ }
+ sql "insert into abs_wide_table values ${wide_rows.join(',')}"
+
+ // Run query with adaptive enabled and collect result.
+ set_adaptive(true)
+ def res_enabled = sql "select id, length(c1) as l1, length(c2) as l2, length(c3) as l3 from abs_wide_table order by 1, 2, 3, 4"
+
+ qt_wide "select id, length(c1) as l1, length(c2) as l2, length(c3) as l3 from abs_wide_table order by 1, 2, 3, 4 limit 50"
+
+ // Run query with adaptive disabled and collect result.
+ set_adaptive(false)
+ def res_disabled = sql "select id, length(c1) as l1, length(c2) as l2, length(c3) as l3 from abs_wide_table order by 1, 2, 3, 4"
+
+ // Results must be identical.
+ assertEquals(res_enabled.size(), res_disabled.size())
+ for (int i = 0; i < res_enabled.size(); i++) {
+ assertEquals(res_enabled[i].toString(), res_disabled[i].toString())
+ }
+
+ // sql "drop table abs_wide_table"
Review Comment:
abs_wide_table is created and populated, but the DROP at the end of Test 1 is commented out. Leaving the table behind can pollute the test environment and potentially affect reruns or later suites. Consider dropping abs_wide_table (like the other test tables) during cleanup.
##########
be/src/runtime/runtime_state.h:
##########
@@ -138,7 +138,40 @@ class RuntimeState {
const DescriptorTbl& desc_tbl() const { return *_desc_tbl; }
void set_desc_tbl(const DescriptorTbl* desc_tbl) { _desc_tbl = desc_tbl; }
+
+ MOCK_FUNCTION int block_max_rows() const {
+ return config::enable_adaptive_batch_size
+ ? std::max(_query_options.batch_size, int(preferred_block_size_rows()))
+ : _query_options.batch_size;
+ }
Review Comment:
block_max_rows() is currently gated only by config::enable_adaptive_batch_size, not by whether the query’s byte budget is enabled. As a result, `preferred_block_size_bytes = 0` (the documented disable switch) still leaves block_max_rows() potentially much larger than batch_size (e.g. 65535), which can change legacy behavior and risk large blocks for wide rows. Consider gating the preferred_block_size_rows path on preferred_block_size_bytes()>0 (or ensuring FE sets preferred_block_size_rows=0 when bytes=0) so “disable” truly restores the fixed-row behavior.
##########
regression-test/suites/query_p0/adaptive_batch_size/adaptive_batch_size.groovy:
##########
@@ -0,0 +1,220 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// Regression tests for the Adaptive Batch Size feature.
+//
+// Design notes:
+// - Each case runs the same query with the feature enabled and disabled, and
+// asserts that results are identical (correctness check).
+// - We do NOT directly assert internal block byte sizes, because the storage
+// layer does not expose them via SQL result columns. Correctness is the
+// primary requirement; performance / memory reduction is verified manually
+// or via profile counters in a separate benchmark.
+
+suite("adaptive_batch_size") {
+
+ // ── helpers ────────────────────────────────────────────────────────────────
+
+ def set_adaptive = { enabled ->
+ // preferred_block_size_bytes controls the feature end-to-end.
+ // Setting it to a very small value (e.g. 1 byte) forces the predictor to
+ // return row count = 1 every time, which is a good stress test.
+ if (enabled) {
+ sql "set preferred_block_size_bytes = 8388608" // 8 MB (default)
+ sql "set batch_size = 65535"
+ sql "set preferred_max_column_in_block_size_bytes = 1048576" // 1 MB
+ } else {
+ // Setting to 0 disables the byte-limit path at the accumulation layer.
+ sql "set preferred_block_size_bytes = 0"
+ sql "set batch_size = 4096"
+ sql "set preferred_max_column_in_block_size_bytes = 0"
+ }
Review Comment:
This suite modifies multiple session variables (e.g. batch_size) but only resets preferred_block_size_bytes and preferred_max_column_in_block_size_bytes at the end. Leaving batch_size / preferred_block_size_rows at non-default values can leak into subsequent suites if they share the same session. Suggest resetting all modified vars back to defaults in the cleanup section.
##########
regression-test/suites/query_p0/adaptive_batch_size/adaptive_batch_size.groovy:
##########
@@ -0,0 +1,220 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// Regression tests for the Adaptive Batch Size feature.
+//
+// Design notes:
+// - Each case runs the same query with the feature enabled and disabled, and
+// asserts that results are identical (correctness check).
+// - We do NOT directly assert internal block byte sizes, because the storage
+// layer does not expose them via SQL result columns. Correctness is the
+// primary requirement; performance / memory reduction is verified manually
+// or via profile counters in a separate benchmark.
+
+suite("adaptive_batch_size") {
+
+ // ── helpers ────────────────────────────────────────────────────────────────
+
+ def set_adaptive = { enabled ->
+ // preferred_block_size_bytes controls the feature end-to-end.
+ // Setting it to a very small value (e.g. 1 byte) forces the predictor to
+ // return row count = 1 every time, which is a good stress test.
+ if (enabled) {
+ sql "set preferred_block_size_bytes = 8388608" // 8 MB (default)
+ sql "set batch_size = 65535"
+ sql "set preferred_max_column_in_block_size_bytes = 1048576" // 1 MB
+ } else {
+ // Setting to 0 disables the byte-limit path at the accumulation layer.
+ sql "set preferred_block_size_bytes = 0"
+ sql "set batch_size = 4096"
+ sql "set preferred_max_column_in_block_size_bytes = 0"
+ }
Review Comment:
The disabled branch only sets preferred_block_size_bytes=0, but does not reset preferred_block_size_rows. Since many operators now use block_max_rows(), leaving preferred_block_size_rows at its default (65535) can still change behavior compared to legacy fixed batch_size=4096. If the intent is “fixed row count only” when disabled, consider also setting preferred_block_size_rows to 0 (or to batch_size) in the disabled branch.
##########
be/test/storage/iterator/vcollect_iterator_collected_enough_test.cpp:
##########
@@ -0,0 +1,384 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gtest/gtest.h>
+
+#include <cstddef>
+#include <cstdint>
+#include <limits>
+#include <string>
+
+#include "common/config.h"
+#include "core/block/block.h"
+#include "core/column/column_string.h"
+#include "core/column/column_vector.h"
+#include "storage/iterator/block_reader.h"
+#include "storage/iterator/vcollect_iterator.h"
+
+namespace doris {
+
+// ============================================================================
+// Part 1: Pure-computation tests for estimate_collected_enough()
+// ============================================================================
+
+class EstimateCollectedEnoughTest : public testing::Test {};
+
+// Budget is 0 → always false (feature disabled).
+TEST_F(EstimateCollectedEnoughTest, BudgetZeroReturnsFalse) {
+ EXPECT_FALSE(estimate_collected_enough(/*present_bytes=*/1000, /*present_rows=*/10,
+ /*rows_to_merge=*/5,
+ /*preferred_block_size_bytes=*/0));
+}
+
+// No rows collected yet → always false (cannot estimate).
+TEST_F(EstimateCollectedEnoughTest, ZeroRowsReturnsFalse) {
+ EXPECT_FALSE(estimate_collected_enough(/*present_bytes=*/0, /*present_rows=*/0,
+ /*rows_to_merge=*/5,
+ /*preferred_block_size_bytes=*/1024));
+}
+
+// Present bytes already exceed budget → true.
+TEST_F(EstimateCollectedEnoughTest, PresentBytesExceedBudget) {
+ EXPECT_TRUE(estimate_collected_enough(/*present_bytes=*/2048, /*present_rows=*/10,
+ /*rows_to_merge=*/0,
+ /*preferred_block_size_bytes=*/1024));
+}
+
+// Present bytes exactly equal budget → true.
+TEST_F(EstimateCollectedEnoughTest, PresentBytesEqualBudget) {
+ EXPECT_TRUE(estimate_collected_enough(/*present_bytes=*/1024, /*present_rows=*/10,
+ /*rows_to_merge=*/0,
+ /*preferred_block_size_bytes=*/1024));
+}
+
+// Prediction: 500 bytes / 10 rows = 50 bytes/row.
+// With 10 pending rows → predicted 500 + 500 = 1000 < 1024 → false.
+TEST_F(EstimateCollectedEnoughTest, PredictionBelowBudget) {
+ EXPECT_FALSE(estimate_collected_enough(/*present_bytes=*/500, /*present_rows=*/10,
+ /*rows_to_merge=*/10,
+ /*preferred_block_size_bytes=*/1024));
+}
+
+// Prediction: 500 bytes / 10 rows = 50 bytes/row.
+// With 11 pending rows → predicted 500 * 21 / 10 = 1050 >= 1024 → true.
+TEST_F(EstimateCollectedEnoughTest, PredictionMeetsBudget) {
+ EXPECT_TRUE(estimate_collected_enough(/*present_bytes=*/500, /*present_rows=*/10,
+ /*rows_to_merge=*/11,
+ /*preferred_block_size_bytes=*/1024));
+}
+
+// Zero pending rows: prediction = present_bytes (no pending rows to flush).
+// 500 < 1024 → false.
+TEST_F(EstimateCollectedEnoughTest, ZeroPendingRows) {
+ EXPECT_FALSE(estimate_collected_enough(/*present_bytes=*/500, /*present_rows=*/10,
+ /*rows_to_merge=*/0,
+ /*preferred_block_size_bytes=*/1024));
+}
+
+// Exact boundary: 512 bytes / 8 rows = 64 bytes/row. With 8 pending rows →
+// predicted 512 * 16 / 8 = 1024 = budget → true.
+TEST_F(EstimateCollectedEnoughTest, ExactBudgetBoundary) {
+ EXPECT_TRUE(estimate_collected_enough(/*present_bytes=*/512, /*present_rows=*/8,
+ /*rows_to_merge=*/8,
+ /*preferred_block_size_bytes=*/1024));
+}
+
+// One below boundary: 512 bytes / 8 rows = 64 bytes/row. With 7 pending rows →
+// predicted 512 * 15 / 8 = 960 < 1024 → false.
+TEST_F(EstimateCollectedEnoughTest, OneBelowBudgetBoundary) {
+ EXPECT_FALSE(estimate_collected_enough(/*present_bytes=*/512, /*present_rows=*/8,
+ /*rows_to_merge=*/7,
+ /*preferred_block_size_bytes=*/1024));
+}
+
+// Overflow guard: present_bytes close to SIZE_MAX; multiplication would wrap → true.
+TEST_F(EstimateCollectedEnoughTest, OverflowGuardReturnsTrueForHugeBytes) {
+ const size_t huge = std::numeric_limits<size_t>::max() / 2 + 1;
+ EXPECT_TRUE(estimate_collected_enough(/*present_bytes=*/huge, /*present_rows=*/1,
+ /*rows_to_merge=*/1,
+ /*preferred_block_size_bytes=*/1024));
+}
+
+// Large but no overflow: present_bytes * total_rows fits in size_t.
+TEST_F(EstimateCollectedEnoughTest, LargeButNoOverflow) {
+ // 1GB present, 100 rows, 100 pending → 2GB total predicted.
+ const size_t one_gb = 1ULL << 30;
+ EXPECT_TRUE(estimate_collected_enough(/*present_bytes=*/one_gb, /*present_rows=*/100,
+ /*rows_to_merge=*/100,
+ /*preferred_block_size_bytes=*/one_gb + 1));
+}
+
+// Single present row with many pending rows should scale correctly.
+// 100 bytes / 1 row → 100 bytes/row. With 99 pending → predicted 100 * 100 / 1 = 10000 >= 5000.
+TEST_F(EstimateCollectedEnoughTest, SingleRowScalesCorrectly) {
+ EXPECT_TRUE(estimate_collected_enough(/*present_bytes=*/100, /*present_rows=*/1,
+ /*rows_to_merge=*/99,
+ /*preferred_block_size_bytes=*/5000));
+}
+
+// ============================================================================
+// Part 2: Integration tests — real MutableColumns + estimate_collected_enough
+//
+// These tests exercise the same code path as collected_enough_rows():
+// present_bytes = Block::columns_byte_size(columns)
+// present_rows = columns[0]->size()
+// → estimate_collected_enough(present_bytes, present_rows, rows_to_merge, budget)
+//
+// Level1Iterator::collected_enough_rows() is a private inner class method, so
+// we replicate its logic here with real columns to verify end-to-end correctness.
+// ============================================================================
+
+class CollectedEnoughWithColumnsTest : public testing::Test {
+protected:
+ void SetUp() override { _saved_adaptive = config::enable_adaptive_batch_size; }
+ void TearDown() override { config::enable_adaptive_batch_size = _saved_adaptive; }
+
+ // Replicate the logic of Level1Iterator::collected_enough_rows() with a
+ // configurable budget, so we can test the column-byte integration path
+ // without instantiating a Level1Iterator (private inner class).
+ static bool collected_enough_rows_sim(const MutableColumns& columns, int rows_to_merge,
+ size_t preferred_block_size_bytes) {
+ if (!config::enable_adaptive_batch_size) {
+ return false;
+ }
+ if (preferred_block_size_bytes == 0) {
+ return false;
+ }
+ const auto present_bytes = Block::columns_byte_size(columns);
+ const auto present_rows = columns.empty() ? 0 : columns[0]->size();
+ return estimate_collected_enough(present_bytes, present_rows, rows_to_merge,
+ preferred_block_size_bytes);
+ }
+
+ // Build a MutableColumns with N_cols ColumnInt32 columns, each having `nrows` rows.
+ // Each Int32 is 4 bytes → total = 4 * nrows * ncols bytes.
+ static MutableColumns make_int32_columns(size_t ncols, size_t nrows) {
+ MutableColumns cols;
+ for (size_t c = 0; c < ncols; ++c) {
+ auto col = ColumnInt32::create();
+ for (size_t r = 0; r < nrows; ++r) {
+ col->insert_value(static_cast<Int32>(r));
+ }
+ cols.push_back(std::move(col));
+ }
+ return cols;
+ }
+
+ bool _saved_adaptive = false;
+};
+
+// Config disabled → always false regardless of data.
+TEST_F(CollectedEnoughWithColumnsTest, DisabledConfigReturnsFalse) {
+ config::enable_adaptive_batch_size = false;
+ auto cols = make_int32_columns(2, 100);
+ // 2 cols × 100 rows × 4 bytes = 800 bytes; budget = 100 bytes (well below)
+ EXPECT_FALSE(collected_enough_rows_sim(cols, 0, /*budget=*/100));
+}
+
+// Config enabled, budget = 0 → always false.
+TEST_F(CollectedEnoughWithColumnsTest, ZeroBudgetReturnsFalse) {
+ config::enable_adaptive_batch_size = true;
+ auto cols = make_int32_columns(2, 100);
+ EXPECT_FALSE(collected_enough_rows_sim(cols, 0, /*budget=*/0));
+}
+
+// Empty columns → present_rows = 0 → cannot estimate → false.
+TEST_F(CollectedEnoughWithColumnsTest, EmptyColumnsReturnsFalse) {
+ config::enable_adaptive_batch_size = true;
+ MutableColumns empty;
+ EXPECT_FALSE(collected_enough_rows_sim(empty, 10, /*budget=*/1024));
+}
+
+// Columns with zero rows → present_rows = 0 → false.
+TEST_F(CollectedEnoughWithColumnsTest, ZeroRowColumnsReturnsFalse) {
+ config::enable_adaptive_batch_size = true;
+ auto cols = make_int32_columns(3, 0);
+ EXPECT_FALSE(collected_enough_rows_sim(cols, 5, /*budget=*/100));
+}
+
+// Single Int32 column, 256 rows → 1024 bytes.
+// Budget = 1024 → already met → true (no pending rows needed).
+TEST_F(CollectedEnoughWithColumnsTest, SingleColumnExactBudgetMet) {
+ config::enable_adaptive_batch_size = true;
+ auto cols = make_int32_columns(1, 256);
+ // 256 rows × 4 bytes = 1024 bytes
+ EXPECT_EQ(Block::columns_byte_size(cols), 1024);
+ EXPECT_TRUE(collected_enough_rows_sim(cols, 0, /*budget=*/1024));
+}
+
+// Single Int32 column, 255 rows → 1020 bytes < 1024 budget.
+// No pending rows → not enough → false.
+TEST_F(CollectedEnoughWithColumnsTest, SingleColumnBelowBudgetNoPending) {
+ config::enable_adaptive_batch_size = true;
+ auto cols = make_int32_columns(1, 255);
+ EXPECT_EQ(Block::columns_byte_size(cols), 1020);
+ EXPECT_FALSE(collected_enough_rows_sim(cols, 0, /*budget=*/1024));
+}
+
+// Single Int32 column, 255 rows → 1020 bytes. With 1 pending row:
+// bytes_per_row = 1020/255 = 4, predicted = 1020 * 256 / 255 = 1024 → meets budget.
+TEST_F(CollectedEnoughWithColumnsTest, SingleColumnBelowBudgetWithPending) {
+ config::enable_adaptive_batch_size = true;
+ auto cols = make_int32_columns(1, 255);
+ EXPECT_TRUE(collected_enough_rows_sim(cols, 1, /*budget=*/1024));
+}
+
+// Multi-column: 4 Int32 columns × 100 rows = 1600 bytes.
+// Budget = 2000 → not met. With 25 pending rows:
+// predicted = 1600 * 125 / 100 = 2000 → meets budget.
+TEST_F(CollectedEnoughWithColumnsTest, MultiColumnPredictionMeetsBudget) {
+ config::enable_adaptive_batch_size = true;
+ auto cols = make_int32_columns(4, 100);
+ EXPECT_EQ(Block::columns_byte_size(cols), 1600);
+ EXPECT_FALSE(collected_enough_rows_sim(cols, 0, /*budget=*/2000));
+ EXPECT_TRUE(collected_enough_rows_sim(cols, 25, /*budget=*/2000));
+}
+
+// Multi-column: just one row below the prediction threshold.
+// 4 cols × 100 rows = 1600 bytes, 24 pending rows:
+// predicted = 1600 * 124 / 100 = 1984 < 2000 → false.
+TEST_F(CollectedEnoughWithColumnsTest, MultiColumnOneBelowPrediction) {
+ config::enable_adaptive_batch_size = true;
+ auto cols = make_int32_columns(4, 100);
+ EXPECT_FALSE(collected_enough_rows_sim(cols, 24, /*budget=*/2000));
+}
+
+// Variable-width column: ColumnString with known data sizes.
+// ColumnString::byte_size() = chars_size + offsets_size.
+// Each offset is sizeof(IColumn::Offset) = 8 bytes (64-bit).
+TEST_F(CollectedEnoughWithColumnsTest, StringColumnByteSizeIntegration) {
+ config::enable_adaptive_batch_size = true;
+
+ auto str_col = ColumnString::create();
+ // Insert 10 strings of 10 chars each → chars = 100 bytes, offsets = 10 * 8 = 80.
+ // Total byte_size = 180 bytes.
+ for (int i = 0; i < 10; ++i) {
+ std::string s(10, 'A' + (i % 26));
+ str_col->insert_data(s.data(), s.size());
+ }
+
+ const size_t expected_bytes = 10 * 10 + 10 * sizeof(IColumn::Offset);
+ EXPECT_EQ(str_col->byte_size(), expected_bytes);
+
+ MutableColumns cols;
+ cols.push_back(std::move(str_col));
+
+ // Budget = expected_bytes → met → true.
+ EXPECT_TRUE(collected_enough_rows_sim(cols, 0, /*budget=*/expected_bytes));
+ // Budget = expected_bytes + 1 → not met with 0 pending → false.
+ EXPECT_FALSE(collected_enough_rows_sim(cols, 0, /*budget=*/expected_bytes + 1));
+}
+
+// Mixed columns: Int32 + String together.
+TEST_F(CollectedEnoughWithColumnsTest, MixedColumnTypes) {
+ config::enable_adaptive_batch_size = true;
+
+ auto int_col = ColumnInt32::create();
+ auto str_col = ColumnString::create();
+ for (int i = 0; i < 50; ++i) {
+ int_col->insert_value(static_cast<Int32>(i));
+ std::string s(20, 'x');
+ str_col->insert_data(s.data(), s.size());
+ }
+ // Int32: 50 × 4 = 200 bytes
+ // String: 50 × 20 chars + 50 × 8 offsets = 1000 + 400 = 1400 bytes
+ // Total: 1600 bytes
+ const size_t int_bytes = 50 * sizeof(Int32);
+ const size_t str_bytes = 50 * 20 + 50 * sizeof(IColumn::Offset);
+ EXPECT_EQ(int_col->byte_size(), int_bytes);
+ EXPECT_EQ(str_col->byte_size(), str_bytes);
+
+ MutableColumns cols;
+ cols.push_back(std::move(int_col));
+ cols.push_back(std::move(str_col));
+
+ const size_t total = int_bytes + str_bytes;
+ EXPECT_EQ(Block::columns_byte_size(cols), total);
+
+ // Budget met exactly → true.
+ EXPECT_TRUE(collected_enough_rows_sim(cols, 0, /*budget=*/total));
+ // Budget slightly above → not met with 0 pending → false.
+ EXPECT_FALSE(collected_enough_rows_sim(cols, 0, /*budget=*/total + 1));
+ // With 1 pending row: predicted = total * 51 / 50 = total + total/50.
+ // So meets budget = total + total/50.
+ EXPECT_TRUE(collected_enough_rows_sim(cols, 1, /*budget=*/total + total / 50));
+}
+
+// Large number of rows to verify no integer issues with real column byte sizes.
+TEST_F(CollectedEnoughWithColumnsTest, LargeRowCountInt32) {
+ config::enable_adaptive_batch_size = true;
+ auto cols = make_int32_columns(1, 100000);
+ // 100000 × 4 = 400000 bytes
+ EXPECT_EQ(Block::columns_byte_size(cols), 400000);
+ EXPECT_TRUE(collected_enough_rows_sim(cols, 0, /*budget=*/400000));
+ EXPECT_FALSE(collected_enough_rows_sim(cols, 0, /*budget=*/400001));
+ // With 1 pending: predicted = 400000 * 100001 / 100000 = 400004 < 400005 → false
+ EXPECT_FALSE(collected_enough_rows_sim(cols, 1, /*budget=*/400005));
+ // predicted = 400004 >= 400004 → true
+ EXPECT_TRUE(collected_enough_rows_sim(cols, 1, /*budget=*/400004));
+}
+
+// ============================================================================
+// Part 3: BlockReader.preferred_block_size_bytes() override tests
+//
+// BlockReader overrides TabletReader::preferred_block_size_bytes() to gate on
+// config::enable_adaptive_batch_size. These tests verify that behavior and
+// ensure collected_enough_rows() would receive the correct budget value.
+// ============================================================================
+
+class BlockReaderByteBudgetTest : public testing::Test {
+protected:
+ void SetUp() override { _saved_adaptive = config::enable_adaptive_batch_size; }
+ void TearDown() override { config::enable_adaptive_batch_size = _saved_adaptive; }
+ bool _saved_adaptive = false;
+};
+
+// When adaptive is enabled, preferred_block_size_bytes() returns the configured value.
+TEST_F(BlockReaderByteBudgetTest, ReturnsConfiguredBytesWhenEnabled) {
+ config::enable_adaptive_batch_size = true;
+ BlockReader reader;
+ reader._reader_context.preferred_block_size_bytes = 65536;
+ EXPECT_EQ(reader.preferred_block_size_bytes(), 65536);
+}
+
+// When adaptive is disabled, preferred_block_size_bytes() returns 0 regardless.
+TEST_F(BlockReaderByteBudgetTest, ReturnsZeroWhenDisabled) {
+ config::enable_adaptive_batch_size = false;
+ BlockReader reader;
+ reader._reader_context.preferred_block_size_bytes = 65536;
+ EXPECT_EQ(reader.preferred_block_size_bytes(), 0);
+}
+
+// Default value of preferred_block_size_bytes in reader context is 0.
+TEST_F(BlockReaderByteBudgetTest, DefaultIsZero) {
+ config::enable_adaptive_batch_size = true;
+ BlockReader reader;
+ EXPECT_EQ(reader.preferred_block_size_bytes(), 0);
+}
+
+// Base TabletReader always returns 0 (feature unsupported at base level).
+TEST_F(BlockReaderByteBudgetTest, BaseTabletReaderReturnsZero) {
+ config::enable_adaptive_batch_size = true;
+ // TabletReader is abstract; use BlockReader as base pointer to test virtual dispatch.
+ BlockReader concrete;
+ concrete._reader_context.preferred_block_size_bytes = 99999;
+ TabletReader* base = &concrete;
+ // Through the virtual dispatch, BlockReader's override should be called.
+ EXPECT_EQ(base->preferred_block_size_bytes(), 99999);
Review Comment:
The test name/comment says “Base TabletReader always returns 0”, but the assertion is checking virtual dispatch through a TabletReader* to BlockReader’s override and expects 99999. Suggest updating the comment (or renaming the test) to reflect what is actually being validated.
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4197379501
/review
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3033265862
##########
be/src/runtime/runtime_state.h:
##########
@@ -138,7 +138,40 @@ class RuntimeState {
const DescriptorTbl& desc_tbl() const { return *_desc_tbl; }
void set_desc_tbl(const DescriptorTbl* desc_tbl) { _desc_tbl = desc_tbl; }
+
+ int block_max_rows() const {
+ return config::enable_adaptive_batch_size
+ ? std::max(_query_options.batch_size, int(preferred_block_size_rows()))
Review Comment:
`block_max_rows()` is now the shared cap for many operator/exchange/sort paths, but this expression changes semantics even when the adaptive feature is supposed to be disabled.
When `config::enable_adaptive_batch_size` is true and the session sets `preferred_block_size_bytes = 0`, `block_max_bytes()` correctly goes back to `0`, but `block_max_rows()` still becomes `max(batch_size, preferred_block_size_rows)`. Since `preferred_block_size_rows` defaults to `65535`, a session that intentionally uses `batch_size = 1024` will now let all of the converted call sites accumulate up to 65535 rows. That makes the `preferred_block_size_bytes = 0` disable path ineffective and can cause large intermediate blocks, memory spikes, and OOM/latency regressions.
This also means users cannot lower the row cap below `batch_size` via `preferred_block_size_rows`, because `max()` always widens it. Please gate the row override on the byte-based feature actually being enabled (or otherwise preserve legacy `batch_size` behavior when `preferred_block_size_bytes == 0`).
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "velodb-robyang (via GitHub)" <gi...@apache.org>.
velodb-robyang commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3071363489
##########
be/src/runtime/runtime_state.h:
##########
@@ -138,7 +138,42 @@ class RuntimeState {
const DescriptorTbl& desc_tbl() const { return *_desc_tbl; }
void set_desc_tbl(const DescriptorTbl* desc_tbl) { _desc_tbl = desc_tbl; }
+
+ MOCK_FUNCTION int block_max_rows() const {
+ if (config::enable_adaptive_batch_size && preferred_block_size_bytes() > 0) {
+ auto rows = preferred_block_size_rows();
+ return static_cast<int>(std::min(rows, static_cast<size_t>(INT32_MAX)));
+ }
+ return _query_options.batch_size;
+ }
+
+ MOCK_FUNCTION size_t block_max_bytes() const {
+ return config::enable_adaptive_batch_size ? preferred_block_size_bytes() : 0;
+ }
+
MOCK_FUNCTION int batch_size() const { return _query_options.batch_size; }
+ MOCK_FUNCTION size_t preferred_block_size_bytes() const {
+ if (_query_options.__isset.preferred_block_size_bytes) {
+ auto v = _query_options.preferred_block_size_bytes;
+ return v > 0 ? static_cast<size_t>(v) : 0;
Review Comment:
这里最好不要用0,用0 的话,代码就会有很多判断,直接用一个比较大的值比较好,比如128MB
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3123044344
##########
be/src/exec/operator/distinct_streaming_aggregation_operator.h:
##########
@@ -68,6 +68,7 @@ class DistinctStreamingAggLocalState final : public PipelineXLocalState<FakeShar
bool _should_expand_hash_table = true;
bool _stop_emplace_flag = false;
const int batch_size;
+ const size_t block_max_bytes;
Review Comment:
我感觉这个变量我们似乎没啥用,另外把budget 统一移动到operator 里,很多重复的代码就没有了
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "velodb-robyang (via GitHub)" <gi...@apache.org>.
velodb-robyang commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3071096125
##########
be/src/core/block/block.h:
##########
@@ -352,6 +352,15 @@ class Block {
void clear_column_mem_not_keep(const std::vector<bool>& column_keep_flags,
bool need_keep_first);
+ // Helper: sum byte_size() of all mutable columns.
Review Comment:
这个block 的size 有很多个,加点注释,说明每个size 都是啥意思,
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "velodb-robyang (via GitHub)" <gi...@apache.org>.
velodb-robyang commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3071103998
##########
be/src/exec/exchange/vdata_stream_recvr.h:
##########
@@ -79,7 +79,7 @@ class VDataStreamRecvr : public HasTaskExecutionCtx {
MOCK_FUNCTION Status create_merger(const VExprContextSPtrs& ordering_expr,
const std::vector<bool>& is_asc_order,
const std::vector<bool>& nulls_first, size_t batch_size,
- int64_t limit, size_t offset);
+ int64_t limit, size_t offset, size_t block_max_bytes = 0);
Review Comment:
这里也是一样
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4251060179
# FE Regression Coverage Report
Increment line coverage ` 78.57% (11/14)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_14b5056c0296a4f23ffce07fc310a5fd549966dc_merge_fe/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_14b5056c0296a4f23ffce07fc310a5fd549966dc_merge_fe/report/index.html)
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4254239534
# BE Regression && UT Coverage Report
Increment line coverage `86.66% (786/907)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_d4d5d5f9628109e8fd7fc00ceaf529d5bf8dd0c6_merge/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_d4d5d5f9628109e8fd7fc00ceaf529d5bf8dd0c6_merge/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 71.97% (26822/37270) |
| Line Coverage | 55.04% (284823/517455) |
| Region Coverage | 52.16% (236203/452853) |
| Branch Coverage | 53.56% (102093/190621) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feature](be) Implement adaptive batch size with EWMA prediction for byte-budget control [doris]
Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4249139038
# FE Regression Coverage Report
Increment line coverage ` 8.33% (11/132)` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/61535_25b25c07c01b606be38d8cb16601a25f8a559167_merge_fe/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/61535_25b25c07c01b606be38d8cb16601a25f8a559167_merge_fe/report/index.html)
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "mrhhsg (via GitHub)" <gi...@apache.org>.
mrhhsg commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3007177649
##########
fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java:
##########
@@ -1282,6 +1285,20 @@ public void checkQuerySlotCount(String slotCnt) {
@VariableMgr.VarAttr(name = BROKER_LOAD_BATCH_SIZE, fuzzy = true, checker = "checkBatchSize")
public int brokerLoadBatchSize = 16352;
+ // Target output block size in bytes for adaptive batch size. 0 disables the byte limit.
+ // Default 8MB. Passed to storage layer to control how many rows each SegmentIterator chunk
+ // should contain so the final Block stays near this size.
+ @VariableMgr.VarAttr(name = PREFERRED_BLOCK_SIZE_BYTES, needForward = true,
+ description = {"目标输出 Block 字节数上限,自适应 batch size 功能使用,0 表示不限制,默认 8MB",
+ "Target output block size in bytes for adaptive batch size. 0 disables the limit. Default 8MB."})
+ public long preferredBlockSizeBytes = 8388608L; // 8MB
+
+ // Per-column byte limit when computing adaptive chunk rows. 0 disables the per-column limit.
+ @VariableMgr.VarAttr(name = PREFERRED_MAX_COLUMN_IN_BLOCK_SIZE_BYTES, needForward = true,
+ description = {"自适应 batch size 时单列字节数上限,0 表示不限制,默认 1MB",
+ "Per-column byte limit for adaptive batch size. 0 disables per-column limit. Default 1MB."})
+ public long preferredMaxColumnInBlockSizeBytes = 1048576L; // 1MB
Review Comment:
控制 block 中某个字段不要太大造成 cache miss
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #61535:
URL: https://github.com/apache/doris/pull/61535#discussion_r3007170018
##########
be/src/storage/segment/segment_iterator.cpp:
##########
@@ -369,6 +369,14 @@ Status SegmentIterator::_init_impl(const StorageReadOptions& opts) {
// Read options will not change, so that just resize here
_block_rowids.resize(_opts.block_row_max);
+ // Adaptive batch size: snapshot the initial row limit and create predictor if enabled.
Review Comment:
some other cases:
1. topn lazy materialization also use segment iterator?
2. point query ?
3. scan stage of streamload?
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4129358209
# BE UT Coverage Report
Increment line coverage ` ` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/841c2a7248322bd5f241495adbc38da11aecef50_841c2a7248322bd5f241495adbc38da11aecef50/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/841c2a7248322bd5f241495adbc38da11aecef50_841c2a7248322bd5f241495adbc38da11aecef50/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 52.82% (19884/37643) |
| Line Coverage | 36.32% (185742/511398) |
| Region Coverage | 32.56% (143834/441708) |
| Branch Coverage | 33.76% (62971/186508) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [PR] [feat](storage) Implement adaptive batch size for SegmentIterator [doris]
Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #61535:
URL: https://github.com/apache/doris/pull/61535#issuecomment-4135480744
# BE UT Coverage Report
Increment line coverage ` ` :tada:
[Increment coverage report](http://coverage.selectdb-in.cc/coverage/841c2a7248322bd5f241495adbc38da11aecef50_841c2a7248322bd5f241495adbc38da11aecef50/increment_report/index.html)
[Complete coverage report](http://coverage.selectdb-in.cc/coverage/841c2a7248322bd5f241495adbc38da11aecef50_841c2a7248322bd5f241495adbc38da11aecef50/report/index.html)
| Category | Coverage |
|-------------------|--------------------|
| Function Coverage | 52.88% (19926/37681) |
| Line Coverage | 36.41% (186676/512751) |
| Region Coverage | 32.66% (144707/443133) |
| Branch Coverage | 33.87% (63475/187425) |
--
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: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org