This is an automated email from the ASF dual-hosted git repository.

mrhhsg pushed a commit to branch adaptive_batch_size
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 52466bbee504238dd703f5555256d12a0dfdcf77
Author: Hu Shenggang <[email protected]>
AuthorDate: Mon Apr 13 16:19:18 2026 +0800

    [improvement](be,fe) Address adaptive batch size review comments
    
    ### What problem does this PR solve?
    
    Issue Number: close #xxx
    
    Related PR: #61535
    
    Problem Summary: Address review comments from velodb-robyang on the adaptive
    batch size PR. Changes include:
    
    1. Move block_budget.h from common/ to util/ and update 8 include paths
    2. Add doc comments to block.h explaining 
bytes()/allocated_bytes()/columns_byte_size()
    3. Remove unused default parameter values from join_hash_table.h and 
vdata_stream_recvr.h
    4. Add per-operator output block byte profile counters (OutputBlockBytes,
       MaxOutputBlockBytes, MinOutputBlockBytes) in the operator base class
    5. Add comment to new_json_reader.h explaining row-based reader batch size
    6. Fix preferred_block_size_bytes() to return 8MB default instead of 0;
       simplify block_max_rows() condition; add relationship documentation
    7. Add bounds checking for session variables: preferredBlockSizeBytes 
[1MB,512MB],
       preferredBlockSizeRows [1,1000000], preferredMaxColumnInBlockSizeBytes 
[256KB,128MB]
    8. Simplify file_scanner.cpp adaptive batch size condition
    
    ### Release note
    
    Added per-operator output block byte size profile counters 
(OutputBlockBytes,
    MaxOutputBlockBytes, MinOutputBlockBytes) for better observability of block
    sizes flowing through the query pipeline. Added bounds checking for adaptive
    batch size session variables.
    
    ### Check List (For Author)
    
    - Test: Regression test / Unit Test / Manual test
        - FE UT: JniScannerTest#testSetBatchSize passed
        - BE+FE build succeeded
    - Behavior changed: No
    - Does this need documentation: No
    
    Co-authored-by: Copilot <[email protected]>
---
 be/src/core/block/block.h                          |  11 ++-
 be/src/exec/common/hash_table/join_hash_table.h    |   2 +-
 be/src/exec/exchange/local_exchanger.cpp           |   4 +-
 be/src/exec/exchange/vdata_stream_recvr.h          |   2 +-
 be/src/exec/exchange/vdata_stream_sender.cpp       |   6 +-
 be/src/exec/operator/aggregation_sink_operator.cpp |   2 +-
 .../exec/operator/aggregation_source_operator.cpp  |   6 +-
 .../distinct_streaming_aggregation_operator.cpp    |   8 +--
 be/src/exec/operator/exchange_source_operator.cpp  |   2 +-
 be/src/exec/operator/hashjoin_build_sink.cpp       |   6 +-
 be/src/exec/operator/hashjoin_probe_operator.cpp   |   4 +-
 .../operator/join/process_hash_table_probe_impl.h  |   6 +-
 .../operator/local_merge_sort_source_operator.cpp  |   4 +-
 .../operator/nested_loop_join_probe_operator.cpp   |  20 +++---
 be/src/exec/operator/operator.cpp                  |  16 +++++
 be/src/exec/operator/operator.h                    |   6 ++
 .../exec/operator/partition_sort_sink_operator.cpp |   2 +-
 .../partitioned_hash_join_probe_operator.cpp       |   2 +-
 be/src/exec/operator/schema_scan_operator.cpp      |   4 +-
 be/src/exec/operator/set_sink_operator.cpp         |   4 +-
 be/src/exec/operator/set_source_operator.cpp       |   4 +-
 .../exec/operator/spill_sort_source_operator.cpp   |   4 +-
 .../operator/streaming_aggregation_operator.cpp    |   4 +-
 be/src/exec/operator/table_function_operator.cpp   |  16 ++---
 be/src/exec/operator/union_sink_operator.cpp       |   6 +-
 be/src/exec/operator/union_source_operator.cpp     |   4 +-
 be/src/exec/scan/es_scanner.cpp                    |   6 +-
 be/src/exec/scan/file_scanner.cpp                  |   4 +-
 be/src/exec/scan/olap_scanner.cpp                  |   2 +-
 be/src/exec/scan/scanner.cpp                       |  11 ++-
 be/src/exec/sort/heap_sorter.cpp                   |   2 +-
 be/src/exec/sort/partition_sorter.cpp              |   6 +-
 be/src/exec/sort/sorter.cpp                        |   9 +--
 be/src/exec/sort/topn_sorter.cpp                   |   2 +-
 be/src/exec/sort/vsorted_run_merger.cpp            |  55 ++++++++++-----
 be/src/format/csv/csv_reader.cpp                   |   4 +-
 be/src/format/json/new_json_reader.cpp             |   4 +-
 be/src/format/json/new_json_reader.h               |   3 +
 be/src/runtime/runtime_profile_counter_names.h     |   3 +
 be/src/runtime/runtime_state.h                     |  44 ++++++------
 be/src/{common => util}/block_budget.h             |   8 +--
 be/test/common/block_budget_test.cpp               |   9 +--
 be/test/core/value/sort_merger_test.cpp            |  74 ++++++++++++++++++++-
 be/test/exec/operator/agg_operator_test.cpp        |   2 +-
 ...istinct_streaming_aggregation_operator_test.cpp |   4 +-
 .../exec/operator/hashjoin_probe_operator_test.cpp |   2 +-
 be/test/exec/operator/set_operator_test.cpp        |   2 +-
 .../exec/operator/streaming_agg_operator_test.cpp  |   2 +-
 .../exec/operator/table_function_operator_test.cpp |   4 +-
 be/test/exec/operator/union_operator_test.cpp      |   8 +--
 be/test/exec/sort/full_sort_test.cpp               |   2 -
 be/test/exec/sort/partition_sorter_test.cpp        |   2 -
 .../iterator/block_reader_batch_max_rows_test.cpp  |   4 +-
 .../segment/adaptive_block_size_predictor_test.cpp |   2 +-
 be/test/storage/test_data/tablet_meta_test.hdr     | Bin 0 -> 280 bytes
 be/test/testutil/mock/mock_runtime_state.h         |   1 -
 .../java/org/apache/doris/qe/SessionVariable.java  |  61 ++++++++++++-----
 gensrc/thrift/PaloInternalService.thrift           |   4 --
 .../adaptive_batch_size/adaptive_batch_size.groovy |   3 +-
 59 files changed, 317 insertions(+), 187 deletions(-)

diff --git a/be/src/core/block/block.h b/be/src/core/block/block.h
index 436412863d1..81ada533773 100644
--- a/be/src/core/block/block.h
+++ b/be/src/core/block/block.h
@@ -183,12 +183,17 @@ public:
 
     Status check_type_and_column() const;
 
-    /// Approximate number of bytes in memory - for profiling and limits.
+    /// Approximate number of bytes used by column data in memory.
+    /// This reflects the actual data footprint (e.g. string contents, numeric 
arrays)
+    /// and is the metric used by adaptive batch size byte budgets.
     size_t bytes() const;
 
+    /// Returns per-column byte sizes as a comma-separated string (for 
debugging).
     std::string columns_bytes() const;
 
-    /// Approximate number of allocated bytes in memory - for profiling and 
limits.
+    /// Approximate number of allocated (reserved) bytes in memory.
+    /// This may be larger than bytes() due to pre-allocated capacity in 
vectors/arenas.
+    /// Used for memory tracking and profiling.
     MOCK_FUNCTION size_t allocated_bytes() const;
 
     /** Get a list of column names separated by commas. */
@@ -353,6 +358,8 @@ public:
                                    bool need_keep_first);
 
     // Helper: sum byte_size() of all mutable columns.
