From 0c1f5ac25e4ec7f13b091ba6ecd2a81e5bcc813e Mon Sep 17 00:00:00 2001 From: obdev Date: Wed, 3 Jan 2024 17:23:03 +0000 Subject: [PATCH] fix hash join core when nest loop mode build hash table --- src/sql/engine/join/hash_join/ob_hash_join_struct.h | 10 ++++++---- src/sql/engine/join/hash_join/ob_hash_join_vec_op.cpp | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/sql/engine/join/hash_join/ob_hash_join_struct.h b/src/sql/engine/join/hash_join/ob_hash_join_struct.h index 4da7b76cae..e25514807b 100644 --- a/src/sql/engine/join/hash_join/ob_hash_join_struct.h +++ b/src/sql/engine/join/hash_join/ob_hash_join_struct.h @@ -314,10 +314,11 @@ public: const ObHJStoredRow **stored_row) { int ret = OB_SUCCESS; if (mem_bound_ < INT64_MAX - && (cur_mem_ > mem_bound_ || cur_row_cnt_ > row_bound_)) { + && (cur_mem_ > mem_bound_ || cur_row_cnt_ >= row_bound_)) { ret = OB_ITER_END; } else { - ret = part_->get_next_batch(exprs, ctx, max_rows, read_rows, stored_row); + int64_t max_read_rows = min(max_rows, row_bound_ - cur_row_cnt_); + ret = part_->get_next_batch(exprs, ctx, max_read_rows, read_rows, stored_row); } if (OB_SUCC(ret)) { cur_row_cnt_ += read_rows; @@ -333,10 +334,11 @@ public: int64_t &read_rows) { int ret = OB_SUCCESS; if (mem_bound_ < INT64_MAX - && (cur_mem_ > mem_bound_ || cur_row_cnt_ > row_bound_)) { + && (cur_mem_ > mem_bound_ || cur_row_cnt_ >= row_bound_)) { ret = OB_ITER_END; } else { - ret = part_->get_next_batch(stored_row, max_rows, read_rows); + int64_t max_read_rows = min(max_rows, row_bound_ - cur_row_cnt_); + ret = part_->get_next_batch(stored_row, max_read_rows, read_rows); } if (OB_SUCC(ret)) { cur_row_cnt_ += read_rows; diff --git a/src/sql/engine/join/hash_join/ob_hash_join_vec_op.cpp b/src/sql/engine/join/hash_join/ob_hash_join_vec_op.cpp index cf92f685f5..fc75b05ace 100644 --- a/src/sql/engine/join/hash_join/ob_hash_join_vec_op.cpp +++ b/src/sql/engine/join/hash_join/ob_hash_join_vec_op.cpp @@ -828,7 +828,7 @@ int ObHashJoinVecOp::build_hash_table_for_nest_loop(int64_t &num_left_rows) // at least hold 1 block in memory int64_t memory_bound = std::max(remain_data_memory_size_, hj_part->get_row_store().get_max_blk_size()); - const int64_t row_bound = hash_table.get_nbuckets() / 2; + const int64_t row_bound = min(hash_table.get_row_count(), hash_table.get_nbuckets() / 2); ObTempRowStore::IterationAge iter_age; hj_part->set_iteration_age(iter_age); JoinPartitionRowIter left_iter(hj_part, row_bound, memory_bound);