dblink_write implement [FEAT MERGE]
Co-authored-by: zzg19950727 <1071026277@qq.com> Co-authored-by: xianyu-w <707512433@qq.com>
This commit is contained in:
@ -12,8 +12,7 @@
|
||||
|
||||
#define USING_LOG_PREFIX SQL_OPT
|
||||
#include "sql/optimizer/ob_log_link.h"
|
||||
#include "sql/optimizer/ob_log_plan.h"
|
||||
//#include "sql/ob_sql_utils.h"
|
||||
#include "sql/ob_sql_utils.h"
|
||||
|
||||
using namespace oceanbase::sql;
|
||||
using namespace oceanbase::common;
|
||||
@ -29,21 +28,32 @@ ObLogLink::ObLogLink(ObLogPlan &plan)
|
||||
allocator_(plan.get_allocator()),
|
||||
stmt_fmt_buf_(NULL),
|
||||
stmt_fmt_len_(0),
|
||||
is_reverse_link_(false),
|
||||
tm_dblink_id_(OB_INVALID_ID),
|
||||
param_infos_()
|
||||
{}
|
||||
|
||||
int ObLogLink::compute_sharding_info()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObOptimizerContext *opt_ctx = NULL;
|
||||
if (OB_ISNULL(get_plan()) ||
|
||||
OB_ISNULL(opt_ctx = &get_plan()->get_optimizer_context())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(ret));
|
||||
} else {
|
||||
strong_sharding_ = opt_ctx->get_local_sharding();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObLogLink::est_cost()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObLogicalOperator *child = NULL;
|
||||
if (OB_ISNULL(child = get_child(ObLogicalOperator::first_child))) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(child), K(ret));
|
||||
} else {
|
||||
card_ = child->get_card();
|
||||
op_cost_ = 0;
|
||||
cost_ = op_cost_ + child->get_cost();
|
||||
}
|
||||
card_ = 0;
|
||||
op_cost_ = 0;
|
||||
cost_ = 0;
|
||||
width_ = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -104,24 +114,6 @@ int ObLogLink::get_plan_item_info(PlanText &plan_text,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObLogLink::generate_link_sql_post(GenLinkStmtPostContext &link_ctx)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(link_ctx.spell_link(static_cast<const ObSelectStmt *>(get_stmt()),
|
||||
&stmt_fmt_buf_,
|
||||
stmt_fmt_len_,
|
||||
get_op_ordering(),
|
||||
output_exprs_,
|
||||
startup_exprs_,
|
||||
filter_exprs_))) {
|
||||
LOG_WARN("dblink fail to reverse spell link", K(dblink_id_), K(ret));
|
||||
} else {
|
||||
LOG_WARN("dblink stmt", K(ObString(stmt_fmt_len_, stmt_fmt_buf_)));
|
||||
link_ctx.reset();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// see comment in ObConstRawExpr::get_name_internal().
|
||||
int ObLogLink::gen_link_stmt_param_infos()
|
||||
{
|
||||
@ -150,5 +142,70 @@ int ObLogLink::gen_link_stmt_param_infos()
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObLogLink::mark_exec_params(ObDMLStmt *stmt)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_ISNULL(stmt)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected null", K(ret));
|
||||
} else {
|
||||
common::ObIArray<ObQueryRefRawExpr*> &subquery_exprs = stmt->get_subquery_exprs();
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < subquery_exprs.count(); i ++) {
|
||||
ObQueryRefRawExpr *expr = subquery_exprs.at(i);
|
||||
if (OB_ISNULL(expr)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected null", K(ret));
|
||||
} else {
|
||||
for (int64_t j = 0; OB_SUCC(ret) && j < expr->get_exec_params().count(); j ++) {
|
||||
ObExecParamRawExpr *param_expr = NULL;
|
||||
if (OB_ISNULL(param_expr = expr->get_exec_params().at(j))) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected null", K(ret));
|
||||
} else {
|
||||
param_expr->set_ref_same_dblink(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
ObSEArray<ObSelectStmt *, 4> child_stmts;
|
||||
if (OB_FAIL(stmt->get_child_stmts(child_stmts))) {
|
||||
LOG_WARN("failed to get child stmts", K(ret));
|
||||
}
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < child_stmts.count(); i ++) {
|
||||
OZ(SMART_CALL(mark_exec_params(child_stmts.at(i))));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObLogLink::set_link_stmt(const ObDMLStmt* stmt)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const ObLogPlan *plan = get_plan();
|
||||
if (NULL == stmt) {
|
||||
stmt = get_stmt();
|
||||
}
|
||||
ObString sql;
|
||||
ObObjPrintParams print_param;
|
||||
print_param.for_dblink_ = 1;
|
||||
ObOptimizerContext *opt_ctx = NULL;
|
||||
if (OB_ISNULL(stmt) || OB_ISNULL(plan) ||
|
||||
OB_ISNULL(opt_ctx = &get_plan()->get_optimizer_context())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", KP(opt_ctx), KP(stmt), KP(plan), K(ret));
|
||||
} else if (OB_FAIL(mark_exec_params(const_cast<ObDMLStmt*>(stmt)))) {
|
||||
LOG_WARN("failed to mark exec params", K(ret));
|
||||
} else if (OB_FAIL(ObSQLUtils::reconstruct_sql(plan->get_allocator(), stmt, sql, opt_ctx->get_schema_guard(), print_param))) {
|
||||
LOG_WARN("failed to reconstruct link sql", KP(stmt), KP(plan), K(get_dblink_id()), K(ret));
|
||||
} else {
|
||||
stmt_fmt_buf_ = sql.ptr();
|
||||
stmt_fmt_len_ = sql.length();
|
||||
LOG_DEBUG("loglink succ to reconstruct link sql", K(sql));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace sql
|
||||
} // namespace oceanbase
|
||||
|
||||
Reference in New Issue
Block a user