+    // Unlike Block::bytes() which operates on immutable ColumnPtr,
+    // this works on MutableColumns during block construction (e.g. in 
BlockReader).
     static inline size_t columns_byte_size(const MutableColumns& cols) {
         size_t total = 0;
         for (const auto& col : cols) {
diff --git a/be/src/exec/common/hash_table/join_hash_table.h 
b/be/src/exec/common/hash_table/join_hash_table.h
index 0ab1c2708e8..27dcca0a2a9 100644
--- a/be/src/exec/common/hash_table/join_hash_table.h
+++ b/be/src/exec/common/hash_table/join_hash_table.h
@@ -107,7 +107,7 @@ public:
                     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,
-                    int batch_size_limit = 0) {
+                    int batch_size_limit) {
         const int effective_batch_size = batch_size_limit > 0 ? 
batch_size_limit : max_batch_size;
 
         if ((JoinOpType == TJoinOp::NULL_AWARE_LEFT_ANTI_JOIN ||
diff --git a/be/src/exec/exchange/local_exchanger.cpp 
b/be/src/exec/exchange/local_exchanger.cpp
index 6d6d27d1c55..2de23a7d73d 100644
--- a/be/src/exec/exchange/local_exchanger.cpp
+++ b/be/src/exec/exchange/local_exchanger.cpp
@@ -150,8 +150,8 @@ Status ShuffleExchanger::get_block(RuntimeState* state, 
Block* block, bool* eos,
     PartitionedBlock partitioned_block;
     MutableBlock mutable_block;
 
-    const auto max_batch_size = state->block_max_rows();
-    const auto max_block_bytes = state->block_max_bytes();
+    const auto max_batch_size = state->batch_size();
+    const auto max_block_bytes = state->preferred_block_size_bytes();
 
     auto get_data = [&]() -> Status {
         do {
diff --git a/be/src/exec/exchange/vdata_stream_recvr.h 
b/be/src/exec/exchange/vdata_stream_recvr.h
index 136600308ee..77c11c7c9fc 100644
--- a/be/src/exec/exchange/vdata_stream_recvr.h
+++ b/be/src/exec/exchange/vdata_stream_recvr.h
@@ -79,7 +79,7 @@ public:
     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, size_t 
block_max_bytes = 0);
+                                       int64_t limit, size_t offset, size_t 
block_max_bytes);
 
     std::vector<SenderQueue*> sender_queues() const { return _sender_queues; }
 
diff --git a/be/src/exec/exchange/vdata_stream_sender.cpp 
b/be/src/exec/exchange/vdata_stream_sender.cpp
index e23e373ff69..1d8698671dc 100644
--- a/be/src/exec/exchange/vdata_stream_sender.cpp
+++ b/be/src/exec/exchange/vdata_stream_sender.cpp
@@ -291,8 +291,8 @@ Status Channel::close(RuntimeState* state) {
 BlockSerializer::BlockSerializer(ExchangeSinkLocalState* parent, bool is_local)
         : _parent(parent),
           _is_local(is_local),
-          _batch_size(parent->state()->block_max_rows()),
-          _block_max_bytes(parent->state()->block_max_bytes()) {}
+          _batch_size(parent->state()->batch_size()),
+          _block_max_bytes(parent->state()->preferred_block_size_bytes()) {}
 
 Status BlockSerializer::next_serialized_block(Block* block, PBlock* dest, 
size_t num_receivers,
                                               bool* serialized, bool eos, 
const uint32_t* data,
@@ -315,7 +315,7 @@ 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) ||
-        (_block_max_bytes > 0 && _mutable_block->bytes() >= _block_max_bytes)) 
{
+        _mutable_block->bytes() >= _block_max_bytes) {
         if (!_is_local) {
             RETURN_IF_ERROR(_serialize_block(dest, num_receivers));
         }
diff --git a/be/src/exec/operator/aggregation_sink_operator.cpp 
b/be/src/exec/operator/aggregation_sink_operator.cpp
index ff51caf8176..0f7505423a3 100644
--- a/be/src/exec/operator/aggregation_sink_operator.cpp
+++ b/be/src/exec/operator/aggregation_sink_operator.cpp
@@ -814,7 +814,7 @@ size_t 
AggSinkLocalState::get_reserve_mem_size(RuntimeState* state, bool eos) co
                 if constexpr (std::is_same_v<HashTableCtxType, 
std::monostate>) {
                     return 0;
                 } else {
-                    return 
arg.hash_table->estimate_memory(state->block_max_rows());
+                    return 
arg.hash_table->estimate_memory(state->batch_size());
                 }
             },
             _agg_data->method_variant);
diff --git a/be/src/exec/operator/aggregation_source_operator.cpp 
b/be/src/exec/operator/aggregation_source_operator.cpp
index 0535daf18bc..017515ad61e 100644
--- a/be/src/exec/operator/aggregation_source_operator.cpp
+++ b/be/src/exec/operator/aggregation_source_operator.cpp
@@ -20,7 +20,7 @@
 #include <memory>
 #include <string>
 
-#include "common/block_budget.h"
+#include "util/block_budget.h"
 #include "common/exception.h"
 #include "core/column/column_fixed_length_object.h"
 #include "exec/operator/operator.h"
@@ -123,7 +123,7 @@ Status 
AggLocalState::_get_results_with_serialized_key(RuntimeState* state, Bloc
     }
 
     // Compute effective max rows based on estimated bytes per row.
-    const BlockBudget budget(state->block_max_rows(), 
state->block_max_bytes());
+    const BlockBudget budget(state->batch_size(), 
state->preferred_block_size_bytes());
     const size_t effective_max_rows = 
budget.effective_max_rows(_estimated_row_bytes);
 
     std::visit(
@@ -319,7 +319,7 @@ Status 
AggLocalState::_get_with_serialized_key_result(RuntimeState* state, Block
     SCOPED_TIMER(_get_results_timer);
 
     // Compute effective max rows based on estimated bytes per row.
-    const BlockBudget budget(state->block_max_rows(), 
state->block_max_bytes());
+    const BlockBudget budget(state->batch_size(), 
state->preferred_block_size_bytes());
     const size_t effective_max_rows = 
budget.effective_max_rows(_estimated_row_bytes);
 
     std::visit(
diff --git a/be/src/exec/operator/distinct_streaming_aggregation_operator.cpp 
b/be/src/exec/operator/distinct_streaming_aggregation_operator.cpp
index 5a0d25b4924..a7015ccf96b 100644
--- a/be/src/exec/operator/distinct_streaming_aggregation_operator.cpp
+++ b/be/src/exec/operator/distinct_streaming_aggregation_operator.cpp
@@ -22,7 +22,7 @@
 #include <memory>
 #include <utility>
 
-#include "common/block_budget.h"
+#include "util/block_budget.h"
 #include "common/compiler_util.h" // IWYU pragma: keep
 #include "exec/operator/streaming_agg_min_reduction.h"
 #include "exprs/vectorized_agg_fn.h"
@@ -38,8 +38,8 @@ namespace doris {
 DistinctStreamingAggLocalState::DistinctStreamingAggLocalState(RuntimeState* 
state,
                                                                OperatorXBase* 
parent)
         : PipelineXLocalState<FakeSharedState>(state, parent),
-          batch_size(state->block_max_rows()),
-          block_max_bytes(state->block_max_bytes()),
+          batch_size(state->batch_size()),
+          block_max_bytes(state->preferred_block_size_bytes()),
           _agg_data(std::make_unique<DistinctDataVariants>()),
           _child_block(Block::create_unique()),
           _aggregated_block(Block::create_unique()),
@@ -397,7 +397,7 @@ 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->block_max_rows(), 
state->block_max_bytes());
+    const BlockBudget budget(state->batch_size(), 
state->preferred_block_size_bytes());
     const bool need_batch = local_state._stop_emplace_flag
                                     ? local_state._aggregated_block->empty()
                                     : 
budget.within_budget(local_state._aggregated_block->rows(),
diff --git a/be/src/exec/operator/exchange_source_operator.cpp 
b/be/src/exec/operator/exchange_source_operator.cpp
index 69fa7bb17a1..b69d0878c75 100644
--- a/be/src/exec/operator/exchange_source_operator.cpp
+++ b/be/src/exec/operator/exchange_source_operator.cpp
@@ -155,7 +155,7 @@ Status ExchangeSourceOperatorX::get_block(RuntimeState* 
state, Block* block, boo
         SCOPED_TIMER(local_state.create_merger_timer);
         RETURN_IF_ERROR(local_state.stream_recvr->create_merger(
                 local_state.vsort_exec_exprs.ordering_expr_ctxs(), 
_is_asc_order, _nulls_first,
-                state->block_max_rows(), _limit, _offset, 
state->block_max_bytes()));
+                state->batch_size(), _limit, _offset, 
state->preferred_block_size_bytes()));
         local_state.is_ready = true;
         return Status::OK();
     }
diff --git a/be/src/exec/operator/hashjoin_build_sink.cpp 
b/be/src/exec/operator/hashjoin_build_sink.cpp
index 94d38560cdc..f0570614a7e 100644
--- a/be/src/exec/operator/hashjoin_build_sink.cpp
+++ b/be/src/exec/operator/hashjoin_build_sink.cpp
@@ -139,7 +139,7 @@ size_t 
HashJoinBuildSinkLocalState::get_reserve_mem_size(RuntimeState* state, bo
         const auto bytes = _build_side_mutable_block.bytes();
         const auto allocated_bytes = 
_build_side_mutable_block.allocated_bytes();
         const auto bytes_per_row = bytes / build_block_rows;
-        const auto estimated_size_of_next_block = bytes_per_row * 
state->block_max_rows();
+        const auto estimated_size_of_next_block = bytes_per_row * 
state->batch_size();
         // If the new size is greater than 85% of allocalted bytes, it maybe 
need to realloc.
         if (((estimated_size_of_next_block + bytes) * 100 / allocated_bytes) 
>= 85) {
             size_to_reserve += 
static_cast<size_t>(static_cast<double>(allocated_bytes) * 1.15);
@@ -147,7 +147,7 @@ size_t 
HashJoinBuildSinkLocalState::get_reserve_mem_size(RuntimeState* state, bo
     }
 
     if (eos) {
-        const size_t rows = build_block_rows + state->block_max_rows();
+        const size_t rows = build_block_rows + state->batch_size();
         const auto bucket_size = hash_join_table_calc_bucket_size(rows);
 
         size_to_reserve += bucket_size * sizeof(uint32_t); // 
JoinHashTable::first
@@ -606,7 +606,7 @@ Status 
HashJoinBuildSinkLocalState::process_build_block(RuntimeState* state, Blo
                           using HashTableCtxType = std::decay_t<decltype(arg)>;
                           using JoinOpType = std::decay_t<decltype(join_op)>;
                           ProcessHashTableBuild<HashTableCtxType> 
hash_table_build_process(
-                                  rows, raw_ptrs, this, 
state->block_max_rows(), state);
+                                  rows, raw_ptrs, this, state->batch_size(), 
state);
                           auto st = hash_table_build_process.template 
run<JoinOpType::value>(
                                   arg, null_map_val ? 
&null_map_val->get_data() : nullptr,
                                   &_shared_state->_has_null_in_build_side,
diff --git a/be/src/exec/operator/hashjoin_probe_operator.cpp 
b/be/src/exec/operator/hashjoin_probe_operator.cpp
index be3d42c4122..c5fb6175ecd 100644
--- a/be/src/exec/operator/hashjoin_probe_operator.cpp
+++ b/be/src/exec/operator/hashjoin_probe_operator.cpp
@@ -98,7 +98,7 @@ Status HashJoinProbeLocalState::open(RuntimeState* state) {
                 } else {
                     _process_hashtable_ctx_variants
                             
->emplace<ProcessHashTableProbe<JoinOpType::value>>(
-                                    this, state->block_max_rows(), 
state->block_max_bytes());
+                                    this, state->batch_size(), 
state->preferred_block_size_bytes());
                 }
             },
             _shared_state->join_op_variants, 
make_bool_variant(p._have_other_join_conjunct));
@@ -390,7 +390,7 @@ Status 
HashJoinProbeLocalState::filter_data_and_build_output(RuntimeState* state
                                                              bool 
check_rows_count) {
     auto output_rows = temp_block->rows();
     if (check_rows_count) {
-        DCHECK(output_rows <= state->block_max_rows());
+        DCHECK(output_rows <= state->batch_size());
     }
     {
         SCOPED_TIMER(_join_filter_timer);
diff --git a/be/src/exec/operator/join/process_hash_table_probe_impl.h 
b/be/src/exec/operator/join/process_hash_table_probe_impl.h
index 1e3c14bf4d4..0d7700e7a8d 100644
--- a/be/src/exec/operator/join/process_hash_table_probe_impl.h
+++ b/be/src/exec/operator/join/process_hash_table_probe_impl.h
@@ -215,7 +215,7 @@ typename HashTableType::State 
ProcessHashTableProbe<JoinOpType>::_init_probe_sid
         COUNTER_UPDATE(_parent->_memory_used_counter, arena_memory_usage);
 
         // Pre-estimate bytes per row from both build and probe sides to limit 
batch size.
-        if (_block_max_bytes > 0) {
+        {
             size_t total_bytes_per_row = 0;
             if (_build_block && _build_block->rows() > 0) {
                 total_bytes_per_row += _build_block->bytes() / 
_build_block->rows();
@@ -582,7 +582,7 @@ Status 
ProcessHashTableProbe<JoinOpType>::process(HashTableType& hash_table_ctx,
     COUNTER_UPDATE(_parent->_intermediate_rows_counter, current_offset);
 
     // Adaptively adjust batch size based on output block bytes.
-    if (_block_max_bytes > 0 && current_offset > 0) {
+    if (current_offset > 0) {
         size_t block_bytes = output_block->bytes();
         size_t bytes_per_row = block_bytes / current_offset;
         if (bytes_per_row > 0) {
@@ -1074,7 +1074,7 @@ Status ProcessHashTableProbe<
         output_block->swap(mutable_block.to_block(0));
 
         // Adaptively adjust batch size based on output block bytes.
-        if (_block_max_bytes > 0 && block_size > 0) {
+        if (block_size > 0) {
             size_t block_bytes = output_block->bytes();
             size_t bytes_per_row = block_bytes / block_size;
             if (bytes_per_row > 0) {
diff --git a/be/src/exec/operator/local_merge_sort_source_operator.cpp 
b/be/src/exec/operator/local_merge_sort_source_operator.cpp
index a2dd1abec27..7a85ff7fceb 100644
--- a/be/src/exec/operator/local_merge_sort_source_operator.cpp
+++ b/be/src/exec/operator/local_merge_sort_source_operator.cpp
@@ -67,8 +67,8 @@ Status LocalMergeSortLocalState::build_merger(RuntimeState* 
state) {
                 p._vsort_exec_exprs.ordering_expr_ctxs()[i]->clone(state, 
ordering_expr_ctxs[i]));
     }
     _merger = std::make_unique<VSortedRunMerger>(
-            ordering_expr_ctxs, p._is_asc_order, p._nulls_first, 
state->block_max_rows(), p._limit,
-            p._offset, custom_profile(), state->block_max_bytes());
+            ordering_expr_ctxs, p._is_asc_order, p._nulls_first, 
state->batch_size(), p._limit,
+            p._offset, custom_profile(), state->preferred_block_size_bytes());
     std::vector<BlockSupplier> child_block_suppliers;
     for (auto sorter : p._sorters) {
         BlockSupplier block_supplier = [sorter, state](Block* block, bool* 
eos) {
diff --git a/be/src/exec/operator/nested_loop_join_probe_operator.cpp 
b/be/src/exec/operator/nested_loop_join_probe_operator.cpp
index 73fa295d048..cce7b452df8 100644
--- a/be/src/exec/operator/nested_loop_join_probe_operator.cpp
+++ b/be/src/exec/operator/nested_loop_join_probe_operator.cpp
@@ -19,7 +19,7 @@
 
 #include <memory>
 
-#include "common/block_budget.h"
+#include "util/block_budget.h"
 #include "common/cast_set.h"
 #include "common/exception.h"
 #include "core/block/block.h"
@@ -195,8 +195,8 @@ void 
NestedLoopJoinProbeLocalState::_generate_block_base_probe(RuntimeState* sta
         return build_blocks[_current_build_pos].rows();
     };
 
-    const auto block_max_bytes = state->block_max_bytes();
-    const BlockBudget budget(state->block_max_rows(), block_max_bytes);
+    const auto block_max_bytes = state->preferred_block_size_bytes();
+    const BlockBudget budget(state->batch_size(), block_max_bytes);
     size_t effective_max_rows = budget.max_rows;
     bool bytes_estimated = false;
     while (_join_block.rows() + add_rows() <= effective_max_rows) {
@@ -237,7 +237,7 @@ void 
NestedLoopJoinProbeLocalState::_generate_block_base_probe(RuntimeState* sta
                             now_process_build_block, 
p._num_build_side_columns);
 
         // Refine row limit based on actual bytes per row after first 
data-producing iteration
-        if (!bytes_estimated && block_max_bytes > 0 && _join_block.rows() > 0) 
{
+        if (!bytes_estimated && _join_block.rows() > 0) {
             bytes_estimated = true;
             size_t bytes_per_row = _join_block.bytes() / _join_block.rows();
             if (bytes_per_row > 0) {
@@ -283,8 +283,8 @@ void 
NestedLoopJoinProbeLocalState::_generate_block_base_build(RuntimeState* sta
         return;
     }
 
-    const auto block_max_bytes = state->block_max_bytes();
-    const BlockBudget budget(state->block_max_rows(), block_max_bytes);
+    const auto block_max_bytes = state->preferred_block_size_bytes();
+    const BlockBudget budget(state->batch_size(), block_max_bytes);
     size_t effective_max_rows = budget.max_rows;
     bool bytes_estimated = false;
     while (_join_block.rows() + probe_rows <= effective_max_rows) {
@@ -321,7 +321,7 @@ void 
NestedLoopJoinProbeLocalState::_generate_block_base_build(RuntimeState* sta
         _probe_block_pos = probe_rows;
 
         // Refine row limit based on actual bytes per row after first 
data-producing iteration
-        if (!bytes_estimated && block_max_bytes > 0 && _join_block.rows() > 0) 
{
+        if (!bytes_estimated && _join_block.rows() > 0) {
             bytes_estimated = true;
             effective_max_rows =
                     budget.effective_max_rows(_join_block.bytes() / 
_join_block.rows());
@@ -394,7 +394,7 @@ Status 
NestedLoopJoinProbeLocalState::generate_other_join_block_data(RuntimeStat
                 // probe row with null from build side.
                 if (_probe_side_process_count) {
                     _finalize_current_phase<false, JoinOpType::value == 
TJoinOp::LEFT_SEMI_JOIN>(
-                            _join_block, state->block_max_rows(), 
state->block_max_bytes());
+                            _join_block, state->batch_size(), 
state->preferred_block_size_bytes());
                 }
             } else if (_probe_side_process_count && p._is_mark_join &&
                        _shared_state->build_blocks.empty()) {
@@ -414,7 +414,7 @@ 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->block_max_rows(), 
state->block_max_bytes());
+                    _join_block, state->batch_size(), 
state->preferred_block_size_bytes());
         }
     }
     COUNTER_UPDATE(_probe_rows_counter, _join_block.rows());
@@ -430,7 +430,7 @@ void 
NestedLoopJoinProbeLocalState::_finalize_current_phase(Block& block, size_t
     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 (block_max_bytes > 0 && column_size > 0) {
+    if (column_size > 0) {
         size_t current_bytes = 0;
         for (const auto& col : dst_columns) {
             current_bytes += col->byte_size();
diff --git a/be/src/exec/operator/operator.cpp 
b/be/src/exec/operator/operator.cpp
index 7b4b78858d1..d97f1d1e0eb 100644
--- a/be/src/exec/operator/operator.cpp
+++ b/be/src/exec/operator/operator.cpp
@@ -406,6 +406,16 @@ Status 
OperatorXBase::get_block_after_projects(RuntimeState* state, Block* block
             if (auto rows = block->rows()) {
                 COUNTER_UPDATE(local_state->_rows_returned_counter, rows);
                 COUNTER_UPDATE(local_state->_blocks_returned_counter, 1);
+                auto block_bytes = static_cast<int64_t>(block->bytes());
+                COUNTER_UPDATE(local_state->_output_block_bytes_counter, 
block_bytes);
+                if (block_bytes > local_state->_max_output_block_bytes) {
+                    local_state->_max_output_block_bytes = block_bytes;
+                    COUNTER_SET(local_state->_max_output_block_bytes_counter, 
block_bytes);
+                }
+                if (block_bytes < local_state->_min_output_block_bytes) {
+                    local_state->_min_output_block_bytes = block_bytes;
+                    COUNTER_SET(local_state->_min_output_block_bytes_counter, 
block_bytes);
+                }
             }
         }
     });
@@ -572,6 +582,12 @@ Status 
PipelineXLocalState<SharedStateArg>::init(RuntimeState* state, LocalState
             ADD_COUNTER_WITH_LEVEL(_common_profile, profile::ROWS_PRODUCED, 
TUnit::UNIT, 1);
     _blocks_returned_counter =
             ADD_COUNTER_WITH_LEVEL(_common_profile, profile::BLOCKS_PRODUCED, 
TUnit::UNIT, 1);
+    _output_block_bytes_counter =
+            ADD_COUNTER_WITH_LEVEL(_common_profile, 
profile::OUTPUT_BLOCK_BYTES, TUnit::BYTES, 1);
+    _max_output_block_bytes_counter = ADD_COUNTER_WITH_LEVEL(
+            _common_profile, profile::MAX_OUTPUT_BLOCK_BYTES, TUnit::BYTES, 1);
+    _min_output_block_bytes_counter = ADD_COUNTER_WITH_LEVEL(
+            _common_profile, profile::MIN_OUTPUT_BLOCK_BYTES, TUnit::BYTES, 1);
     _projection_timer = ADD_TIMER_WITH_LEVEL(_common_profile, 
profile::PROJECTION_TIME, 2);
     _init_timer = ADD_TIMER_WITH_LEVEL(_common_profile, profile::INIT_TIME, 2);
     _open_timer = ADD_TIMER_WITH_LEVEL(_common_profile, profile::OPEN_TIME, 2);
diff --git a/be/src/exec/operator/operator.h b/be/src/exec/operator/operator.h
index 07b573dc911..2d8490eb20b 100644
--- a/be/src/exec/operator/operator.h
+++ b/be/src/exec/operator/operator.h
@@ -23,6 +23,7 @@
 #include <atomic>
 #include <cstdint>
 #include <functional>
+#include <limits>
 #include <memory>
 #include <string>
 #include <utility>
@@ -299,6 +300,11 @@ protected:
 
     RuntimeProfile::Counter* _rows_returned_counter = nullptr;
     RuntimeProfile::Counter* _blocks_returned_counter = nullptr;
+    RuntimeProfile::Counter* _output_block_bytes_counter = nullptr;
+    RuntimeProfile::Counter* _max_output_block_bytes_counter = nullptr;
+    RuntimeProfile::Counter* _min_output_block_bytes_counter = nullptr;
+    int64_t _max_output_block_bytes = 0;
+    int64_t _min_output_block_bytes = std::numeric_limits<int64_t>::max();
     RuntimeProfile::Counter* _wait_for_dependency_timer = nullptr;
     // Account for current memory and peak memory used by this node
     RuntimeProfile::HighWaterMarkCounter* _memory_used_counter = nullptr;
diff --git a/be/src/exec/operator/partition_sort_sink_operator.cpp 
b/be/src/exec/operator/partition_sort_sink_operator.cpp
index 58c5f402f06..f91261f1e82 100644
--- a/be/src/exec/operator/partition_sort_sink_operator.cpp
+++ b/be/src/exec/operator/partition_sort_sink_operator.cpp
@@ -191,7 +191,7 @@ Status 
PartitionSortSinkOperatorX::_split_block_by_partition(
 
 size_t PartitionSortSinkOperatorX::get_reserve_mem_size(RuntimeState* state, 
bool eos) {
     auto& local_state = get_local_state(state);
-    auto rows = state->block_max_rows();
+    auto rows = state->batch_size();
     size_t reserve_mem_size =
             std::visit(Overload {[&](std::monostate&) -> size_t { return 0; },
                                  [&](auto& agg_method) -> size_t {
diff --git a/be/src/exec/operator/partitioned_hash_join_probe_operator.cpp 
b/be/src/exec/operator/partitioned_hash_join_probe_operator.cpp
index 8dbed8d0a7d..1bbc1972bec 100644
--- a/be/src/exec/operator/partitioned_hash_join_probe_operator.cpp
+++ b/be/src/exec/operator/partitioned_hash_join_probe_operator.cpp
@@ -916,7 +916,7 @@ size_t 
PartitionedHashJoinProbeOperatorX::get_reserve_mem_size(RuntimeState* sta
     if (about_to_build && local_state._recovered_build_block) {
         // Estimate rows that will land in the hash table so we can reserve
         // enough for JoinHashTable::first[] + JoinHashTable::next[].
-        size_t rows = std::max(static_cast<size_t>(state->block_max_rows()),
+        size_t rows = std::max(static_cast<size_t>(state->batch_size()),
                                
static_cast<size_t>(local_state._recovered_build_block->rows()));
 
         const size_t bucket_size = hash_join_table_calc_bucket_size(rows);
diff --git a/be/src/exec/operator/schema_scan_operator.cpp 
b/be/src/exec/operator/schema_scan_operator.cpp
index aec72a3cffe..88e309be118 100644
--- a/be/src/exec/operator/schema_scan_operator.cpp
+++ b/be/src/exec/operator/schema_scan_operator.cpp
@@ -21,7 +21,7 @@
 
 #include <memory>
 
-#include "common/block_budget.h"
+#include "util/block_budget.h"
 #include "core/data_type/data_type_factory.hpp"
 #include "exec/operator/operator.h"
 #include "runtime/runtime_profile.h"
@@ -244,7 +244,7 @@ Status SchemaScanOperatorX::get_block(RuntimeState* state, 
Block* block, bool* e
                 break;
             }
 
-            const BlockBudget budget(state->block_max_rows(), 
state->block_max_bytes());
+            const BlockBudget budget(state->batch_size(), 
state->preferred_block_size_bytes());
             if (budget.exceeded(src_block.rows(), src_block.bytes())) {
                 break;
             }
diff --git a/be/src/exec/operator/set_sink_operator.cpp 
b/be/src/exec/operator/set_sink_operator.cpp
index d0b4893b563..11e1cb61600 100644
--- a/be/src/exec/operator/set_sink_operator.cpp
+++ b/be/src/exec/operator/set_sink_operator.cpp
@@ -260,14 +260,14 @@ size_t 
SetSinkOperatorX<is_intersect>::get_reserve_mem_size(RuntimeState* state,
                 if constexpr (std::is_same_v<HashTableCtxType, 
std::monostate>) {
                     return 0;
                 } else {
-                    return 
arg.hash_table->estimate_memory(state->block_max_rows());
+                    return 
arg.hash_table->estimate_memory(state->batch_size());
                 }
             },
             local_state._shared_state->hash_table_variants->method_variant);
 
     size_to_reserve += local_state._mutable_block.allocated_bytes();
     for (auto& _child_expr : _child_exprs) {
-        size_to_reserve += 
_child_expr->root()->estimate_memory(state->block_max_rows());
+        size_to_reserve += 
_child_expr->root()->estimate_memory(state->batch_size());
     }
     return size_to_reserve;
 }
diff --git a/be/src/exec/operator/set_source_operator.cpp 
b/be/src/exec/operator/set_source_operator.cpp
index 5a36a73cafb..81677c48b76 100644
--- a/be/src/exec/operator/set_source_operator.cpp
+++ b/be/src/exec/operator/set_source_operator.cpp
@@ -20,7 +20,7 @@
 #include <memory>
 #include <type_traits>
 
-#include "common/block_budget.h"
+#include "util/block_budget.h"
 #include "common/status.h"
 #include "exec/operator/operator.h"
 #include "runtime/runtime_profile.h"
@@ -83,7 +83,7 @@ Status 
SetSourceOperatorX<is_intersect>::get_block(RuntimeState* state, Block* b
     SCOPED_PEAK_MEM(&local_state._estimate_memory_usage);
 
     // Compute effective batch size based on estimated bytes per row.
-    const BlockBudget budget(state->block_max_rows(), 
state->block_max_bytes());
+    const BlockBudget budget(state->batch_size(), 
state->preferred_block_size_bytes());
     const size_t effective_batch_size = 
budget.effective_max_rows(local_state._estimated_row_bytes);
 
     _create_mutable_cols(local_state, block);
diff --git a/be/src/exec/operator/spill_sort_source_operator.cpp 
b/be/src/exec/operator/spill_sort_source_operator.cpp
index 73654652316..3a1f6dfed4e 100644
--- a/be/src/exec/operator/spill_sort_source_operator.cpp
+++ b/be/src/exec/operator/spill_sort_source_operator.cpp
@@ -156,8 +156,8 @@ Status 
SpillSortLocalState::_create_intermediate_merger(RuntimeState* state, int
     }
 
     _merger =
-            std::make_unique<VSortedRunMerger>(sort_description, 
state->block_max_rows(), limit,
-                                               offset, custom_profile(), 
state->block_max_bytes());
+            std::make_unique<VSortedRunMerger>(sort_description, 
state->batch_size(), limit,
+                                               offset, custom_profile(), 
state->preferred_block_size_bytes());
 
     _current_merging_files.clear();
     _current_merging_readers.clear();
diff --git a/be/src/exec/operator/streaming_aggregation_operator.cpp 
b/be/src/exec/operator/streaming_aggregation_operator.cpp
index 329c6331272..8dbf182cec4 100644
--- a/be/src/exec/operator/streaming_aggregation_operator.cpp
+++ b/be/src/exec/operator/streaming_aggregation_operator.cpp
@@ -22,7 +22,7 @@
 #include <memory>
 #include <utility>
 
-#include "common/block_budget.h"
+#include "util/block_budget.h"
 #include "common/cast_set.h"
 #include "common/compiler_util.h" // IWYU pragma: keep
 #include "core/column/column_fixed_length_object.h"
@@ -471,7 +471,7 @@ Status 
StreamingAggLocalState::_get_results_with_serialized_key(RuntimeState* st
     }
 
     // Compute effective max rows based on estimated bytes per row from 
previous calls.
-    const BlockBudget budget(state->block_max_rows(), 
state->block_max_bytes());
+    const BlockBudget budget(state->batch_size(), 
state->preferred_block_size_bytes());
     const size_t effective_max_rows = 
budget.effective_max_rows(_estimated_row_bytes);
 
     std::visit(
diff --git a/be/src/exec/operator/table_function_operator.cpp 
b/be/src/exec/operator/table_function_operator.cpp
index bb822a06470..8bb1e4ce7d6 100644
--- a/be/src/exec/operator/table_function_operator.cpp
+++ b/be/src/exec/operator/table_function_operator.cpp
@@ -23,7 +23,7 @@
 #include <memory>
 #include <numeric>
 
-#include "common/block_budget.h"
+#include "util/block_budget.h"
 #include "common/cast_set.h"
 #include "core/assert_cast.h"
 #include "core/block/block.h"
@@ -259,14 +259,14 @@ Status 
TableFunctionLocalState::_get_expanded_block_block_fast_path(
     DCHECK(_block_fast_path_enabled);
 
     auto remaining_capacity =
-            state->block_max_rows() - 
cast_set<int>(columns[p._child_slots.size()]->size());
+            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->block_max_bytes();
-    if (block_max_bytes > 0 && _child_block->rows() > 0) {
+    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;
@@ -531,7 +531,7 @@ Status 
TableFunctionLocalState::get_expanded_block(RuntimeState* state, Block* o
     }
 
     if (use_slow_path) {
-        const BlockBudget budget_slow(state->block_max_rows(), 
state->block_max_bytes());
+        const BlockBudget budget_slow(state->batch_size(), 
state->preferred_block_size_bytes());
         bool skip_child_row = false;
         while 
(budget_slow.within_budget(columns[p._child_slots.size()]->size(), 
m_block.bytes())) {
             RETURN_IF_CANCELLED(state);
@@ -566,9 +566,9 @@ Status 
TableFunctionLocalState::get_expanded_block(RuntimeState* state, Block* o
             auto repeat_times = _fns[p._fn_num - 1]->get_value(
                     columns[p._child_slots.size() + p._fn_num - 1],
                     //// It has already been checked that
-                    // columns[p._child_slots.size()]->size() < 
state->block_max_rows(),
+                    // columns[p._child_slots.size()]->size() < 
state->batch_size(),
                     // so columns[p._child_slots.size()]->size() will not 
exceed the range of int.
-                    state->block_max_rows() - 
(int)columns[p._child_slots.size()]->size());
+                    state->batch_size() - 
(int)columns[p._child_slots.size()]->size());
             _current_row_insert_times += repeat_times;
             for (int i = 0; i < p._fn_num - 1; i++) {
                 _fns[i]->get_same_many_values(columns[i + 
p._child_slots.size()], repeat_times);
@@ -616,7 +616,7 @@ Status 
TableFunctionLocalState::_get_expanded_block_for_outer_conjuncts(RuntimeS
         child_row_to_output_rows_indices.push_back(0);
     }
 
-    const BlockBudget budget(state->block_max_rows(), 
state->block_max_bytes());
+    const BlockBudget budget(state->batch_size(), 
state->preferred_block_size_bytes());
     auto output_row_count = columns[child_slot_count]->size();
     auto within_block_limit = [&]() -> bool {
         return budget.within_budget(output_row_count, m_block.bytes());
diff --git a/be/src/exec/operator/union_sink_operator.cpp 
b/be/src/exec/operator/union_sink_operator.cpp
index 6e959626d84..93dfe051c7f 100644
--- a/be/src/exec/operator/union_sink_operator.cpp
+++ b/be/src/exec/operator/union_sink_operator.cpp
@@ -134,10 +134,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
-    const auto block_max_bytes = state->block_max_bytes();
+    const auto block_max_bytes = state->preferred_block_size_bytes();
     if (local_state._output_block &&
-        (local_state._output_block->rows() >= state->block_max_rows() ||
-         (block_max_bytes > 0 && local_state._output_block->bytes() >= 
block_max_bytes))) {
+        (local_state._output_block->rows() >= state->batch_size() ||
+         local_state._output_block->bytes() >= block_max_bytes)) {
         RETURN_IF_ERROR(local_state._shared_state->data_queue.push_block(
                 std::move(local_state._output_block), _cur_child_id));
     }
diff --git a/be/src/exec/operator/union_source_operator.cpp 
b/be/src/exec/operator/union_source_operator.cpp
index e0390e63576..a6545429381 100644
--- a/be/src/exec/operator/union_source_operator.cpp
+++ b/be/src/exec/operator/union_source_operator.cpp
@@ -20,7 +20,7 @@
 #include <functional>
 #include <utility>
 
-#include "common/block_budget.h"
+#include "util/block_budget.h"
 #include "common/status.h"
 #include "core/block/block.h"
 #include "core/block/columns_with_type_and_name.h"
@@ -154,7 +154,7 @@ Status UnionSourceOperatorX::get_next_const(RuntimeState* 
state, Block* block) {
     MutableBlock mblock = 
VectorizedUtils::build_mutable_mem_reuse_block(block, row_descriptor());
 
     ColumnsWithTypeAndName tmp_block_columns;
-    const BlockBudget budget(state->block_max_rows(), 
state->block_max_bytes());
+    const BlockBudget budget(state->batch_size(), 
state->preferred_block_size_bytes());
     for (; _const_expr_list_idx < _const_expr_lists.size() &&
            budget.within_budget(mblock.rows(), mblock.bytes());
          ++_const_expr_list_idx) {
diff --git a/be/src/exec/scan/es_scanner.cpp b/be/src/exec/scan/es_scanner.cpp
index 7b92f3e36a0..6e9e81d17c7 100644
--- a/be/src/exec/scan/es_scanner.cpp
+++ b/be/src/exec/scan/es_scanner.cpp
@@ -118,8 +118,8 @@ Status EsScanner::_get_block_impl(RuntimeState* state, 
Block* block, bool* eof)
     std::vector<MutableColumnPtr> columns(column_size);
 
     bool mem_reuse = block->mem_reuse();
-    const int block_max_rows = state->block_max_rows();
-    const size_t block_max_bytes = state->block_max_bytes();
+    const int block_max_rows = state->batch_size();
+    const size_t block_max_bytes = state->preferred_block_size_bytes();
     // only empty block should be here
     DCHECK(block->rows() == 0);
 
@@ -137,7 +137,7 @@ Status EsScanner::_get_block_impl(RuntimeState* state, 
Block* block, bool* eof)
             RETURN_IF_CANCELLED(state);
             // Get from scanner
             RETURN_IF_ERROR(_get_next(columns));
-            if (block_max_bytes > 0 && (columns[0]->size() & 255) == 0) {
+            if ((columns[0]->size() & 255) == 0) {
                 size_t bytes = 0;
                 for (const auto& col : columns) {
                     bytes += col->byte_size();
diff --git a/be/src/exec/scan/file_scanner.cpp 
b/be/src/exec/scan/file_scanner.cpp
index 80d032d76f9..46e4d2e9625 100644
--- a/be/src/exec/scan/file_scanner.cpp
+++ b/be/src/exec/scan/file_scanner.cpp
@@ -215,7 +215,7 @@ Status FileScanner::init(RuntimeState* state, const 
VExprContextSPtrs& conjuncts
 bool FileScanner::_should_enable_adaptive_batch_size(TFileFormatType::type 
format_type) const {
     // Only enable for readers that support set_batch_size().
     // Table-format wrappers are covered because they delegate to native 
readers.
-    if (!config::enable_adaptive_batch_size || 
_state->preferred_block_size_bytes() <= 0) {
+    if (!config::enable_adaptive_batch_size) {
         return false;
     }
     switch (format_type) {
@@ -263,7 +263,7 @@ void 
FileScanner::_init_adaptive_batch_size_state(TFileFormatType::type format_t
             _state->preferred_block_size_bytes(),
             _state->preferred_max_column_in_block_size_bytes(), 0.0,
             std::unordered_map<ColumnId, double> {}, 
ADAPTIVE_BATCH_INITIAL_PROBE_ROWS,
-            _state->preferred_block_size_rows());
+            _state->batch_size());
 }
 
 size_t FileScanner::_predict_reader_batch_rows() {
diff --git a/be/src/exec/scan/olap_scanner.cpp 
b/be/src/exec/scan/olap_scanner.cpp
index 9a8c67a6f28..33bdb575fc0 100644
--- a/be/src/exec/scan/olap_scanner.cpp
+++ b/be/src/exec/scan/olap_scanner.cpp
@@ -167,7 +167,7 @@ Status OlapScanner::prepare() {
     // Adaptive batch size: pass session variable values to the storage reader.
     // The reader will forward them to RowsetReaderContext -> 
StorageReadOptions -> predictor.
     
_tablet_reader->set_preferred_block_size_bytes(_state->preferred_block_size_bytes());
-    
_tablet_reader->set_preferred_block_size_rows(_state->preferred_block_size_rows());
+    _tablet_reader->set_preferred_block_size_rows(_state->batch_size());
     
_tablet_reader->set_preferred_max_col_bytes(_state->preferred_max_column_in_block_size_bytes());
     TabletSchemaSPtr cached_schema;
     std::string schema_key;
diff --git a/be/src/exec/scan/scanner.cpp b/be/src/exec/scan/scanner.cpp
index a1e6ccc8e7b..9bb55e02f34 100644
--- a/be/src/exec/scan/scanner.cpp
+++ b/be/src/exec/scan/scanner.cpp
@@ -86,18 +86,17 @@ Status Scanner::get_block_after_projects(RuntimeState* 
state, Block* block, bool
             _padding_block.swap(_origin_block);
         } else {
             
_origin_block.clear_column_data(row_descriptor.num_materialized_slots());
-            const auto min_batch_size = std::max(state->block_max_rows() / 2, 
1);
-            const auto block_max_bytes = state->block_max_bytes();
+            const auto min_batch_size = std::max(state->batch_size() / 2, 1);
+            const auto block_max_bytes = state->preferred_block_size_bytes();
             while (_padding_block.rows() < min_batch_size &&
-                   (block_max_bytes == 0 || _padding_block.bytes() < 
block_max_bytes) && !*eos) {
+                   _padding_block.bytes() < block_max_bytes && !*eos) {
                 RETURN_IF_ERROR(get_block(state, &_origin_block, eos));
                 if (_origin_block.rows() >= min_batch_size) {
                     break;
                 }
 
-                if (_origin_block.rows() + _padding_block.rows() <= 
state->block_max_rows() &&
-                    (block_max_bytes == 0 ||
-                     _origin_block.bytes() + _padding_block.bytes() <= 
block_max_bytes)) {
+                if (_origin_block.rows() + _padding_block.rows() <= 
state->batch_size() &&
+                    _origin_block.bytes() + _padding_block.bytes() <= 
block_max_bytes) {
                     RETURN_IF_ERROR(_merge_padding_block());
                     
_origin_block.clear_column_data(row_descriptor.num_materialized_slots());
                 } else {
diff --git a/be/src/exec/sort/heap_sorter.cpp b/be/src/exec/sort/heap_sorter.cpp
index 79c8dbed55f..11e401c668f 100644
--- a/be/src/exec/sort/heap_sorter.cpp
+++ b/be/src/exec/sort/heap_sorter.cpp
@@ -102,7 +102,7 @@ Status HeapSorter::prepare_for_read(bool is_spill) {
 }
 
 Status HeapSorter::get_next(RuntimeState* state, Block* block, bool* eos) {
-    return _state->merge_sort_read(block, state->block_max_rows(), eos, 
state->block_max_bytes());
+    return _state->merge_sort_read(block, state->batch_size(), eos, 
state->preferred_block_size_bytes());
 }
 
 Field HeapSorter::get_top_value() {
diff --git a/be/src/exec/sort/partition_sorter.cpp 
b/be/src/exec/sort/partition_sorter.cpp
index 7af9d7fa9a1..2be26077a27 100644
--- a/be/src/exec/sort/partition_sorter.cpp
+++ b/be/src/exec/sort/partition_sorter.cpp
@@ -95,9 +95,9 @@ void PartitionSorter::reset_sorter_state(RuntimeState* 
runtime_state) {
 
 Status PartitionSorter::get_next(RuntimeState* state, Block* block, bool* eos) 
{
     if (_top_n_algorithm == TopNAlgorithm::ROW_NUMBER) {
-        return _read_row_num(block, eos, state->block_max_rows(), 
state->block_max_bytes());
+        return _read_row_num(block, eos, state->batch_size(), 
state->preferred_block_size_bytes());
     } else {
-        return _read_row_rank(block, eos, state->block_max_rows(), 
state->block_max_bytes());
+        return _read_row_rank(block, eos, state->batch_size(), 
state->preferred_block_size_bytes());
     }
 }
 
@@ -152,6 +152,7 @@ Status PartitionSorter::_read_row_num(Block* output_block, 
bool* eos, int batch_
             queue.remove_top();
         }
 
+        // block_max_bytes == 0 means no byte budget.
         if (block_max_bytes > 0 && merged_rows > 0 && m_block.bytes() >= 
block_max_bytes) {
             break;
         }
@@ -205,6 +206,7 @@ Status PartitionSorter::_read_row_rank(Block* output_block, 
bool* eos, int batch
                 queue.remove_top();
             }
 
+            // block_max_bytes == 0 means no byte budget.
             if (block_max_bytes > 0 && (merged_rows & 255) == 0 &&
                 m_block.bytes() >= block_max_bytes) {
                 return Status::OK();
diff --git a/be/src/exec/sort/sorter.cpp b/be/src/exec/sort/sorter.cpp
index e06099dc1e3..b60d61926ae 100644
--- a/be/src/exec/sort/sorter.cpp
+++ b/be/src/exec/sort/sorter.cpp
@@ -127,6 +127,7 @@ void MergeSorterState::_merge_sort_read_impl(int 
batch_size, doris::Block* block
             _queue.remove_top();
         }
 
+        // block_max_bytes == 0 means no byte budget.
         if (block_max_bytes > 0 && merged_rows > 0 && m_block.bytes() >= 
block_max_bytes) {
             break;
         }
@@ -209,9 +210,9 @@ size_t FullSorter::get_reserve_mem_size(RuntimeState* 
state, bool eos) const {
         const auto bytes = _state->unsorted_block()->bytes();
         const auto allocated_bytes = 
_state->unsorted_block()->allocated_bytes();
         const auto bytes_per_row = bytes / rows;
-        const auto estimated_size_of_next_block = bytes_per_row * 
state->block_max_rows();
+        const auto estimated_size_of_next_block = bytes_per_row * 
state->batch_size();
         auto new_block_bytes = estimated_size_of_next_block + bytes;
-        auto new_rows = rows + state->block_max_rows();
+        auto new_rows = rows + state->batch_size();
         // If the new size is greater than 85% of allocalted bytes, it maybe 
need to realloc.
         if ((new_block_bytes * 100 / allocated_bytes) >= 85) {
             size_to_reserve += (size_t)(allocated_bytes * 1.15);
@@ -278,12 +279,12 @@ Status FullSorter::prepare_for_read(bool is_spill) {
 }
 
 Status FullSorter::get_next(RuntimeState* state, Block* block, bool* eos) {
-    return _state->merge_sort_read(block, state->block_max_rows(), eos, 
state->block_max_bytes());
+    return _state->merge_sort_read(block, state->batch_size(), eos, 
state->preferred_block_size_bytes());
 }
 
 Status FullSorter::merge_sort_read_for_spill(RuntimeState* state, 
doris::Block* block,
                                              int batch_size, bool* eos) {
-    return _state->merge_sort_read(block, batch_size, eos, 
state->block_max_bytes());
+    return _state->merge_sort_read(block, batch_size, eos, 
state->preferred_block_size_bytes());
 }
 
 Status FullSorter::do_sort() {
diff --git a/be/src/exec/sort/topn_sorter.cpp b/be/src/exec/sort/topn_sorter.cpp
index 6083675e9d7..efa8cf5cd86 100644
--- a/be/src/exec/sort/topn_sorter.cpp
+++ b/be/src/exec/sort/topn_sorter.cpp
@@ -59,7 +59,7 @@ Status TopNSorter::prepare_for_read(bool is_spill) {
 }
 
 Status TopNSorter::get_next(RuntimeState* state, Block* block, bool* eos) {
-    return _state->merge_sort_read(block, state->block_max_rows(), eos, 
state->block_max_bytes());
+    return _state->merge_sort_read(block, state->batch_size(), eos, 
state->preferred_block_size_bytes());
 }
 
 Status TopNSorter::_do_sort(Block* block) {
diff --git a/be/src/exec/sort/vsorted_run_merger.cpp 
b/be/src/exec/sort/vsorted_run_merger.cpp
index 88e139d201a..b5dab055761 100644
--- a/be/src/exec/sort/vsorted_run_merger.cpp
+++ b/be/src/exec/sort/vsorted_run_merger.cpp
@@ -118,10 +118,9 @@ Status VSortedRunMerger::get_next(Block* output_block, 
bool* eos) {
     if (_priority_queue.empty()) {
         *eos = true;
         return Status::OK();
-    } else if (_priority_queue.size() == 1 && _block_max_bytes == 0) {
-        // Single-run fast path: swap the entire remaining supplier block into 
output.
-        // When byte budget is active, fall through to the general merge path 
which
-        // already respects _block_max_bytes.
+    } else if (_priority_queue.size() == 1) {
+        // Single-run fast path: cut/swap the supplier block into output.
+        // Uses column->cut() which is O(columns) instead of row-by-row merge 
O(rows*columns).
         auto current = _priority_queue.top();
         DCHECK(!current->eof());
         DCHECK(current->block_ptr() != nullptr);
@@ -140,21 +139,42 @@ Status VSortedRunMerger::get_next(Block* output_block, 
bool* eos) {
             }
         }
 
-        if (!current->is_first()) {
-            for (int i = 0; i < current->block->columns(); i++) {
-                auto& column_with_type = 
current->block_ptr()->get_by_position(i);
-                column_with_type.column =
-                        column_with_type.column->cut(current->pos, 
current->rows - current->pos);
+        size_t remaining = current->rows - current->pos;
+        size_t output_rows = std::min(remaining, _batch_size);
+
+        // Apply byte budget: estimate rows that fit within _block_max_bytes.
+        // _block_max_bytes == 0 means no byte budget (e.g., iceberg sort 
writer).
+        if (_block_max_bytes > 0 && remaining > 1 && 
current->block_ptr()->bytes() > 0) {
+            size_t bytes_per_row = current->block_ptr()->bytes() / 
current->rows;
+            if (bytes_per_row > 0) {
+                size_t byte_limited = _block_max_bytes / bytes_per_row;
+                output_rows = std::min(output_rows, std::max(size_t(1), 
byte_limited));
             }
         }
-        current->block_ptr()->swap(*output_block);
-        current->next(current->rows - current->pos);
-        if (current->eof()) {
-            *eos = true;
+
+        if (current->is_first() && output_rows == remaining) {
+            // Entire block fits — zero-copy swap.
+            current->block_ptr()->swap(*output_block);
         } else {
-            _pending_cursor = current.impl;
+            // Build output block from cut columns without modifying the 
supplier block.
+            // This preserves remaining rows for subsequent get_next calls.
+            auto* src_block = current->block_ptr();
+            output_block->clear();
+            for (int i = 0; i < src_block->columns(); i++) {
+                auto col_with_type = src_block->get_by_position(i);
+                col_with_type.column = col_with_type.column->cut(current->pos, 
output_rows);
+                output_block->insert(std::move(col_with_type));
+            }
+        }
+        current->next(output_rows);
+        if (output_rows >= remaining) {
+            _priority_queue.pop();
+            if (current->eof()) {
+                *eos = true;
+            } else {
+                _pending_cursor = current.impl;
+            }
         }
-        _priority_queue.pop();
         return Status::OK();
     } else {
         size_t num_columns = _priority_queue.top().impl->block->columns();
@@ -205,10 +225,11 @@ Status VSortedRunMerger::get_next(Block* output_block, 
bool* eos) {
                 return Status::OK();
             }
 
-            if (_block_max_bytes > 0 && merged_rows > 0 && (merged_rows & 255) 
== 0 &&
+            if (merged_rows > 0 && (merged_rows & 255) == 0 &&
                 !_indexs.empty()) {
                 do_insert();
-                if (m_block.bytes() >= _block_max_bytes) {
+                // _block_max_bytes == 0 means no byte budget.
+                if (_block_max_bytes > 0 && m_block.bytes() >= 
_block_max_bytes) {
                     break;
                 }
             }
diff --git a/be/src/format/csv/csv_reader.cpp b/be/src/format/csv/csv_reader.cpp
index acac156a7d2..679db5d1fec 100644
--- a/be/src/format/csv/csv_reader.cpp
+++ b/be/src/format/csv/csv_reader.cpp
@@ -320,8 +320,8 @@ Status CsvReader::get_next_block(Block* block, size_t* 
read_rows, bool* eof) {
         return Status::OK();
     }
 
-    const size_t batch_size = _state->block_max_rows();
-    const auto max_block_bytes = _state->block_max_bytes();
+    const size_t batch_size = _state->batch_size();
+    const auto max_block_bytes = _state->preferred_block_size_bytes();
     size_t rows = 0;
 
     bool success = false;
diff --git a/be/src/format/json/new_json_reader.cpp 
b/be/src/format/json/new_json_reader.cpp
index 1c211cd263e..9d20aab37a0 100644
--- a/be/src/format/json/new_json_reader.cpp
+++ b/be/src/format/json/new_json_reader.cpp
@@ -207,8 +207,8 @@ Status NewJsonReader::get_next_block(Block* block, size_t* 
read_rows, bool* eof)
         return Status::OK();
     }
 
-    const auto batch_size = _state->block_max_rows();
-    const auto max_block_bytes = _state->block_max_bytes();
+    const auto batch_size = _state->batch_size();
+    const auto max_block_bytes = _state->preferred_block_size_bytes();
 
     size_t next_checking_rows = *read_rows + 1;
     while (block->rows() < batch_size && !_reader_eof) {
diff --git a/be/src/format/json/new_json_reader.h 
b/be/src/format/json/new_json_reader.h
index 2f04e281528..a8f4540865e 100644
--- a/be/src/format/json/new_json_reader.h
+++ b/be/src/format/json/new_json_reader.h
@@ -81,6 +81,9 @@ public:
             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;
+    // Row-based readers control throughput via row count, not byte budget.
+    // The FileScanner's AdaptiveBlockSizePredictor converts the byte budget
+    // into a predicted row count and calls set_batch_size() with it.
     void set_batch_size(size_t batch_size) override;
     size_t get_batch_size() const override { return _batch_size; }
     Status get_columns(std::unordered_map<std::string, DataTypePtr>* 
name_to_type,
diff --git a/be/src/runtime/runtime_profile_counter_names.h 
b/be/src/runtime/runtime_profile_counter_names.h
index 5b0bd86f474..bd4d2e878a8 100644
--- a/be/src/runtime/runtime_profile_counter_names.h
+++ b/be/src/runtime/runtime_profile_counter_names.h
@@ -34,6 +34,9 @@ inline constexpr char FAKER_PROFILE[] = "faker profile";
 // ============================================================
 inline constexpr char ROWS_PRODUCED[] = "RowsProduced";
 inline constexpr char BLOCKS_PRODUCED[] = "BlocksProduced";
+inline constexpr char OUTPUT_BLOCK_BYTES[] = "OutputBlockBytes";
+inline constexpr char MAX_OUTPUT_BLOCK_BYTES[] = "MaxOutputBlockBytes";
+inline constexpr char MIN_OUTPUT_BLOCK_BYTES[] = "MinOutputBlockBytes";
 
 // ============================================================
 // Sink operator common counters (PipelineXSinkLocalState::init)
diff --git a/be/src/runtime/runtime_state.h b/be/src/runtime/runtime_state.h
index d93998da69c..e53729dae0c 100644
--- a/be/src/runtime/runtime_state.h
+++ b/be/src/runtime/runtime_state.h
@@ -139,41 +139,37 @@ public:
     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;
+    // 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);
     }
 
-    MOCK_FUNCTION int batch_size() const { return _query_options.batch_size; }
+    // 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 {
-        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;
+        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 0;
+        return kDefault;
     }
 
+    // Per-column byte limit for adaptive chunk rows (default 1MB, range 
[256KB, 128MB]).
+    // Consistent with SessionVariable.preferredMaxColumnInBlockSizeBytes on 
FE side.
     MOCK_FUNCTION size_t preferred_max_column_in_block_size_bytes() const {
+        static constexpr size_t kDefault = 1048576UL; // 1MB
         if (_query_options.__isset.preferred_max_column_in_block_size_bytes) {
             auto v = _query_options.preferred_max_column_in_block_size_bytes;
-            return v > 0 ? static_cast<size_t>(v) : 0;
+            return v > 0 ? static_cast<size_t>(v) : kDefault;
         }
-        return 1048576UL; // 1MB default
-    }
-    MOCK_FUNCTION size_t preferred_block_size_rows() const {
-        if (_query_options.__isset.preferred_block_size_rows) {
-            auto v = _query_options.preferred_block_size_rows;
-            return v > 0 ? static_cast<size_t>(v) : 65535;
-        }
-        return 65535;
+        return kDefault;
     }
+
     int query_parallel_instance_num() const { return 
_query_options.parallel_instance; }
     int max_errors() const { return _query_options.max_errors; }
     int execution_timeout() const {
diff --git a/be/src/common/block_budget.h b/be/src/util/block_budget.h
similarity index 93%
rename from be/src/common/block_budget.h
rename to be/src/util/block_budget.h
index 509e751043b..f9b47c512d3 100644
--- a/be/src/common/block_budget.h
+++ b/be/src/util/block_budget.h
@@ -28,20 +28,18 @@ namespace doris {
 // helper methods instead of reimplementing the same row/byte logic inline.
 //
 // Typical usage:
-//   BlockBudget budget(state->block_max_rows(), state->block_max_bytes());
+//   BlockBudget budget(state->batch_size(), 
state->preferred_block_size_bytes());
 //   size_t eff = budget.effective_max_rows(estimated_row_bytes);
 //   while (budget.within_budget(block.rows(), block.bytes())) { ... }
 //
 struct BlockBudget {
     size_t max_rows;
-    size_t max_bytes; // 0 = byte budget disabled
+    size_t max_bytes; // byte budget from preferred_block_size_bytes(), always 
> 0
 
     BlockBudget(size_t max_rows_, size_t max_bytes_) : max_rows(max_rows_), 
max_bytes(max_bytes_) {}
 
-    bool has_byte_budget() const { return max_bytes > 0; }
-
     // Pre-compute effective row limit from an estimated average row byte size.
-    // When byte budget is disabled or estimated_row_bytes == 0, returns 
max_rows.
+    // When max_bytes == 0 or estimated_row_bytes == 0, returns max_rows.
     // Always returns at least 1.
     size_t effective_max_rows(size_t estimated_row_bytes) const {
         if (max_bytes > 0 && estimated_row_bytes > 0) {
diff --git a/be/test/common/block_budget_test.cpp 
b/be/test/common/block_budget_test.cpp
index 8f2dd5a57ed..6eb6a7be7a5 100644
--- a/be/test/common/block_budget_test.cpp
+++ b/be/test/common/block_budget_test.cpp
@@ -15,7 +15,7 @@
 // specific language governing permissions and limitations
 // under the License.
 
-#include "common/block_budget.h"
+#include "util/block_budget.h"
 
 #include <gtest/gtest.h>
 
@@ -122,11 +122,4 @@ TEST_F(BlockBudgetTest, RemainingRowsZeroCurrentBytes) {
     EXPECT_EQ(b.remaining_rows(50, 0), 50);
 }
 
-// ── has_byte_budget ─────────────────────────────────────────────────────────
-
-TEST_F(BlockBudgetTest, HasByteBudget) {
-    EXPECT_FALSE(BlockBudget(100, 0).has_byte_budget());
-    EXPECT_TRUE(BlockBudget(100, 1).has_byte_budget());
-}
-
 } // namespace doris
diff --git a/be/test/core/value/sort_merger_test.cpp 
b/be/test/core/value/sort_merger_test.cpp
index 9af8b16c531..8e7f0b88cc4 100644
--- a/be/test/core/value/sort_merger_test.cpp
+++ b/be/test/core/value/sort_merger_test.cpp
@@ -667,4 +667,76 @@ TEST(SortMergerTest, BLOCK_MAX_BYTES_WITH_MANY_ROWS) {
     }
 }
 
-} // namespace doris
\ No newline at end of file
+TEST(SortMergerTest, SINGLE_RUN_FAST_PATH_BYTE_BUDGET) {
+    /**
+     * Single-run fast path with byte budget: 1 child providing 256 rows in 
one block.
+     * batch_size=4096, block_max_bytes=100.
+     * Each nullable Int64 row ≈ 9 bytes (8 data + 1 null).
+     * byte_limited ≈ 100/9 ≈ 11 rows per output block.
+     * Verifies:
+     *   - All rows are output (no data loss from cut on supplier block)
+     *   - Multiple output blocks are produced (byte budget limits each block)
+     *   - Data is sorted correctly
+     */
+    const int batch_size = 4096;
+    const size_t block_max_bytes = 100;
+    const int total_rows = 256;
+
+    std::unique_ptr<VSortedRunMerger> merger;
+    auto profile = std::make_shared<RuntimeProfile>("");
+    auto ordering_expr = MockSlotRef::create_mock_contexts(
+            
std::make_shared<DataTypeNullable>(std::make_shared<DataTypeInt64>()));
+    {
+        std::vector<bool> is_asc_order = {true};
+        std::vector<bool> nulls_first = {false};
+        merger.reset(new VSortedRunMerger(ordering_expr, is_asc_order, 
nulls_first, batch_size, -1,
+                                          0, profile.get(), block_max_bytes));
+    }
+    {
+        int supply_count = 0;
+        std::vector<BlockSupplier> child_block_suppliers;
+        BlockSupplier block_supplier = [&supply_count](Block* block, bool* 
eos) {
+            std::vector<Int64> values;
+            std::vector<UInt8> null_map;
+            for (int i = 0; i < 256; i++) {
+                values.push_back(i);
+                null_map.push_back(0);
+            }
+            *block = 
ColumnHelper::create_nullable_block<DataTypeInt64>(values, null_map);
+            supply_count++;
+            *eos = true;
+            return Status::OK();
+        };
+        child_block_suppliers.push_back(block_supplier);
+        EXPECT_TRUE(merger->prepare(child_block_suppliers).ok());
+        EXPECT_EQ(merger->_priority_queue.size(), 1) << "single child = 
single-run fast path";
+    }
+    {
+        size_t total_output_rows = 0;
+        int num_blocks = 0;
+        Int64 last_value = -1;
+        bool eos = false;
+        while (!eos) {
+            Block block;
+            EXPECT_TRUE(merger->get_next(&block, &eos).ok());
+            if (block.rows() > 0) {
+                num_blocks++;
+                // Verify sorted order and continuity
+                auto col = block.get_by_position(0).column;
+                auto nullable_col =
+                        assert_cast<const 
ColumnNullable*>(col.get())->get_nested_column_ptr();
+                auto* data = assert_cast<const 
ColumnInt64*>(nullable_col.get())->get_data().data();
+                for (size_t i = 0; i < block.rows(); i++) {
+                    EXPECT_EQ(data[i], last_value + 1)
+                            << "row " << (total_output_rows + i) << " 
mismatch";
+                    last_value = data[i];
+                }
+                total_output_rows += block.rows();
+            }
+        }
+        EXPECT_EQ(total_output_rows, total_rows) << "all rows must be output 
(no data loss)";
+        EXPECT_GT(num_blocks, 1) << "byte budget should produce multiple 
blocks";
+    }
+}
+
+} // namespace doris
diff --git a/be/test/exec/operator/agg_operator_test.cpp 
b/be/test/exec/operator/agg_operator_test.cpp
index a1ce94482dc..cdacdcff0ae 100644
--- a/be/test/exec/operator/agg_operator_test.cpp
+++ b/be/test/exec/operator/agg_operator_test.cpp
@@ -727,7 +727,7 @@ TEST_F(AggOperatorTestWithGroupBy, 
ByteBudgetLimitsOutputRows) {
     ctx.state._batch_size = 4096;
     ctx.state._query_options.__set_batch_size(4096);
     ctx.state._query_options.__set_preferred_block_size_bytes(1);
-    ctx.state._query_options.__set_preferred_block_size_rows(65535);
+    ctx.state._query_options.__set_batch_size(65535);
 
     auto sink_op = std::make_shared<MockAggsinkOperator>();
     sink_op->_aggregate_evaluators.push_back(create_mock_agg_fn_evaluator(
diff --git 
a/be/test/exec/operator/distinct_streaming_aggregation_operator_test.cpp 
b/be/test/exec/operator/distinct_streaming_aggregation_operator_test.cpp
index 4b533f5b659..5b43fe32c34 100644
--- a/be/test/exec/operator/distinct_streaming_aggregation_operator_test.cpp
+++ b/be/test/exec/operator/distinct_streaming_aggregation_operator_test.cpp
@@ -36,7 +36,7 @@ struct DistinctStreamingAggOperatorTest : public 
::testing::Test {
         state = std::make_shared<MockRuntimeState>();
         state->_batch_size = 10;
         state->_query_options.__set_batch_size(10);
-        state->_query_options.__set_preferred_block_size_rows(10);
+        state->_query_options.__set_batch_size(10);
         op->_child = mock_op;
     }
 
@@ -203,7 +203,7 @@ TEST_F(DistinctStreamingAggOperatorTest, 
ByteBudgetLimitsOutputBlock) {
     state->_batch_size = 4096;
     state->_query_options.__set_batch_size(4096);
     state->_query_options.__set_preferred_block_size_bytes(1);
-    state->_query_options.__set_preferred_block_size_rows(65535);
+    state->_query_options.__set_batch_size(65535);
 
     op->_is_streaming_preagg = false;
     create_op({std::make_shared<DataTypeInt64>()}, 
{std::make_shared<DataTypeInt64>()});
diff --git a/be/test/exec/operator/hashjoin_probe_operator_test.cpp 
b/be/test/exec/operator/hashjoin_probe_operator_test.cpp
index 1616ada7db1..73e78185a8e 100644
--- a/be/test/exec/operator/hashjoin_probe_operator_test.cpp
+++ b/be/test/exec/operator/hashjoin_probe_operator_test.cpp
@@ -1256,7 +1256,7 @@ TEST_F(HashJoinProbeOperatorTest, 
InnerJoinWithAdaptiveBatchSize) {
     auto saved = config::enable_adaptive_batch_size;
     config::enable_adaptive_batch_size = true;
     
_helper.runtime_state->_query_options.__set_preferred_block_size_bytes(512);
-    
_helper.runtime_state->_query_options.__set_preferred_block_size_rows(65535);
+    _helper.runtime_state->_query_options.__set_batch_size(65535);
 
     auto sink_block = ColumnHelper::create_block<DataTypeInt32>({1, 2, 3, 4, 
5});
     
sink_block.insert(ColumnHelper::create_nullable_column_with_name<DataTypeString>(
diff --git a/be/test/exec/operator/set_operator_test.cpp 
b/be/test/exec/operator/set_operator_test.cpp
index 90e97b5a970..f8ebea809fd 100644
--- a/be/test/exec/operator/set_operator_test.cpp
+++ b/be/test/exec/operator/set_operator_test.cpp
@@ -695,7 +695,7 @@ TEST_F(ExceptOperatorTest, ByteBudgetLimitsOutputRows) {
     config::enable_adaptive_batch_size = true;
     state->_batch_size = 4096;
     state->_query_options.__set_preferred_block_size_bytes(1);
-    state->_query_options.__set_preferred_block_size_rows(65535);
+    state->_query_options.__set_batch_size(65535);
 
     init_op(2, 
{std::make_shared<DataTypeNullable>(std::make_shared<DataTypeInt64>())});
     sink_op->_child_exprs = MockSlotRef::create_mock_contexts(
diff --git a/be/test/exec/operator/streaming_agg_operator_test.cpp 
b/be/test/exec/operator/streaming_agg_operator_test.cpp
index d8e8fa3e377..926652d22d5 100644
--- a/be/test/exec/operator/streaming_agg_operator_test.cpp
+++ b/be/test/exec/operator/streaming_agg_operator_test.cpp
@@ -402,7 +402,7 @@ TEST_F(StreamingAggOperatorTest, 
ByteBudgetLimitsEffectiveMaxRows) {
     state->_batch_size = 4096;
     state->_query_options.__set_batch_size(4096);
     state->_query_options.__set_preferred_block_size_bytes(1);
-    state->_query_options.__set_preferred_block_size_rows(65535);
+    state->_query_options.__set_batch_size(65535);
 
     op->_aggregate_evaluators.push_back(create_mock_agg_fn_evaluator(
             pool, MockSlotRef::create_mock_contexts(1, 
std::make_shared<DataTypeInt64>()), false,
diff --git a/be/test/exec/operator/table_function_operator_test.cpp 
b/be/test/exec/operator/table_function_operator_test.cpp
index aa9f4b18dea..b8d3ac2d2a0 100644
--- a/be/test/exec/operator/table_function_operator_test.cpp
+++ b/be/test/exec/operator/table_function_operator_test.cpp
@@ -415,7 +415,6 @@ TEST_F(TableFunctionOperatorTest, block_fast_path_explode) {
 TEST_F(TableFunctionOperatorTest, block_fast_path_explode_batch_truncate) {
     state->_batch_size = 2;
     state->_query_options.__set_batch_size(2);
-    state->_query_options.__set_preferred_block_size_rows(2);
     bool get_value_called = false;
     auto int_type = std::make_shared<DataTypeInt32>();
     auto arr_type = std::make_shared<DataTypeArray>(int_type);
@@ -660,7 +659,6 @@ TEST_F(TableFunctionOperatorTest,
        block_fast_path_explode_nullable_array_partial_gap_uses_slow_path) {
     state->_batch_size = 2;
     state->_query_options.__set_batch_size(2);
-    state->_query_options.__set_preferred_block_size_rows(2);
     bool get_value_called = false;
     auto int_type = std::make_shared<DataTypeInt32>();
     auto arr_type = 
std::make_shared<DataTypeNullable>(std::make_shared<DataTypeArray>(int_type));
@@ -2174,7 +2172,7 @@ TEST_F(TableFunctionOperatorTest, 
ByteBudgetLimitsOutputRows) {
     config::enable_adaptive_batch_size = true;
     state->_batch_size = 4096;
     state->_query_options.__set_preferred_block_size_bytes(1);
-    state->_query_options.__set_preferred_block_size_rows(65535);
+    state->_query_options.__set_batch_size(65535);
 
     bool get_value_called = false;
     auto array_type = 
std::make_shared<DataTypeArray>(std::make_shared<DataTypeInt32>());
diff --git a/be/test/exec/operator/union_operator_test.cpp 
b/be/test/exec/operator/union_operator_test.cpp
index ed1bed563ae..8287cc5d9a6 100644
--- a/be/test/exec/operator/union_operator_test.cpp
+++ b/be/test/exec/operator/union_operator_test.cpp
@@ -77,7 +77,7 @@ struct UnionOperatorTest : public ::testing::Test {
 TEST_F(UnionOperatorTest, test_all_const_expr) {
     state->_batch_size = 2;
     state->_query_options.__set_batch_size(2);
-    state->_query_options.__set_preferred_block_size_rows(2);
+    state->_query_options.__set_batch_size(2);
     source_op.reset(new MockUnionSourceOperator {
             0,
             {std::make_shared<DataTypeInt64>(), 
std::make_shared<DataTypeInt64>(),
@@ -258,7 +258,7 @@ TEST_F(UnionOperatorTest, test_sink_and_source) {
         for (int i = 0; i < child_size; i++) {
             sink_state[i]->_batch_size = 2;
             sink_state[i]->_query_options.__set_batch_size(2);
-            sink_state[i]->_query_options.__set_preferred_block_size_rows(2);
+            sink_state[i]->_query_options.__set_batch_size(2);
             Block block = ColumnHelper::create_block<DataTypeInt64>({1, 2}, 
{3, 4});
             EXPECT_TRUE(sink_ops[i]->sink(sink_state[i].get(), &block, false));
         }
@@ -304,7 +304,7 @@ TEST_F(UnionOperatorTest, ByteBudgetLimitsConstExprOutput) {
     state->_batch_size = 2;
     state->_query_options.__set_batch_size(2);
     state->_query_options.__set_preferred_block_size_bytes(1);
-    state->_query_options.__set_preferred_block_size_rows(2);
+    state->_query_options.__set_batch_size(2);
 
     source_op.reset(new MockUnionSourceOperator {
             0, // child_size=0 means const-only
@@ -331,7 +331,7 @@ TEST_F(UnionOperatorTest, ByteBudgetLimitsConstExprOutput) {
         EXPECT_TRUE(source_local_state->open(state.get()));
     }
 
-    // Pull all const expr output. With tiny byte budget and 
preferred_block_size_rows=2,
+    // Pull all const expr output. With tiny byte budget and batch_size=2,
     // each get_block returns at most 2 const rows, and once bytes exceed 1, 
it stops.
     size_t total_rows = 0;
     int calls = 0;
diff --git a/be/test/exec/sort/full_sort_test.cpp 
b/be/test/exec/sort/full_sort_test.cpp
index 23b364c53d2..750f01aeacb 100644
--- a/be/test/exec/sort/full_sort_test.cpp
+++ b/be/test/exec/sort/full_sort_test.cpp
@@ -129,7 +129,6 @@ TEST_F(FullSorterTest, test_get_next_block_max_bytes) {
     auto saved_adaptive = config::enable_adaptive_batch_size;
     config::enable_adaptive_batch_size = true;
     _state._query_options.__set_batch_size(1000);
-    _state._query_options.__set_preferred_block_size_rows(1000);
     _state._query_options.__set_preferred_block_size_bytes(50);
 
     sorter = FullSorter::create_unique(sort_exec_exprs, -1, 0, &pool, 
is_asc_order, nulls_first,
@@ -169,7 +168,6 @@ TEST_F(FullSorterTest, 
test_merge_sort_read_for_spill_block_max_bytes) {
     auto saved_adaptive = config::enable_adaptive_batch_size;
     config::enable_adaptive_batch_size = true;
     _state._query_options.__set_batch_size(1000);
-    _state._query_options.__set_preferred_block_size_rows(1000);
     _state._query_options.__set_preferred_block_size_bytes(50);
 
     sorter = FullSorter::create_unique(sort_exec_exprs, -1, 0, &pool, 
is_asc_order, nulls_first,
diff --git a/be/test/exec/sort/partition_sorter_test.cpp 
b/be/test/exec/sort/partition_sorter_test.cpp
index 5d8bdfaa480..56a68f03536 100644
--- a/be/test/exec/sort/partition_sorter_test.cpp
+++ b/be/test/exec/sort/partition_sorter_test.cpp
@@ -203,7 +203,6 @@ TEST_F(PartitionSorterTest, 
test_partition_sorter_ROW_NUMBER_block_max_bytes) {
     auto saved_adaptive = config::enable_adaptive_batch_size;
     config::enable_adaptive_batch_size = true;
     _state._query_options.__set_batch_size(1000);
-    _state._query_options.__set_preferred_block_size_rows(1000);
     _state._query_options.__set_preferred_block_size_bytes(50);
 
     sorter = PartitionSorter::create_unique(sort_exec_exprs, -1, 0, &pool, 
is_asc_order,
@@ -251,7 +250,6 @@ TEST_F(PartitionSorterTest, 
test_partition_sorter_RANK_block_max_bytes) {
     auto saved_adaptive = config::enable_adaptive_batch_size;
     config::enable_adaptive_batch_size = true;
     _state._query_options.__set_batch_size(2000);
-    _state._query_options.__set_preferred_block_size_rows(2000);
     _state._query_options.__set_preferred_block_size_bytes(50);
 
     SortCursorCmp previous_row;
diff --git a/be/test/storage/iterator/block_reader_batch_max_rows_test.cpp 
b/be/test/storage/iterator/block_reader_batch_max_rows_test.cpp
index b93588fd11c..65d1881e508 100644
--- a/be/test/storage/iterator/block_reader_batch_max_rows_test.cpp
+++ b/be/test/storage/iterator/block_reader_batch_max_rows_test.cpp
@@ -86,7 +86,7 @@ TEST_F(BlockReaderBatchMaxRowsTest, 
FallbackWhenByteBudgetIsZero) {
     reader._reader_context.preferred_block_size_bytes = 0;
 
     // When byte budget is zero, batch_max_rows falls back to batch_size
-    // regardless of preferred_block_size_rows.
+    // regardless of batch_size.
     EXPECT_EQ(reader.batch_max_rows(), 4096);
 }
 
@@ -96,7 +96,7 @@ TEST_F(BlockReaderBatchMaxRowsTest, DefaultPreferredRows) {
     BlockReader reader;
     reader._reader_context.batch_size = 4096;
     reader._reader_context.preferred_block_size_bytes = 8388608; // byte 
budget must be active
-    // default preferred_block_size_rows is 65535
+    // default batch_size is 65535
 
     EXPECT_EQ(reader.batch_max_rows(), 65535);
 }
diff --git a/be/test/storage/segment/adaptive_block_size_predictor_test.cpp 
b/be/test/storage/segment/adaptive_block_size_predictor_test.cpp
index aad9a412c39..697e54b5643 100644
--- a/be/test/storage/segment/adaptive_block_size_predictor_test.cpp
+++ b/be/test/storage/segment/adaptive_block_size_predictor_test.cpp
@@ -471,7 +471,7 @@ TEST_F(AdaptiveBlockSizePredictorTest, 
PredictProbeRowsOneWorks) {
     EXPECT_EQ(pred.predict_next_rows(), 1u);
 }
 
-// ── preferred_block_size_rows tests ─────────────────────────────────────────
+// ── batch_size tests ────────────────────────────────────────────────────────
 
 TEST_F(AdaptiveBlockSizePredictorTest, DefaultBlockSizeRows) {
     AdaptiveBlockSizePredictor pred(kBlockBytes, kColBytes, 0.0);
diff --git a/be/test/storage/test_data/tablet_meta_test.hdr 
b/be/test/storage/test_data/tablet_meta_test.hdr
new file mode 100644
index 00000000000..017dbd8e748
Binary files /dev/null and b/be/test/storage/test_data/tablet_meta_test.hdr 
differ
diff --git a/be/test/testutil/mock/mock_runtime_state.h 
b/be/test/testutil/mock/mock_runtime_state.h
index 1fd36663101..fae90a6adad 100644
--- a/be/test/testutil/mock/mock_runtime_state.h
+++ b/be/test/testutil/mock/mock_runtime_state.h
@@ -56,7 +56,6 @@ public:
             : RuntimeState(query_id, fragment_id, query_options, 
query_globals, exec_env, ctx) {}
 
     int batch_size() const override { return _batch_size; }
-    int block_max_rows() const override { return _batch_size; }
 
     bool enable_shared_exchange_sink_buffer() const override {
         return _enable_shared_exchange_sink_buffer;
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
index 8acac9ed189..e1afa33a7cf 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
@@ -165,7 +165,6 @@ public class SessionVariable implements Serializable, 
Writable {
     public static final String BATCH_SIZE = "batch_size";
     public static final String BROKER_LOAD_BATCH_SIZE = 
"broker_load_batch_size";
     public static final String PREFERRED_BLOCK_SIZE_BYTES = 
"preferred_block_size_bytes";
-    public static final String PREFERRED_BLOCK_SIZE_ROWS = 
"preferred_block_size_rows";
     public static final String PREFERRED_MAX_COLUMN_IN_BLOCK_SIZE_BYTES =
             "preferred_max_column_in_block_size_bytes";
     public static final String DISABLE_STREAMING_PREAGGREGATIONS = 
"disable_streaming_preaggregations";
@@ -1285,32 +1284,35 @@ public class SessionVariable implements Serializable, 
Writable {
     @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;
+    public int batchSize = 65535;
 
     // 16352 + 16 + 16 = 16384
     @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.
+    // Target output block size in bytes for adaptive batch size.
+    // Default 8MB. Bounds: [1MB, 512MB]. Feature on/off is controlled by BE 
config
+    // enable_adaptive_batch_size. Passed to storage/operator layers to 
control how many
+    // rows each block 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."})
+            checker = "checkPreferredBlockSizeBytes",
+            description = {"目标输出 Block 字节数上限,自适应 batch size 功能使用,"
+                    + "范围 [1MB, 512MB],默认 8MB",
+                "Target output block size in bytes for adaptive batch size. "
+                    + "Range [1MB, 512MB]. 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;
-
-    // Per-column byte limit when computing adaptive chunk rows. 0 disables 
the per-column limit.
+    // Per-column byte limit when computing adaptive chunk rows. Default 1MB.
+    // Bounds: [256KB, 128MB]. Controls maximum byte size of a single column 
in a block
+    // to avoid cache misses from overly large columns.
     @VarAttrDef.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."})
+            checker = "checkPreferredMaxColumnInBlockSizeBytes",
+            description = {"自适应 batch size 时单列字节数上限,"
+                    + "防止单列过大导致 cache miss,范围 [256KB, 128MB],默认 1MB",
+                "Per-column byte limit for adaptive batch size to avoid cache 
misses. "
+                    + "Range [256KB, 128MB]. Default 1MB."})
     public long preferredMaxColumnInBlockSizeBytes = 1048576L; // 1MB
 
     @VarAttrDef.VarAttr(name = DISABLE_STREAMING_PREAGGREGATIONS, fuzzy = true)
@@ -5363,7 +5365,6 @@ public class SessionVariable implements Serializable, 
Writable {
 
         tResult.setBatchSize(batchSize);
         tResult.setPreferredBlockSizeBytes(preferredBlockSizeBytes);
-        tResult.setPreferredBlockSizeRows(preferredBlockSizeRows);
         
tResult.setPreferredMaxColumnInBlockSizeBytes(preferredMaxColumnInBlockSizeBytes);
         tResult.setDisableStreamPreaggregations(disableStreamPreaggregations);
         
tResult.setEnableDistinctStreamingAggregation(enableDistinctStreamingAggregation);
@@ -6038,6 +6039,30 @@ public class SessionVariable implements Serializable, 
Writable {
         }
     }
 
+    private static final long PREFERRED_BLOCK_SIZE_BYTES_MIN = 1048576L;      
// 1MB
+    private static final long PREFERRED_BLOCK_SIZE_BYTES_MAX = 536870912L;    
// 512MB
+
+    public void checkPreferredBlockSizeBytes(String value) {
+        long v = Long.parseLong(value);
+        if (v < PREFERRED_BLOCK_SIZE_BYTES_MIN || v > 
PREFERRED_BLOCK_SIZE_BYTES_MAX) {
+            throw new InvalidParameterException(
+                    "preferred_block_size_bytes should be between 1MB ("
+                    + PREFERRED_BLOCK_SIZE_BYTES_MIN + ") and 512MB ("
+                    + PREFERRED_BLOCK_SIZE_BYTES_MAX + "), got " + v);
+        }
+    }
+
+    public void checkPreferredMaxColumnInBlockSizeBytes(String value) {
+        long v = Long.parseLong(value);
+        long min = 262144L;    // 256KB
+        long max = 134217728L; // 128MB
+        if (v < min || v > max) {
+            throw new InvalidParameterException(
+                    "preferred_max_column_in_block_size_bytes should be 
between 256KB ("
+                    + min + ") and 128MB (" + max + "), got " + v);
+        }
+    }
+
     public void checkSkewRewriteAggBucketNum(String bucketNumStr) {
         try {
             long bucketNum = Long.parseLong(bucketNumStr);
diff --git a/gensrc/thrift/PaloInternalService.thrift 
b/gensrc/thrift/PaloInternalService.thrift
index c89072a2c5f..71dffc62b0c 100644
--- a/gensrc/thrift/PaloInternalService.thrift
+++ b/gensrc/thrift/PaloInternalService.thrift
@@ -481,10 +481,6 @@ struct TQueryOptions {
   // 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
-
   // For cloud, to control if the content would be written into file cache
   // In write path, to control if the content would be written into file cache.
   // In read path, read from file cache or remote storage when execute query.
diff --git 
a/regression-test/suites/query_p0/adaptive_batch_size/adaptive_batch_size.groovy
 
b/regression-test/suites/query_p0/adaptive_batch_size/adaptive_batch_size.groovy
index 8fa691a1b79..b4695321495 100644
--- 
a/regression-test/suites/query_p0/adaptive_batch_size/adaptive_batch_size.groovy
+++ 
b/regression-test/suites/query_p0/adaptive_batch_size/adaptive_batch_size.groovy
@@ -206,7 +206,6 @@ suite("adaptive_batch_size") {
 
     // Reset all modified session variables to defaults.
     sql "set preferred_block_size_bytes = 8388608"
-    sql "set preferred_block_size_rows = 65535"
     sql "set preferred_max_column_in_block_size_bytes = 1048576"
-    sql "set batch_size = 4096"
+    sql "set batch_size = 65535"
 }


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


Reply via email to