fix extract onetime expr bug of sharing query ref expr

This commit is contained in:
obdev
2022-11-03 01:36:06 +00:00
committed by wangzelin.wzl
parent 13774e3016
commit 77839a046e
3 changed files with 15 additions and 7 deletions

View File

@ -460,7 +460,7 @@ int get_proc_db_name(
} else { } else {
uint64_t tenant_id = ctx.session_info_->get_login_tenant_id(); uint64_t tenant_id = ctx.session_info_->get_login_tenant_id();
ObSchemaGetterGuard &schema_guard = *ctx.schema_guard_; ObSchemaGetterGuard &schema_guard = *ctx.schema_guard_;
uint64_t db_id; uint64_t db_id = OB_INVALID_ID;
const ObDatabaseSchema *db_schema = NULL; const ObDatabaseSchema *db_schema = NULL;
if (static_cast<uint64_t>(ObObjectType::FUNCTION) == need_priv.obj_type_) { if (static_cast<uint64_t>(ObObjectType::FUNCTION) == need_priv.obj_type_) {
const ObRoutineInfo *routine_schema = NULL; const ObRoutineInfo *routine_schema = NULL;
@ -494,7 +494,7 @@ int get_seq_db_name(
ObString &db_name) ObString &db_name)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
uint64_t db_id; uint64_t db_id = OB_INVALID_ID;
const ObSequenceSchema *seq_schema = NULL; const ObSequenceSchema *seq_schema = NULL;
const ObDatabaseSchema *db_schema = NULL; const ObDatabaseSchema *db_schema = NULL;
OZ (schema_guard.get_sequence_schema(tenant_id, obj_id, seq_schema)); OZ (schema_guard.get_sequence_schema(tenant_id, obj_id, seq_schema));

View File

@ -1046,12 +1046,17 @@ int ObTransformPostProcess::extract_onetime_subquery(ObRawExpr *&expr,
!expr->has_flag(CNT_ALIAS); !expr->has_flag(CNT_ALIAS);
if (is_valid) { if (is_valid) {
int64_t ref_count = 0;
if (OB_FAIL(is_non_correlated_exists_for_onetime(expr, if (OB_FAIL(is_non_correlated_exists_for_onetime(expr,
is_valid_non_correlated_exists))) { is_valid_non_correlated_exists,
ref_count))) {
LOG_WARN("failed to check non correlated exist for one time", K(ret)); LOG_WARN("failed to check non correlated exist for one time", K(ret));
} else if (is_valid_non_correlated_exists && } else if (!is_valid_non_correlated_exists) {
OB_FAIL(onetime_list.push_back(expr))) { // do nothing
} else if (OB_FAIL(onetime_list.push_back(expr))) {
LOG_WARN("failed to push back non-correlated exists", K(ret)); LOG_WARN("failed to push back non-correlated exists", K(ret));
} else if (ref_count > 1) {
is_valid = false;
} }
} }
} }
@ -1165,7 +1170,8 @@ int ObTransformPostProcess::create_onetime_param(ObDMLStmt *stmt,
} }
int ObTransformPostProcess::is_non_correlated_exists_for_onetime(ObRawExpr *expr, int ObTransformPostProcess::is_non_correlated_exists_for_onetime(ObRawExpr *expr,
bool &is_non_correlated_exists_for_onetime) bool &is_non_correlated_exists_for_onetime,
int64_t &ref_count)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
is_non_correlated_exists_for_onetime = false; is_non_correlated_exists_for_onetime = false;
@ -1181,6 +1187,7 @@ int ObTransformPostProcess::is_non_correlated_exists_for_onetime(ObRawExpr *expr
LOG_WARN("failed to check subquery has ref assign user var", K(ret)); LOG_WARN("failed to check subquery has ref assign user var", K(ret));
} else if (!has_ref_assign_user_var && query_ref_expr->get_param_count() == 0) { } else if (!has_ref_assign_user_var && query_ref_expr->get_param_count() == 0) {
is_non_correlated_exists_for_onetime = true; is_non_correlated_exists_for_onetime = true;
ref_count = query_ref_expr->get_ref_count();
} }
} }
return ret; return ret;

View File

@ -142,7 +142,8 @@ private:
const int64_t stmt_level); const int64_t stmt_level);
int is_non_correlated_exists_for_onetime(ObRawExpr *expr, int is_non_correlated_exists_for_onetime(ObRawExpr *expr,
bool &is_non_correlated_exists_for_onetime); bool &is_non_correlated_exists_for_onetime,
int64_t &ref_count);
DISALLOW_COPY_AND_ASSIGN(ObTransformPostProcess); DISALLOW_COPY_AND_ASSIGN(ObTransformPostProcess);
}; };