forked from oceanbase/oceanbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathob_trigger_handler.h
More file actions
138 lines (130 loc) · 6.72 KB
/
Copy pathob_trigger_handler.h
File metadata and controls
138 lines (130 loc) · 6.72 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.
*/
#ifndef OCEANBASE_SQL_ENGINE_DML_OB_TRIGGER_HANDLER_OP_
#define OCEANBASE_SQL_ENGINE_DML_OB_TRIGGER_HANDLER_OP_
#include "sql/engine/ob_operator.h"
#include "sql/engine/dml/ob_dml_ctx_define.h"
namespace oceanbase
{
namespace sql
{
class ObTableModifyOp;
class TriggerHandle
{
public:
static int set_rowid_into_row(const ObTriggerColumnsInfo &cols,
const ObObj &rowid_val,
ObObj* cells);
static int set_rowid_into_row(const ObTriggerColumnsInfo &cols,
ObEvalCtx &eval_ctx,
ObExpr *src_expr,
ObObj* cells);
static int init_param_rows(ObEvalCtx &eval_ctx,
const ObTrigDMLCtDef &trig_ctdef,
ObTrigDMLRtDef &trig_rtdef);
static int init_param_old_row(ObEvalCtx &eval_ctx,
const ObTrigDMLCtDef &trig_ctdef,
ObTrigDMLRtDef &trig_rtdef);
static int init_param_new_row(ObEvalCtx &eval_ctx,
const ObTrigDMLCtDef &trig_ctdef,
ObTrigDMLRtDef &trig_rtdef);
static int do_handle_before_row(ObTableModifyOp &dml_op,
ObDASDMLBaseCtDef &das_base_ctdef,
const ObTrigDMLCtDef &trig_ctdef,
ObTrigDMLRtDef &trig_rtdef);
static int do_handle_after_row(ObTableModifyOp &dml_op,
const ObTrigDMLCtDef &trig_ctdef,
ObTrigDMLRtDef &trig_rtdef,
uint64_t tg_event);
static int do_handle_before_stmt(ObTableModifyOp &dml_op,
const ObTrigDMLCtDef &trig_ctdef,
ObTrigDMLRtDef &trig_rtdef,
uint64_t tg_event);
static int do_handle_after_stmt(ObTableModifyOp &dml_op,
const ObTrigDMLCtDef &trig_ctdef,
ObTrigDMLRtDef &trig_rtdef,
uint64_t tg_event);
static int init_trigger_params(ObDMLRtCtx &das_ctx,
uint64_t trigger_event,
const ObTrigDMLCtDef &trig_ctdef,
ObTrigDMLRtDef &trig_rtdef);
static int64_t get_routine_param_count(const uint64_t routine_id);
inline static bool is_trigger_body_routine(const uint64_t package_id,
const uint64_t routine_id,
pl::ObProcType type)
{
bool is_trg_routine = false;
if (schema::ObTriggerInfo::is_trigger_body_package_id(package_id) && pl::ObProcType::PACKAGE_PROCEDURE == type) {
if (lib::is_oracle_mode()) {
is_trg_routine = (routine_id >= ROUTINE_IDX_CALC_WHEN && routine_id <= ROUTINE_IDX_AFTER_STMT);
} else {
is_trg_routine = (routine_id >= ROUTINE_IDX_BEFORE_ROW_MYSQL && routine_id <= ROUTINE_IDX_AFTER_ROW_MYSQL);
}
}
return is_trg_routine;
}
private:
// trigger
static int init_trigger_row(ObIAllocator &alloc, int64_t rowtype_col_count, pl::ObPLRecord *&record);
static int calc_when_condition(ObTableModifyOp &dml_op,
ObTrigDMLRtDef &trig_rtdef,
uint64_t trigger_id,
bool &need_fire);
static int calc_before_row(ObTableModifyOp &dml_op, ObTrigDMLRtDef &trig_rtdef, uint64_t trigger_id);
static int calc_after_row(ObTableModifyOp &dml_op, ObTrigDMLRtDef &trig_rtdef, uint64_t trigger_id);
static int calc_before_stmt(ObTableModifyOp &dml_op,
ObTrigDMLRtDef &trig_rtdef,
uint64_t trigger_id);
static int calc_after_stmt(ObTableModifyOp &dml_op, ObTrigDMLRtDef &trig_rtdef, uint64_t trigger_id);
static int calc_trigger_routine(ObExecContext &exec_ctx,
uint64_t trigger_id,
uint64_t routine_id,
ParamStore ¶ms);
static int calc_trigger_routine(ObExecContext &exec_ctx,
uint64_t trigger_id,
uint64_t routine_id,
ParamStore ¶ms,
ObObj &result);
static int check_and_update_new_row(ObTableModifyOp *self_op,
const ObTriggerColumnsInfo &columns,
ObEvalCtx &eval_ctx,
const ObIArray<ObExpr *> &new_row_exprs,
pl::ObPLRecord *new_record,
bool check);
static int do_handle_rowid_before_row(ObTableModifyOp &dml_op,
const ObTrigDMLCtDef &trig_ctdef,
ObTrigDMLRtDef &trig_rtdef,
uint64_t tg_event);
static int do_handle_rowid_after_row(ObTableModifyOp &dml_op,
const ObTrigDMLCtDef &trig_ctdef,
ObTrigDMLRtDef &trig_rtdef,
uint64_t tg_event);
static inline int destroy_compound_trigger_state(ObExecContext &exec_ctx, const ObTrigDMLCtDef &trig_ctdef);
private:
static const uint64_t ROUTINE_IDX_CALC_WHEN = 1;
static const uint64_t ROUTINE_IDX_BEFORE_STMT = 2;
static const uint64_t ROUTINE_IDX_BEFORE_ROW = 3;
static const uint64_t ROUTINE_IDX_AFTER_ROW = 4;
static const uint64_t ROUTINE_IDX_AFTER_STMT = 5;
static const uint64_t ROUTINE_IDX_BEFORE_ROW_MYSQL = 1;
static const uint64_t ROUTINE_IDX_AFTER_ROW_MYSQL = 2;
static const int64_t WHEN_POINT_PARAM_OFFSET = 0;
static const int64_t WHEN_POINT_PARAM_COUNT = 2;
static const int64_t STMT_POINT_PARAM_OFFSET = 2;
static const int64_t STMT_POINT_PARAM_COUNT = 0;
static const int64_t ROW_POINT_PARAM_OFFSET = 0;
static const int64_t ROW_POINT_PARAM_COUNT = 2;
static const int64_t ROW_POINT_PARAM_COUNT_MYSQL = 2;
};
} // namespace sql
} // namespace oceanbase
#endif