forked from oceanbase/oceanbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathob_log_plan_factory.cpp
More file actions
138 lines (134 loc) · 4.32 KB
/
Copy pathob_log_plan_factory.cpp
File metadata and controls
138 lines (134 loc) · 4.32 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
/**
* 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_OPT
#include "ob_log_plan_factory.h"
#include "sql/resolver/ob_stmt.h"
#include "sql/optimizer/ob_select_log_plan.h"
#include "sql/optimizer/ob_delete_log_plan.h"
#include "sql/optimizer/ob_update_log_plan.h"
#include "sql/optimizer/ob_insert_log_plan.h"
#include "sql/optimizer/ob_explain_log_plan.h"
#include "sql/optimizer/ob_help_log_plan.h"
#include "sql/optimizer/ob_merge_log_plan.h"
#include "sql/optimizer/ob_insert_all_log_plan.h"
#include "sql/optimizer/ob_optimizer_context.h"
using namespace oceanbase;
using namespace oceanbase::sql;
using namespace oceanbase::common;
ObLogPlanFactory::ObLogPlanFactory(ObIAllocator &allocator)
: allocator_(allocator),
plan_store_(allocator)
{
}
ObLogPlanFactory::~ObLogPlanFactory()
{
//destroy();
}
// TODO(jiuman): will rewrite it with template later to remove redundancy
ObLogPlan *ObLogPlanFactory::create(ObOptimizerContext &ctx, const ObDMLStmt &stmt)
{
ObLogPlan *ret = NULL;
switch (stmt.get_stmt_type()) {
case stmt::T_SHOW_INDEXES:
case stmt::T_SELECT: {
void *ptr = allocator_.alloc(sizeof(ObSelectLogPlan));
if (NULL != ptr) {
ret = new (ptr) ObSelectLogPlan(ctx, static_cast<const ObSelectStmt*>(&stmt));
} else {
SQL_OPT_LOG_RET(WARN, OB_ALLOCATE_MEMORY_FAILED, "Allocate ObSelectLogPlan error");
}
break;
}
case stmt::T_DELETE: {
void *ptr = allocator_.alloc(sizeof(ObDeleteLogPlan));
if (NULL != ptr) {
ret = new (ptr) ObDeleteLogPlan(ctx, static_cast<const ObDeleteStmt*>(&stmt));
} else {
SQL_OPT_LOG_RET(WARN, OB_ALLOCATE_MEMORY_FAILED, "Allocate ObDeleteLogPlan error");
}
break;
}
case stmt::T_UPDATE: {
void *ptr = allocator_.alloc(sizeof(ObUpdateLogPlan));
if (NULL != ptr) {
ret = new (ptr) ObUpdateLogPlan(ctx, static_cast<const ObUpdateStmt*>(&stmt));
} else {
SQL_OPT_LOG_RET(WARN, OB_ALLOCATE_MEMORY_FAILED, "Allocate ObUpdateLogPlan error");
}
break;
}
case stmt::T_INSERT:
case stmt::T_REPLACE: {
void *ptr = allocator_.alloc(sizeof(ObInsertLogPlan));
if (NULL != ptr) {
ret = new (ptr) ObInsertLogPlan(ctx, static_cast<const ObInsertStmt*>(&stmt));
} else {
SQL_OPT_LOG_RET(WARN, OB_ALLOCATE_MEMORY_FAILED, "Allocate ObInsertLogPlan error");
}
break;
}
case stmt::T_EXPLAIN: {
void *ptr = allocator_.alloc(sizeof(ObExplainLogPlan));
if (NULL != ptr) {
ret = new (ptr) ObExplainLogPlan(ctx, &stmt);
} else {
SQL_OPT_LOG_RET(WARN, OB_ALLOCATE_MEMORY_FAILED, "Allocate ObExplainLogPlan error");
}
break;
}
case stmt::T_HELP: {
void *ptr = allocator_.alloc(sizeof(ObHelpLogPlan));
if (NULL != ptr) {
ret = new (ptr) ObHelpLogPlan(ctx, &stmt);
} else {
}
break;
}
case stmt::T_MERGE: {
void *ptr = allocator_.alloc(sizeof(ObMergeLogPlan));
if (NULL != ptr) {
ret = new (ptr) ObMergeLogPlan(ctx, static_cast<const ObMergeStmt*>(&stmt));
} else {
SQL_OPT_LOG_RET(WARN, OB_ALLOCATE_MEMORY_FAILED, "Allocate ObMergeLogPlan error");
}
break;
}
case stmt::T_INSERT_ALL: {
void *ptr = allocator_.alloc(sizeof(ObInsertAllLogPlan));
if (NULL != ptr) {
ret = new (ptr) ObInsertAllLogPlan(ctx, static_cast<const ObInsertAllStmt*>(&stmt));
} else {
SQL_OPT_LOG_RET(WARN, OB_ALLOCATE_MEMORY_FAILED, "Allocate ObInsertAllLogPlan error");
}
break;
}
default:
break;
}
if (ret != NULL) {
int err = OB_SUCCESS;
if (OB_SUCCESS != (err = plan_store_.store_obj(ret))) {
LOG_WARN_RET(err, "store log plan failed", K(err));
ret->~ObLogPlan();
ret = NULL;
}
}
return ret;
}
void ObLogPlanFactory::destroy()
{
DLIST_FOREACH_NORET(node, plan_store_.get_obj_list()) {
if (node != NULL && node->get_obj() != NULL) {
node->get_obj()->destory();
}
}
}