From 7a8ac82dee0e4b1ed94eaa75d163f38f56361fb4 Mon Sep 17 00:00:00 2001 From: obdev Date: Wed, 10 Jan 2024 10:44:00 +0000 Subject: [PATCH] [CP] [CP] [CP] fix: fix the 4377 error induced by NLJ batch Rescan --- src/sql/optimizer/ob_log_join.cpp | 3 +++ src/sql/optimizer/ob_log_subplan_filter.cpp | 4 ++++ src/sql/optimizer/ob_optimizer_util.cpp | 26 +++++++++++++++++++++ src/sql/optimizer/ob_optimizer_util.h | 2 ++ 4 files changed, 35 insertions(+) diff --git a/src/sql/optimizer/ob_log_join.cpp b/src/sql/optimizer/ob_log_join.cpp index 1ec7d2beca..1d98f7840f 100644 --- a/src/sql/optimizer/ob_log_join.cpp +++ b/src/sql/optimizer/ob_log_join.cpp @@ -1361,6 +1361,8 @@ int ObLogJoin::check_and_set_use_batch() can_use_batch_nlj_ = false; } else if (OB_FAIL(check_if_disable_batch(get_child(1), can_use_batch_nlj_))) { LOG_WARN("failed to check if disable batch", K(ret)); + } else if (can_use_batch_nlj_ && OB_FAIL(ObOptimizerUtil::check_ancestor_node_support_skip_scan(this, can_use_batch_nlj_))) { + LOG_WARN("failed to check whether ancestor node support skip read", K(ret)); } } // set use batch @@ -1372,6 +1374,7 @@ int ObLogJoin::check_and_set_use_batch() return ret; } + int ObLogJoin::check_if_disable_batch(ObLogicalOperator* root, bool &can_use_batch_nlj) { int ret = OB_SUCCESS; diff --git a/src/sql/optimizer/ob_log_subplan_filter.cpp b/src/sql/optimizer/ob_log_subplan_filter.cpp index 5d93d1d1ec..937efdf90e 100644 --- a/src/sql/optimizer/ob_log_subplan_filter.cpp +++ b/src/sql/optimizer/ob_log_subplan_filter.cpp @@ -562,6 +562,10 @@ int ObLogSubPlanFilter::check_and_set_das_group_rescan() } } } + if (OB_SUCC(ret) && enable_das_group_rescan_ && + OB_FAIL(ObOptimizerUtil::check_ancestor_node_support_skip_scan(this, enable_das_group_rescan_))) { + LOG_WARN("failed to check whether ancestor node support skip read", K(ret)); + } // check if exec params contain sub_query for (int64_t i = 0; OB_SUCC(ret) && enable_das_group_rescan_ && i < exec_params_.count(); i++) { const ObExecParamRawExpr *exec_param = exec_params_.at(i); diff --git a/src/sql/optimizer/ob_optimizer_util.cpp b/src/sql/optimizer/ob_optimizer_util.cpp index 4e7fa48d9e..63632c1ba0 100644 --- a/src/sql/optimizer/ob_optimizer_util.cpp +++ b/src/sql/optimizer/ob_optimizer_util.cpp @@ -27,6 +27,7 @@ #include "share/location_cache/ob_location_service.h" #include "share/ob_order_perserving_encoder.h" #include "sql/rewrite/ob_predicate_deduce.h" +#include "sql/optimizer/ob_log_join.h" using namespace oceanbase; using namespace sql; @@ -9488,4 +9489,29 @@ bool ObOptimizerUtil::find_superset(const ObRelIds &rel_ids, bret = (single_table_ids.at(i).is_superset(rel_ids)); } return bret; +} + +int ObOptimizerUtil::check_ancestor_node_support_skip_scan(ObLogicalOperator* op, bool &can_use_batch_nlj) +{ + int ret = OB_SUCCESS; + ObLogicalOperator* parent = nullptr; + if (OB_ISNULL(op)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("Current operator node is null", K(ret)); + } else if (OB_ISNULL(parent = op->get_parent())) { + // do nothing + } else if (can_use_batch_nlj) { + if (parent->get_type() == log_op_def::LOG_SUBPLAN_FILTER) { + can_use_batch_nlj = false; + } else if (parent->get_type() == log_op_def::LOG_JOIN) { + ObLogJoin *join = static_cast(parent); + if (IS_SEMI_ANTI_JOIN(join->get_join_type())) { + can_use_batch_nlj = false; + } + } + if (can_use_batch_nlj && OB_FAIL(SMART_CALL(check_ancestor_node_support_skip_scan(parent, can_use_batch_nlj)))) { + LOG_WARN("failed to check parent node can use batch NLJ", K(ret)); + } + } + return ret; } \ No newline at end of file diff --git a/src/sql/optimizer/ob_optimizer_util.h b/src/sql/optimizer/ob_optimizer_util.h index 5c11407557..a97c24933e 100644 --- a/src/sql/optimizer/ob_optimizer_util.h +++ b/src/sql/optimizer/ob_optimizer_util.h @@ -1534,6 +1534,8 @@ public: ObSqlTempTableInfo &temp_table_info, ObRawExpr *&temp_table_filter, ObSelectStmt *temp_table_query = NULL); + + static int check_ancestor_node_support_skip_scan(ObLogicalOperator* op, bool &can_use_batch_nlj); private: //disallow construct ObOptimizerUtil();