forked from oceanbase/seekdb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathob_executor.cpp
More file actions
172 lines (163 loc) · 5.7 KB
/
Copy pathob_executor.cpp
File metadata and controls
172 lines (163 loc) · 5.7 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
167
168
169
170
171
172
/*
* Copyright (c) 2025 OceanBase.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define USING_LOG_PREFIX SQL_EXE
#include "ob_executor.h"
#include "sql/executor/ob_remote_scheduler.h"
#include "sql/executor/ob_task_spliter.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();
// Special handling for the following cases:
// MULTI PART INSERT (remote)
// SELECT (local)
// Such a plan in the optimizer generation phase, plan type is OB_PHY_PLAN_DISTRIBUTED,
// But need to use local way for execution scheduling
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: {
if (session_info->is_inner()) {
EVENT_INC(SQL_INNER_LOCAL_COUNT);
} else {
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:
if (session_info->is_inner()) {
EVENT_INC(SQL_INNER_REMOTE_COUNT);
} else {
EVENT_INC(SQL_REMOTE_COUNT);
}
ret = execute_remote_single_partition_plan(ctx);
break;
case OB_PHY_PLAN_DISTRIBUTED:
if (session_info->is_inner()) {
EVENT_INC(SQL_INNER_DISTRIBUTED_COUNT);
} else {
EVENT_INC(SQL_DISTRIBUTED_COUNT);
}
// PX special path
// PX mode, scheduling work is handled by the ObPxCoord operator
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 function should be designed to be callable at any time, therefore regardless of the value of inited_
int ret = OB_SUCCESS;
ObSQLSessionInfo *session_info = ctx.get_my_session();
if (OB_LIKELY(NULL != session_info)) {
// Reset cur_phy_plan_ in session to NULL
session_info->reset_cur_phy_plan_to_null();
}
return ret;
}