diff --git a/src/sql/optimizer/ob_logical_operator.cpp b/src/sql/optimizer/ob_logical_operator.cpp index 29e13676f9..aa3eec17c4 100644 --- a/src/sql/optimizer/ob_logical_operator.cpp +++ b/src/sql/optimizer/ob_logical_operator.cpp @@ -1400,6 +1400,8 @@ int ObLogicalOperator::do_pre_traverse_operation(const TraverseOp &op, void *ctx LOG_WARN("get unexpected null", K(session), K(ret)); } else if (is_plan_root() && OB_FAIL(adjust_plan_root_output_exprs())) { LOG_WARN("failed to set plan root output", K(ret)); + } else if (is_plan_root() && OB_FAIL(collecte_inseparable_exprs(*alloc_expr_context))) { + LOG_WARN("failed to set plan root output", K(ret)); } else if (OB_FAIL(allocate_expr_pre(*alloc_expr_context))) { LOG_WARN("failed to do allocate expr pre", K(ret)); } else { @@ -1686,6 +1688,22 @@ int ObLogicalOperator::mark_expr_produced(ObRawExpr *expr, return ret; } +int ObLogicalOperator::collecte_inseparable_exprs(ObAllocExprContext &ctx) +{ + int ret = OB_SUCCESS; + const ObDMLStmt *stmt = NULL; + if (OB_ISNULL(stmt = get_stmt())) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("get unexpected null", K(stmt), K(ret)); + } else if (stmt->is_dblink_stmt() && stmt->is_select_stmt()) { + const ObSelectStmt *sel_stmt = static_cast(stmt); + if (OB_FAIL(sel_stmt->get_select_exprs(ctx.inseparable_exprs_))) { + LOG_WARN("failed to get select exprs", K(ret)); + } + } + return ret; +} + int ObLogicalOperator::allocate_expr_pre(ObAllocExprContext &ctx) { int ret = OB_SUCCESS; @@ -1880,8 +1898,6 @@ int ObLogicalOperator::add_expr_to_ctx(ObAllocExprContext &ctx, if (OB_ISNULL(expr)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("get unexpected null", K(ret)); - } else if (log_op_def::LOG_LINK_SCAN == get_type()) { - // do not extract shared exprs for link op } else if (OB_FAIL(extract_shared_exprs(expr, ctx, 0, @@ -2044,11 +2060,13 @@ int ObLogicalOperator::extract_shared_exprs(ObRawExpr *raw_expr, LOG_WARN("failed to add var to array", K(ret)); } - for (int64_t i = 0; OB_SUCC(ret) && i < raw_expr->get_param_count(); ++i) { - ret = SMART_CALL(extract_shared_exprs(raw_expr->get_param_expr(i), - ctx, - ref_cnt, - shard_exprs)); + if (!ObOptimizerUtil::find_item(ctx.inseparable_exprs_, raw_expr)) { + for (int64_t i = 0; OB_SUCC(ret) && i < raw_expr->get_param_count(); ++i) { + ret = SMART_CALL(extract_shared_exprs(raw_expr->get_param_expr(i), + ctx, + ref_cnt, + shard_exprs)); + } } return ret; } diff --git a/src/sql/optimizer/ob_logical_operator.h b/src/sql/optimizer/ob_logical_operator.h index 2025d22eda..ba964aad99 100644 --- a/src/sql/optimizer/ob_logical_operator.h +++ b/src/sql/optimizer/ob_logical_operator.h @@ -651,6 +651,8 @@ struct ObAllocExprContext // {key => flattern expr, value => reference count } hash::ObHashMap flattern_expr_map_; common::ObSEArray expr_producers_; + // Exprs that cannot be used to extract shared child exprs + common::ObSEArray inseparable_exprs_; }; struct ObPxPipeBlockingCtx @@ -1185,6 +1187,8 @@ public: return common::OB_SUCCESS; } + int collecte_inseparable_exprs(ObAllocExprContext &ctx); + virtual int allocate_expr_pre(ObAllocExprContext &ctx); virtual int get_op_exprs(ObIArray &all_exprs); diff --git a/src/sql/rewrite/ob_transform_dblink.cpp b/src/sql/rewrite/ob_transform_dblink.cpp index 8c824f37cf..064cb70df0 100644 --- a/src/sql/rewrite/ob_transform_dblink.cpp +++ b/src/sql/rewrite/ob_transform_dblink.cpp @@ -453,19 +453,6 @@ int ObTransformDBlink::pack_link_table(ObDMLStmt *stmt, bool &trans_happened) LOG_TRACE("succeed to pack one link stmt", K(helpers.at(i))); } } - } else if (stmt->is_set_stmt()) { - ObSelectStmt *sel_stmt = static_cast(stmt); - for (int64_t i = 0; OB_SUCC(ret) && i < sel_stmt->get_set_query().count(); ++i) { - ObSelectStmt *child_stmt = sel_stmt->get_set_query(i); - if (OB_ISNULL(child_stmt)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected null", K(ret)); - } else if (!child_stmt->is_dblink_stmt()) { - // do nothing - } else if (OB_FAIL(ObTransformUtils::pack_stmt(ctx_, static_cast(child_stmt)))) { - LOG_WARN("failed to pack link stmt", K(ret)); - } - } } return ret; }