refine plan generate strategy for remote sql

This commit is contained in:
yb0
2021-12-21 15:09:54 +08:00
committed by LINxiansheng
parent fe44cd94cf
commit 62a736875f
2 changed files with 21 additions and 39 deletions

View File

@ -29,9 +29,10 @@ int ObOptimizer::optimize(ObDMLStmt& stmt, ObLogPlan*& logical_plan)
const ObSQLSessionInfo* session = ctx_.get_session_info();
int64_t last_mem_usage = ctx_.get_allocator().total();
int64_t optimizer_mem_usage = 0;
if (OB_ISNULL(query_ctx) || OB_ISNULL(session)) {
ObTaskExecutorCtx* task_exec_ctx = ctx_.get_task_exec_ctx();
if (OB_ISNULL(query_ctx) || OB_ISNULL(session) || OB_ISNULL(task_exec_ctx)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid arguments", K(ret), K(query_ctx), K(session));
LOG_WARN("invalid arguments", K(ret), K(query_ctx), K(session), K(task_exec_ctx));
} else if (OB_FAIL(init_env_info(stmt))) {
LOG_WARN("failed to init px info", K(ret));
} else if (OB_FAIL(generate_plan_for_temp_table(stmt))) {
@ -62,6 +63,22 @@ int ObOptimizer::optimize(ObDMLStmt& stmt, ObLogPlan*& logical_plan)
LOG_USER_ERROR(OB_OP_NOT_ALLOW, "Access tables from multiple tenants");
}
}
if (OB_SUCC(ret)) {
if (ctx_.get_exec_ctx()->get_sql_ctx()->is_remote_sql_ && plan->get_phy_plan_type() != OB_PHY_PLAN_LOCAL) {
// set table location to refresh location cache
ObSEArray<ObTablePartitionInfo*, 8> table_partitions;
if (OB_FAIL(plan->get_global_table_partition_info(table_partitions))) {
LOG_WARN("failed to get global table partition info", K(ret));
} else if (OB_FAIL(task_exec_ctx->set_table_locations(table_partitions))) {
LOG_WARN("failed to set table locations", K(ret));
}
if (OB_SUCC(ret)) {
ret = OB_LOCATION_NOT_EXIST;
LOG_WARN("best plan for remote sql is not local", K(ret), K(plan->get_phy_plan_type()));
}
}
}
if (OB_SUCC(ret)) {
logical_plan = plan;
LOG_TRACE("succ to optimize statement", "stmt", stmt.get_sql_stmt(), K(logical_plan->get_optimization_cost()));