feat: add the rule to use-das when has variable assignments in sql
Co-authored-by: leslieyuchen <leslieyuchen@gmail.com>
This commit is contained in:
parent
a46ee110fb
commit
bacc417957
File diff suppressed because one or more lines are too long
@ -1168,6 +1168,8 @@ DEFINE_ORACLE_ERROR(OB_ERR_UNSUPPORTED_FK_SET_NULL_ON_GENERATED_COLUMN, -5513, E
|
||||
DEFINE_ORACLE_ERROR(OB_JSON_PROCESSING_ERROR, -5514, -1, "42000", " JSON processing error", 40444, " JSON processing error");
|
||||
DEFINE_ERROR(OB_ERR_TABLE_WITHOUT_ALIAS, -5515, ER_TF_MUST_HAVE_ALIAS, "42000", "Every table function must have an alias");
|
||||
|
||||
DEFINE_ERROR_EXT(OB_ERR_DEPRECATED_SYNTAX, -5516, ER_WARN_DEPRECATED_SYNTAX, "HY000", "This syntax is deprecated and will be removed in a future release", "%s is deprecated and will be removed in a future release. Please use \'%s\' instead");
|
||||
|
||||
DEFINE_ERROR_EXT(OB_ERR_SP_ALREADY_EXISTS, -5541, ER_SP_ALREADY_EXISTS, "42000", "procedure/function already exists", "%s %.*s already exists");
|
||||
DEFINE_ERROR_EXT(OB_ERR_SP_DOES_NOT_EXIST, -5542, ER_SP_DOES_NOT_EXIST, "42000", "procedure/function does not exist", "%s %.*s.%.*s does not exist");
|
||||
DEFINE_PLS_ERROR_EXT(OB_ERR_SP_UNDECLARED_VAR, -5543, ER_SP_UNDECLARED_VAR, "42000", "Undeclared variable", "Undeclared variable: %.*s", 201, "identifier must be declared", "identifier '%.*s' must be declared");
|
||||
|
@ -266,7 +266,6 @@ constexpr int OB_ENCODING_EST_SIZE_OVERFLOW = -4397;
|
||||
constexpr int OB_INVALID_SUB_PARTITION_TYPE = -4398;
|
||||
constexpr int OB_ERR_UNEXPECTED_UNIT_STATUS = -4399;
|
||||
constexpr int OB_AUTOINC_CACHE_NOT_EQUAL = -4400;
|
||||
constexpr int OB_TENANT_SNAPSHOT_NOT_EXIST = -4401;
|
||||
constexpr int OB_IMPORT_NOT_IN_SERVER = -4505;
|
||||
constexpr int OB_CONVERT_ERROR = -4507;
|
||||
constexpr int OB_BYPASS_TIMEOUT = -4510;
|
||||
@ -872,6 +871,7 @@ constexpr int OB_ERR_FK_COLUMN_NOT_NULL = -5512;
|
||||
constexpr int OB_ERR_UNSUPPORTED_FK_SET_NULL_ON_GENERATED_COLUMN = -5513;
|
||||
constexpr int OB_JSON_PROCESSING_ERROR = -5514;
|
||||
constexpr int OB_ERR_TABLE_WITHOUT_ALIAS = -5515;
|
||||
constexpr int OB_ERR_DEPRECATED_SYNTAX = -5516;
|
||||
constexpr int OB_ERR_SP_ALREADY_EXISTS = -5541;
|
||||
constexpr int OB_ERR_SP_DOES_NOT_EXIST = -5542;
|
||||
constexpr int OB_ERR_SP_UNDECLARED_VAR = -5543;
|
||||
@ -2837,6 +2837,7 @@ constexpr int OB_ERR_INVALID_DATE_MSG_FMT_V2 = -4219;
|
||||
#define OB_ERR_UNSUPPORTED_FK_SET_NULL_ON_GENERATED_COLUMN__USER_ERROR_MSG " Cannot define foreign key with ON DELETE SET NULL clause on a generated column"
|
||||
#define OB_JSON_PROCESSING_ERROR__USER_ERROR_MSG " JSON processing error"
|
||||
#define OB_ERR_TABLE_WITHOUT_ALIAS__USER_ERROR_MSG "Every table function must have an alias"
|
||||
#define OB_ERR_DEPRECATED_SYNTAX__USER_ERROR_MSG "%s is deprecated and will be removed in a future release. Please use \'%s\' instead"
|
||||
#define OB_ERR_SP_ALREADY_EXISTS__USER_ERROR_MSG "%s %.*s already exists"
|
||||
#define OB_ERR_SP_DOES_NOT_EXIST__USER_ERROR_MSG "%s %.*s.%.*s does not exist"
|
||||
#define OB_ERR_SP_UNDECLARED_VAR__USER_ERROR_MSG "Undeclared variable: %.*s"
|
||||
@ -4971,6 +4972,7 @@ constexpr int OB_ERR_INVALID_DATE_MSG_FMT_V2 = -4219;
|
||||
#define OB_ERR_UNSUPPORTED_FK_SET_NULL_ON_GENERATED_COLUMN__ORA_USER_ERROR_MSG "ORA-54036: cannot define referential constraint with ON DELETE SET NULL clause on virtual column"
|
||||
#define OB_JSON_PROCESSING_ERROR__ORA_USER_ERROR_MSG "ORA-40444: JSON processing error"
|
||||
#define OB_ERR_TABLE_WITHOUT_ALIAS__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -5515, Every table function must have an alias"
|
||||
#define OB_ERR_DEPRECATED_SYNTAX__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -5516, %s is deprecated and will be removed in a future release. Please use \'%s\' instead"
|
||||
#define OB_ERR_SP_ALREADY_EXISTS__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -5541, %s %.*s already exists"
|
||||
#define OB_ERR_SP_DOES_NOT_EXIST__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -5542, %s %.*s.%.*s does not exist"
|
||||
#define OB_ERR_SP_UNDECLARED_VAR__ORA_USER_ERROR_MSG "PLS-00201: identifier '%.*s' must be declared"
|
||||
@ -6063,7 +6065,7 @@ constexpr int OB_ERR_INVALID_DATE_MSG_FMT_V2 = -4219;
|
||||
#define OB_ERR_DATA_TOO_LONG_MSG_FMT_V2__ORA_USER_ERROR_MSG "ORA-12899: value too large for column %.*s (actual: %ld, maximum: %ld)"
|
||||
#define OB_ERR_INVALID_DATE_MSG_FMT_V2__ORA_USER_ERROR_MSG "ORA-01861: Incorrect datetime value for column '%.*s' at row %ld"
|
||||
|
||||
extern int g_all_ob_errnos[2130];
|
||||
extern int g_all_ob_errnos[2131];
|
||||
|
||||
const char *ob_error_name(const int oberr);
|
||||
const char* ob_error_cause(const int oberr);
|
||||
|
@ -1376,6 +1376,11 @@ DEF_BOOL(_enable_new_sql_nio, OB_CLUSTER_PARAMETER, "true",
|
||||
"specifies whether SQL serial network is turned on. Turned on to support mysql_send_long_data"
|
||||
"The default value is FALSE. Value: TRUE: turned on FALSE: turned off",
|
||||
ObParameterAttr(Section::OBSERVER, Source::DEFAULT, EditLevel::STATIC_EFFECTIVE));
|
||||
|
||||
// Add a config to enable use das if the sql statement has variable assignment
|
||||
DEF_BOOL(_enable_var_assign_use_das, OB_TENANT_PARAMETER, "True",
|
||||
"enable use das if the sql statement has variable assignment",
|
||||
ObParameterAttr(Section::OBSERVER, Source::DEFAULT, EditLevel::DYNAMIC_EFFECTIVE));
|
||||
// query response time
|
||||
DEF_BOOL(query_response_time_stats, OB_TENANT_PARAMETER, "False",
|
||||
"Enable or disable QUERY_RESPONSE_TIME statistics collecting"
|
||||
|
@ -6946,6 +6946,13 @@ int ObStaticEngineCG::set_other_properties(const ObLogPlan &log_plan, ObPhysical
|
||||
ret = phy_plan.set_vars(log_plan.get_stmt()->get_query_ctx()->variables_);
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret) && !log_plan.get_stmt()->is_explain_stmt()) {
|
||||
if (OB_FAIL(generate_rt_exprs(log_plan.get_stmt()->get_query_ctx()->var_init_exprs_,
|
||||
phy_plan.var_init_exprs_))) {
|
||||
LOG_WARN("generate var init exprs failed", KR(ret));
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
//convert insert row param index map
|
||||
stmt::StmtType stmt_type = stmt::T_NONE;
|
||||
|
@ -99,6 +99,7 @@ ObPhysicalPlan::ObPhysicalPlan(MemoryContext &mem_context /* = CURRENT_CONTEXT *
|
||||
need_drive_dml_query_(false),
|
||||
tx_id_(-1),
|
||||
tm_sessid_(-1),
|
||||
var_init_exprs_(allocator_),
|
||||
is_returning_(false),
|
||||
is_late_materialized_(false),
|
||||
is_dep_base_table_(false),
|
||||
@ -222,6 +223,7 @@ void ObPhysicalPlan::reset()
|
||||
stat_.minimal_worker_map_.destroy();
|
||||
tx_id_ = -1;
|
||||
tm_sessid_ = -1;
|
||||
var_init_exprs_.reset();
|
||||
need_record_plan_info_ = false;
|
||||
logical_plan_.reset();
|
||||
is_enable_px_fast_reclaim_ = false;
|
||||
|
@ -596,7 +596,6 @@ private:
|
||||
// constraint for duplicate table to choose replica
|
||||
// dist plan will use this as (dup_tab_pos, advisor_tab_pos) pos is position in base constraint
|
||||
DupTabReplicaArray dup_table_replica_cons_;
|
||||
|
||||
public:
|
||||
ObExprFrameInfo expr_frame_info_;
|
||||
|
||||
@ -608,6 +607,7 @@ public:
|
||||
bool need_drive_dml_query_;
|
||||
int64_t tx_id_; //for dblink recover xa tx
|
||||
int64_t tm_sessid_; //for dblink get connection attached on tm session
|
||||
ExprFixedArray var_init_exprs_;
|
||||
private:
|
||||
bool is_returning_; //是否设置了returning
|
||||
|
||||
|
@ -103,6 +103,17 @@ int ObExecuteResult::open() const
|
||||
if (OB_TRY_LOCK_ROW_CONFLICT != ret && OB_TRANSACTION_SET_VIOLATION != ret) {
|
||||
LOG_WARN("open operator failed", K(ret));
|
||||
}
|
||||
} else if (!static_engine_root_->get_spec().plan_->var_init_exprs_.empty()) {
|
||||
// Evaluate the var init expr in generated table, This is to be compatible with some of mysql's uses of variables
|
||||
// Such as "select c1,(@rownum:= @rownum+1) as CCBH from t1,(SELECT@rownum:=0) B"
|
||||
const ExprFixedArray &var_init_exprs = static_engine_root_->get_spec().plan_->var_init_exprs_;
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < var_init_exprs.count(); i++) {
|
||||
ObDatum *datum = NULL;
|
||||
ObExpr *expr = var_init_exprs.at(i);
|
||||
if (OB_FAIL(expr->eval(static_engine_root_->get_eval_ctx(), datum))) {
|
||||
LOG_WARN("expr evaluate failed", K(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -795,6 +795,7 @@ int ObOptimizerTraceImpl::trace_parameters()
|
||||
TRACE_PARAMETER(_hash_join_enabled, bool);
|
||||
TRACE_PARAMETER(_optimizer_sortmerge_join_enabled, bool);
|
||||
TRACE_PARAMETER(_nested_loop_join_enabled, bool);
|
||||
TRACE_PARAMETER(_enable_var_assign_use_das, bool);
|
||||
//for system variables
|
||||
TRACE_SYS_VAR(_PX_SHARED_HASH_JOIN, int64_t);
|
||||
TRACE_SYS_VAR(_ENABLE_PARALLEL_DML, int64_t);
|
||||
|
@ -778,6 +778,7 @@ public:
|
||||
common::ObSArray<ObPCConstParamInfo, common::ModulePageAllocator, true> all_plan_const_param_constraints_;
|
||||
common::ObSArray<ObPCConstParamInfo, common::ModulePageAllocator, true> all_possible_const_param_constraints_;
|
||||
common::ObSArray<ObPCParamEqualInfo, common::ModulePageAllocator, true> all_equal_param_constraints_;
|
||||
common::ObSEArray<ObRawExpr*, 4, common::ModulePageAllocator, true> var_init_exprs_;
|
||||
common::ObDList<ObPreCalcExprConstraint> all_pre_calc_constraints_;
|
||||
common::ObSArray<ObExprConstraint, common::ModulePageAllocator, true> all_expr_constraints_;
|
||||
common::ObSArray<ObPCPrivInfo, common::ModulePageAllocator, true> all_priv_constraints_;
|
||||
|
@ -1509,6 +1509,16 @@ int ObJoinOrder::will_use_das(const uint64_t table_id,
|
||||
}
|
||||
}
|
||||
|
||||
bool enable_var_assign_use_das = true;
|
||||
if (OB_SUCC(ret)) {
|
||||
ObSQLSessionInfo *session_info = NULL;
|
||||
if (OB_NOT_NULL(session_info = get_plan()->get_optimizer_context().get_session_info())) {
|
||||
enable_var_assign_use_das = session_info->is_var_assign_use_das_enabled();
|
||||
} else {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("session info is null", K(ret));
|
||||
}
|
||||
}
|
||||
if(OB_SUCC(ret)) {
|
||||
bool hint_force_das = false;
|
||||
bool hint_force_no_das = false;
|
||||
@ -1518,7 +1528,7 @@ int ObJoinOrder::will_use_das(const uint64_t table_id,
|
||||
get_plan()->get_optimizer_context().has_dblink() ||
|
||||
get_plan()->get_optimizer_context().has_subquery_in_function_table() ||
|
||||
get_plan()->get_optimizer_context().has_cursor_expression() ||
|
||||
get_plan()->get_optimizer_context().has_var_assign() ||
|
||||
(get_plan()->get_optimizer_context().has_var_assign() && enable_var_assign_use_das) ||
|
||||
is_batch_update_table;
|
||||
if (EXTERNAL_TABLE == table_item->table_type_) {
|
||||
create_das_path = false;
|
||||
|
@ -537,7 +537,7 @@ int ObLogTableScan::extract_pushdown_filters(ObIArray<ObRawExpr*> &nonpushdown_f
|
||||
if (OB_FAIL(nonpushdown_filters.push_back(filters.at(i)))) {
|
||||
LOG_WARN("push UDF filter store non-pushdown filter failed", K(ret), K(i));
|
||||
}
|
||||
} else if (filters.at(i)->has_flag(CNT_ASSIGN_EXPR)) {
|
||||
} else if (filters.at(i)->has_flag(CNT_DYNAMIC_USER_VARIABLE)) {
|
||||
if (OB_FAIL(nonpushdown_filters.push_back(filters.at(i)))) {
|
||||
LOG_WARN("push variable assign filter store non-pushdown filter failed", K(ret), K(i));
|
||||
}
|
||||
|
@ -407,6 +407,7 @@ int ObConfigInfoInPC::load_influence_plan_config()
|
||||
px_join_skew_handling_ = tenant_config->_px_join_skew_handling;
|
||||
px_join_skew_minfreq_ = static_cast<int8_t>(tenant_config->_px_join_skew_minfreq);
|
||||
min_cluster_version_ = GET_MIN_CLUSTER_VERSION();
|
||||
enable_var_assign_use_das_ = tenant_config->_enable_var_assign_use_das;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -453,6 +454,9 @@ int ObConfigInfoInPC::serialize_configs(char *buf, int buf_len, int64_t &pos)
|
||||
} else if (OB_FAIL(databuff_printf(buf, buf_len, pos,
|
||||
"%d", is_enable_px_fast_reclaim_))) {
|
||||
SQL_PC_LOG(WARN, "failed to databuff_printf", K(ret), K(is_enable_px_fast_reclaim_));
|
||||
} else if (OB_FAIL(databuff_printf(buf, buf_len, pos,
|
||||
"%d", enable_var_assign_use_das_))) {
|
||||
SQL_PC_LOG(WARN, "failed to databuff_printf", K(ret), K(enable_var_assign_use_das_));
|
||||
} else {
|
||||
// do nothing
|
||||
}
|
||||
|
@ -1004,6 +1004,7 @@ public:
|
||||
px_join_skew_minfreq_(30),
|
||||
min_cluster_version_(0),
|
||||
is_enable_px_fast_reclaim_(false),
|
||||
enable_var_assign_use_das_(true),
|
||||
cluster_config_version_(-1),
|
||||
tenant_config_version_(-1),
|
||||
tenant_id_(0)
|
||||
@ -1045,6 +1046,7 @@ public:
|
||||
int8_t px_join_skew_minfreq_;
|
||||
uint64_t min_cluster_version_;
|
||||
bool is_enable_px_fast_reclaim_;
|
||||
bool enable_var_assign_use_das_;
|
||||
|
||||
private:
|
||||
// current cluster config version_
|
||||
|
@ -4476,6 +4476,16 @@ int ObDMLResolver::do_resolve_generate_table(const ParseNode &table_node,
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected error", K(alias_node->type_), K(ret));
|
||||
}
|
||||
|
||||
bool enable_var_assign_use_das = true;
|
||||
if (OB_SUCC(ret)) {
|
||||
if (OB_NOT_NULL(session_info_)) {
|
||||
enable_var_assign_use_das = session_info_->is_var_assign_use_das_enabled();
|
||||
} else {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("session info is null", K(ret));
|
||||
}
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (column_alias_node != NULL &&
|
||||
OB_FAIL(refine_generate_table_column_name(*column_alias_node, *ref_stmt))) {
|
||||
@ -4485,6 +4495,10 @@ int ObDMLResolver::do_resolve_generate_table(const ParseNode &table_node,
|
||||
LOG_WARN("check duplicated column failed", K(ret));
|
||||
} else if (OB_FAIL(resolve_generate_table_item(ref_stmt, alias_name, table_item))) {
|
||||
LOG_WARN("resolve generate table item failed", K(ret));
|
||||
} else if (enable_var_assign_use_das && OB_FAIL(extract_var_init_exprs(ref_stmt, params_.query_ctx_->var_init_exprs_))) {
|
||||
// Extract the var assign expr in generated table, This is to be compatible with some of mysql's uses of variables
|
||||
// Such as "select c1,(@rownum:= @rownum+1) as CCBH from t1,(SELECT@rownum:=0) B"
|
||||
LOG_WARN("extract var init exprs failed", K(ret));
|
||||
} else {
|
||||
LOG_DEBUG("finish do_resolve_generate_table", K(alias_name), KPC(table_item),
|
||||
KPC(table_item->ref_query_));
|
||||
@ -4492,6 +4506,25 @@ int ObDMLResolver::do_resolve_generate_table(const ParseNode &table_node,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLResolver::extract_var_init_exprs(ObSelectStmt *ref_query, ObIArray<ObRawExpr*> &assign_exprs)
|
||||
{
|
||||
// Extract the var assign expr in generated table, This is to be compatible with some of mysql's uses of variables
|
||||
// Such as "select c1,(@rownum:= @rownum+1) as CCBH from t1,(SELECT@rownum:=0) B"
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_ISNULL(ref_query)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("ref query is nullptr", KR(ret));
|
||||
} else if (ref_query->get_from_item_size() <= 0) {
|
||||
for (int i = 0; OB_SUCC(ret) && i < ref_query->get_select_item_size(); ++i) {
|
||||
const SelectItem &select_item = ref_query->get_select_item(i);
|
||||
if (OB_FAIL(ObRawExprUtils::extract_var_assign_exprs(select_item.expr_, assign_exprs))) {
|
||||
LOG_WARN("extract var assign exprs failed", K(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLResolver::resolve_generate_table_item(ObSelectStmt *ref_query,
|
||||
const ObString &alias_name,
|
||||
TableItem *&tbl_item)
|
||||
@ -6510,11 +6543,18 @@ int ObDMLResolver::resolve_order_item(const ParseNode &sort_node, OrderItem &ord
|
||||
SQL_RESV_LOG(WARN, "index order item not support in update");
|
||||
} else if (OB_FAIL(resolve_sql_expr(*(sort_node.children_[0]), expr))) {
|
||||
SQL_RESV_LOG(WARN, "resolve sql expression failed", K(ret));
|
||||
} else if (expr->has_flag(CNT_ASSIGN_EXPR)) {
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
LOG_WARN("Not supported variable assignment in order by item", K(ret));
|
||||
LOG_USER_ERROR(OB_NOT_SUPPORTED, "Variable assignment in order by item");
|
||||
} else {
|
||||
// check if order by item has var assign expr, which will cause uncertain behavior
|
||||
if (OB_NOT_NULL(expr) && expr->has_flag(CNT_ASSIGN_EXPR)) {
|
||||
LOG_USER_WARN(OB_ERR_DEPRECATED_SYNTAX, "Setting user variables within expressions",
|
||||
"SET variable=expression, ... or SELECT expression(s) INTO variables(s)");
|
||||
if (OB_NOT_NULL(session_info_) && OB_NOT_NULL(session_info_->get_cur_exec_ctx()) &&
|
||||
OB_NOT_NULL(session_info_->get_cur_exec_ctx()->get_sql_ctx())) {
|
||||
const ObSqlCtx *sql_ctx = session_info_->get_cur_exec_ctx()->get_sql_ctx();
|
||||
LOG_ERROR("Variable assignment in order by items will cause uncertain behavior",
|
||||
K(ObString(sql_ctx->sql_id_)));
|
||||
}
|
||||
}
|
||||
order_item.expr_ = expr;
|
||||
}
|
||||
return ret;
|
||||
|
@ -189,6 +189,7 @@ public:
|
||||
const ParseNode *alias_node,
|
||||
ObChildStmtResolver &child_resolver,
|
||||
TableItem *&table_item);
|
||||
int extract_var_init_exprs(ObSelectStmt *ref_query, common::ObIArray<ObRawExpr*> &assign_exprs);
|
||||
int resolve_generate_table_item(ObSelectStmt *ref_query, const ObString &alias_name, TableItem *&tbl_item);
|
||||
int resolve_joined_table(const ParseNode &parse_node, JoinedTable *&joined_table);
|
||||
int resolve_joined_table_item(const ParseNode &parse_node, JoinedTable *&joined_table);
|
||||
|
@ -1739,9 +1739,14 @@ int ObSelectResolver::resolve_order_item(const ParseNode &sort_node, OrderItem &
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret) && OB_NOT_NULL(order_item.expr_) && order_item.expr_->has_flag(CNT_ASSIGN_EXPR)) {
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
LOG_WARN("Not supported variable assignment in order by item", K(ret));
|
||||
LOG_USER_ERROR(OB_NOT_SUPPORTED, "Variable assignment in order by item");
|
||||
LOG_USER_WARN(OB_ERR_DEPRECATED_SYNTAX, "Setting user variables within expressions",
|
||||
"SET variable=expression, ... or SELECT expression(s) INTO variables(s)");
|
||||
if (OB_NOT_NULL(session_info_) && OB_NOT_NULL(session_info_->get_cur_exec_ctx()) &&
|
||||
OB_NOT_NULL(session_info_->get_cur_exec_ctx()->get_sql_ctx())) {
|
||||
const ObSqlCtx *sql_ctx = session_info_->get_cur_exec_ctx()->get_sql_ctx();
|
||||
LOG_ERROR("Variable assignment in order by items will cause uncertain behavior",
|
||||
K(ObString(sql_ctx->sql_id_)));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -39,7 +39,17 @@ int ObRawExprInfoExtractor::visit(ObConstRawExpr &expr)
|
||||
int ret = OB_SUCCESS;
|
||||
ObItemType type = expr.get_expr_type();
|
||||
switch (type) {
|
||||
//case T_USER_VARIABLE_IDENTIFIER:
|
||||
case T_USER_VARIABLE_IDENTIFIER: {
|
||||
ObUserVarIdentRawExpr &var_expr = static_cast<ObUserVarIdentRawExpr&>(expr);
|
||||
if (var_expr.get_is_contain_assign() || var_expr.get_query_has_udf()) {
|
||||
if (OB_FAIL(var_expr.add_flag(IS_DYNAMIC_USER_VARIABLE))) {
|
||||
LOG_WARN("add flag to user var ident raw expr failed", KR(ret));
|
||||
}
|
||||
} else if (OB_FAIL(var_expr.add_flag(IS_CONST))) {
|
||||
LOG_WARN("failed to add flag IS_CONST", K(ret));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case T_SYSTEM_VARIABLE:
|
||||
case T_QUESTIONMARK: {
|
||||
if (OB_FAIL(expr.add_flag(IS_STATIC_PARAM))) {
|
||||
@ -58,10 +68,8 @@ int ObRawExprInfoExtractor::visit(ObConstRawExpr &expr)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
if (OB_FAIL(ret)) {
|
||||
// do nothing
|
||||
} else if (OB_FAIL(expr.add_flag(IS_CONST))) {
|
||||
if (OB_SUCC(ret) && T_USER_VARIABLE_IDENTIFIER != type) {
|
||||
if (OB_FAIL(expr.add_flag(IS_CONST))) {
|
||||
LOG_WARN("failed to add flag IS_CONST", K(ret));
|
||||
}
|
||||
}
|
||||
|
@ -3340,6 +3340,29 @@ int ObRawExprUtils::extract_set_op_exprs(const ObRawExpr *raw_expr,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObRawExprUtils::extract_var_assign_exprs(const ObRawExpr *raw_expr,
|
||||
ObIArray<ObRawExpr*> &assign_exprs)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_ISNULL(raw_expr)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid raw expr", K(ret), K(raw_expr));
|
||||
} else if (raw_expr->has_flag(IS_ASSIGN_EXPR) && raw_expr->get_relation_ids().is_empty()) {
|
||||
if (OB_FAIL(add_var_to_array_no_dup(assign_exprs, const_cast<ObRawExpr*>(raw_expr)))) {
|
||||
LOG_WARN("failed to append expr", K(ret));
|
||||
}
|
||||
} else {
|
||||
int64_t N = raw_expr->get_param_count();
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < N; ++i) {
|
||||
if (OB_FAIL(SMART_CALL(extract_var_assign_exprs(raw_expr->get_param_expr(i),
|
||||
assign_exprs)))) {
|
||||
LOG_WARN("failed to extract var assign op exprs", K(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObRawExprUtils::extract_set_op_exprs(const ObIArray<ObRawExpr*> &exprs,
|
||||
common::ObIArray<ObRawExpr*> &set_op_exprs)
|
||||
{
|
||||
|
@ -385,6 +385,8 @@ public:
|
||||
static bool is_all_column_exprs(const common::ObIArray<ObRawExpr*> &exprs);
|
||||
static int extract_set_op_exprs(const ObRawExpr *raw_expr,
|
||||
common::ObIArray<ObRawExpr*> &set_op_exprs);
|
||||
static int extract_var_assign_exprs(const ObRawExpr *raw_expr,
|
||||
common::ObIArray<ObRawExpr*> &assign_exprs);
|
||||
static int extract_set_op_exprs(const ObIArray<ObRawExpr*> &exprs,
|
||||
common::ObIArray<ObRawExpr*> &set_op_exprs);
|
||||
/// extract column exprs from the raw expr
|
||||
|
@ -512,6 +512,17 @@ bool ObSQLSessionInfo::is_index_skip_scan_enabled() const
|
||||
return bret;
|
||||
}
|
||||
|
||||
bool ObSQLSessionInfo::is_var_assign_use_das_enabled() const
|
||||
{
|
||||
bool bret = true;
|
||||
int64_t tenant_id = get_effective_tenant_id();
|
||||
omt::ObTenantConfigGuard tenant_config(TENANT_CONF(tenant_id));
|
||||
if (tenant_config.is_valid()) {
|
||||
bret = tenant_config->_enable_var_assign_use_das;
|
||||
}
|
||||
return bret;
|
||||
}
|
||||
|
||||
void ObSQLSessionInfo::destroy(bool skip_sys_var)
|
||||
{
|
||||
if (is_inited_) {
|
||||
|
@ -1150,6 +1150,7 @@ public:
|
||||
bool is_in_range_optimization_enabled() const;
|
||||
int is_better_inlist_enabled(bool &enabled) const;
|
||||
bool is_index_skip_scan_enabled() const;
|
||||
bool is_var_assign_use_das_enabled() const;
|
||||
|
||||
ObSessionDDLInfo &get_ddl_info() { return ddl_info_; }
|
||||
void set_ddl_info(const ObSessionDDLInfo &ddl_info) { ddl_info_ = ddl_info; }
|
||||
|
@ -290,6 +290,7 @@ _enable_tenant_sql_net_thread
|
||||
_enable_trace_session_leak
|
||||
_enable_transaction_internal_routing
|
||||
_enable_values_table_folding
|
||||
_enable_var_assign_use_das
|
||||
_endpoint_tenant_mapping
|
||||
_fast_commit_callback_count
|
||||
_follower_snapshot_read_retry_duration
|
||||
|
Loading…
x
Reference in New Issue
Block a user