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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to