forked from oceanbase/oceanbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathob_executor.cpp
More file actions
166 lines (156 loc) · 5.63 KB
/
Copy pathob_executor.cpp
File metadata and controls
166 lines (156 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#define USING_LOG_PREFIX SQL_EXE
#include "sql/executor/ob_executor.h"
#include "lib/stat/ob_diagnose_info.h"
#include "sql/executor/ob_remote_scheduler.h"
#include "sql/executor/ob_task_executor_ctx.h"
#include "sql/executor/ob_execute_result.h"
#include "sql/executor/ob_task_spliter.h"
#include "sql/engine/ob_physical_plan.h"
#include "sql/engine/ob_physical_plan_ctx.h"
#include "sql/session/ob_sql_session_info.h"
#include "sql/engine/ob_exec_context.h"
#include "sql/engine/ob_operator.h"
#include "lib/profile/ob_perf_event.h"
using namespace oceanbase::common;
using namespace oceanbase::sql;
int ObExecutor::init(ObPhysicalPlan *plan)
{
int ret = OB_SUCCESS;
if (true == inited_) {
ret = OB_INIT_TWICE;
LOG_WARN("executor is inited twice", K(ret));
} else if (OB_ISNULL(plan)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("plan is NULL", K(ret));
} else {
phy_plan_ = plan;
inited_ = true;
}
return ret;
}
void ObExecutor::reset()
{
inited_ = false;
phy_plan_ = NULL;
execution_id_ = OB_INVALID_ID;
}
int ObExecutor::execute_plan(ObExecContext &ctx)
{
NG_TRACE(exec_plan_begin);
int ret = OB_SUCCESS;
ObTaskExecutorCtx &task_exec_ctx = ctx.get_task_exec_ctx();
ObExecuteResult &exec_result = task_exec_ctx.get_execute_result();
ObSQLSessionInfo *session_info = ctx.get_my_session();
ObPhysicalPlanCtx *plan_ctx = ctx.get_physical_plan_ctx();
int64_t batched_stmt_cnt = ctx.get_sql_ctx()->multi_stmt_item_.get_batched_stmt_cnt();
ctx.set_use_temp_expr_ctx_cache(true);
// If the batch execution is rewritten by insert multi values, there is no need to repack multiple times
if (ctx.get_sql_ctx()->is_do_insert_batch_opt()) {
batched_stmt_cnt = 0;
}
if (OB_UNLIKELY(!inited_)) {
ret = OB_NOT_INIT;
LOG_WARN("not inited", K(ret));
} else if (OB_ISNULL(session_info)) {
ret = OB_NOT_INIT;
LOG_WARN("session info is NULL", K(ret));
} else if (OB_ISNULL(phy_plan_)) {
ret = OB_NOT_INIT;
LOG_WARN("phy_plan_ is NULL", K(ret));
} else if (OB_FAIL(session_info->set_cur_phy_plan(phy_plan_))) {
LOG_WARN("set extra serialize vars", K(ret));
} else if (OB_FAIL(phy_plan_->get_expr_frame_info()
.pre_alloc_exec_memory(ctx))) {
LOG_WARN("fail to pre allocate memory", K(ret), K(phy_plan_->get_expr_frame_info()));
} else if (batched_stmt_cnt > 0
&& OB_FAIL(plan_ctx->create_implicit_cursor_infos(batched_stmt_cnt))) {
LOG_WARN("create implicit cursor infos failed", K(ret), K(batched_stmt_cnt));
} else {
ObPhyPlanType execute_type = phy_plan_->get_plan_type();
// 特殊处理如下case:
// MULTI PART INSERT (remote)
// SELECT (local)
// 这样的计划在优化器生成阶段,plan type是OB_PHY_PLAN_DISTRIBUTED,
// 但是需要使用local的方式进行执行调度
if (execute_type != OB_PHY_PLAN_LOCAL && phy_plan_->is_require_local_execution()) {
execute_type = OB_PHY_PLAN_LOCAL;
LOG_TRACE("change the plan execution type",
"fact", execute_type, K(phy_plan_->get_plan_type()));
}
switch (execute_type) {
case OB_PHY_PLAN_LOCAL: {
EVENT_INC(SQL_LOCAL_COUNT);
ObOperator *op = NULL;
if (OB_FAIL(phy_plan_->get_root_op_spec()->create_operator(ctx, op))) {
LOG_WARN("create operator from spec failed", K(ret));
} else if (OB_ISNULL(op)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("created operator is NULL", K(ret));
} else {
exec_result.set_static_engine_root(op);
}
break;
}
case OB_PHY_PLAN_REMOTE:
EVENT_INC(SQL_REMOTE_COUNT);
ret = execute_remote_single_partition_plan(ctx);
break;
case OB_PHY_PLAN_DISTRIBUTED:
EVENT_INC(SQL_DISTRIBUTED_COUNT);
// PX 特殊路径
// PX 模式下,调度工作由 ObPxCoord 算子负责
ret = execute_static_cg_px_plan(ctx);
break;
default:
ret = OB_ERR_UNEXPECTED;
break;
}
}
NG_TRACE(exec_plan_end);
return ret;
}
int ObExecutor::execute_remote_single_partition_plan(ObExecContext &ctx)
{
ObRemoteScheduler scheduler;
return scheduler.schedule(ctx, phy_plan_);
}
int ObExecutor::execute_static_cg_px_plan(ObExecContext &ctx)
{
int ret = OB_SUCCESS;
ObOperator *op = NULL;
if (OB_FAIL(phy_plan_->get_root_op_spec()->create_op_input(ctx))) {
LOG_WARN("create input from spec failed", K(ret));
} else if (OB_FAIL(phy_plan_->get_root_op_spec()->create_operator(ctx, op))) {
LOG_WARN("create operator from spec failed", K(ret));
} else if (OB_ISNULL(op)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("created operator is NULL", K(ret));
} else {
ctx.get_task_executor_ctx()
->get_execute_result()
.set_static_engine_root(op);
}
return ret;
}
int ObExecutor::close(ObExecContext &ctx)
{
// close函数要设计成不管什么时候调都可以,因此不管inited_的值
int ret = OB_SUCCESS;
ObSQLSessionInfo *session_info = ctx.get_my_session();
if (OB_LIKELY(NULL != session_info)) {
//将session中的cur_phy_plan_重置为NULL
session_info->reset_cur_phy_plan_to_null();
}
return ret;
}