From 38d383096202e4e9c1aa6b51f6be6e2219894828 Mon Sep 17 00:00:00 2001 From: leslieyuchen Date: Thu, 2 Nov 2023 05:12:51 +0000 Subject: [PATCH] [CP] fix partition wise join and global index lookup -4016 --- .../engine/subquery/ob_subplan_filter_op.cpp | 45 ++++++++++++++----- src/sql/engine/table/ob_table_scan_op.cpp | 8 +++- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/sql/engine/subquery/ob_subplan_filter_op.cpp b/src/sql/engine/subquery/ob_subplan_filter_op.cpp index 843f50b87c..b2b92c29ec 100644 --- a/src/sql/engine/subquery/ob_subplan_filter_op.cpp +++ b/src/sql/engine/subquery/ob_subplan_filter_op.cpp @@ -136,20 +136,41 @@ int ObSubQueryIterator::rewind(const bool reset_onetime_plan /* = false */) } if (OB_SUCC(ret) && current_group_ < parent_spf_group) { if (new_group) { - //If in lookup op, we need to call get next row to init all of iter. - op_.get_next_row(); - } - int64_t old_jump_read_group_id; - old_jump_read_group_id = op_.get_exec_ctx().get_das_ctx().jump_read_group_id_; - op_.get_exec_ctx().get_das_ctx().jump_read_group_id_ = parent_spf_group; - if (OB_FAIL(op_.rescan())) { - if(OB_ITER_END == ret) { - ret = OB_ERR_UNEXPECTED; + /** + * Since the initialization of the lookup Iterator is done within index_lookup.get_next_row(), + * when SPF enters skip scan, + * we need to mark the jump_read_group_id for each scan Iterator + * and determine the number of rows to skip based on the current group_id. + * The issue with the lookup process here is that when SPF performs multiple skip scans, + * the lookup process may not be executed at all, + * resulting in uninitialized lookup Iterators. + * As a result, when subsequent skip reads occur, + * the lookup Iterator will not be set with the correct jum_read_group_id. + * Therefore, it is necessary to ensure that get_next_row() is called at least once to + * initialize the lookup Iterator on the right branch. + **/ + if (OB_FAIL(op_.get_next_row())) { + if (OB_ITER_END == ret) { + //ignore OB_ITER_END + ret = OB_SUCCESS; + } else { + LOG_WARN("get next row from child failed", K(ret)); + } } - LOG_WARN("Das jump read rescan fail.", K(ret)); } - op_.get_exec_ctx().get_das_ctx().jump_read_group_id_ = old_jump_read_group_id; - current_group_ = parent_spf_group; + if (OB_SUCC(ret)) { + int64_t old_jump_read_group_id; + old_jump_read_group_id = op_.get_exec_ctx().get_das_ctx().jump_read_group_id_; + op_.get_exec_ctx().get_das_ctx().jump_read_group_id_ = parent_spf_group; + if (OB_FAIL(op_.rescan())) { + if(OB_ITER_END == ret) { + ret = OB_ERR_UNEXPECTED; + } + LOG_WARN("Das jump read rescan fail.", K(ret)); + } + op_.get_exec_ctx().get_das_ctx().jump_read_group_id_ = old_jump_read_group_id; + current_group_ = parent_spf_group; + } } } } else { diff --git a/src/sql/engine/table/ob_table_scan_op.cpp b/src/sql/engine/table/ob_table_scan_op.cpp index 055cd103cf..ca5a3041a2 100644 --- a/src/sql/engine/table/ob_table_scan_op.cpp +++ b/src/sql/engine/table/ob_table_scan_op.cpp @@ -1652,6 +1652,9 @@ bool ObTableScanOp::need_real_rescan() bool bret = false; if (!MY_SPEC.batch_scan_flag_) { bret = true; + } else if (tsc_rtdef_.bnlj_params_.empty()) { + //batch rescan not init, need to do real rescan + bret = true; } else { ObPhysicalPlanCtx *plan_ctx = GET_PHY_PLAN_CTX(ctx_); int64_t param_idx = tsc_rtdef_.bnlj_params_.at(0).param_idx_; @@ -3059,7 +3062,10 @@ int ObGlobalIndexLookupOpImpl::close() int ObGlobalIndexLookupOpImpl::rescan() { int ret = OB_SUCCESS; - if (get_batch_rescan() && lookup_group_cnt_ < index_group_cnt_) { + if (OB_ISNULL(table_scan_op_)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("table scan op not init", K(ret)); + } else if (!table_scan_op_->need_real_rescan() && lookup_group_cnt_ < index_group_cnt_) { LOG_DEBUG("rescan in group lookup, only need to switch iterator", K(lookup_group_cnt_), K(index_group_cnt_)); if (OB_FAIL(table_scan_op_->build_bnlj_params())) {