forked from oceanbase/seekdb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathob_log_sequence.cpp
More file actions
135 lines (127 loc) · 4.32 KB
/
Copy pathob_log_sequence.cpp
File metadata and controls
135 lines (127 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
/*
* 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_OPT
#include "ob_log_sequence.h"
using namespace oceanbase::sql;
using namespace oceanbase::common;
using namespace oceanbase::sql::log_op_def;
int ObLogSequence::get_op_exprs(ObIArray<ObRawExpr*> &all_exprs)
{
int ret = OB_SUCCESS;
const ObDMLStmt *stmt = NULL;
if (OB_ISNULL(stmt = get_stmt())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("stmt is null", K(ret), K(get_stmt()));
} else if (OB_FAIL(stmt->get_sequence_exprs(all_exprs))) {
LOG_WARN("fail get sequence exprs", K(ret));
} else if (OB_FAIL(ObLogicalOperator::get_op_exprs(all_exprs))) {
LOG_WARN("failed to get exprs", K(ret));
} else { /*do nothing*/ }
return ret;
}
int ObLogSequence::est_cost()
{
int ret = OB_SUCCESS;
ObLogicalOperator *child = NULL;
if (OB_ISNULL(get_plan())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else {
ObOptimizerContext &opt_ctx = get_plan()->get_optimizer_context();
if (0 == get_num_of_child()) {
op_cost_ = ObOptEstCost::cost_sequence(0,
nextval_seq_ids_.count(),
opt_ctx);
cost_ = op_cost_;
card_ = 0.0;
} else if (OB_ISNULL(child = get_child(first_child))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else {
op_cost_ = ObOptEstCost::cost_sequence(child->get_card(),
nextval_seq_ids_.count(),
opt_ctx);
cost_ = op_cost_ + child->get_cost();
card_ = child->get_card();
}
}
return ret;
}
int ObLogSequence::est_width()
{
int ret = OB_SUCCESS;
ObLogicalOperator *child = NULL;
double width = 0.0;
if (0 == get_num_of_child()) {
width = 0.0;
} else if (OB_ISNULL(child = get_child(ObLogicalOperator::first_child))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(child), K(ret));
} else {
width = child->get_width() + nextval_seq_ids_.count() * 8;
}
set_width(width);
return ret;
}
int ObLogSequence::do_re_est_cost(EstimateCostInfo ¶m, double &card, double &op_cost, double &cost)
{
int ret = OB_SUCCESS;
double child_card = 0.0;
double child_cost = 0.0;
ObLogicalOperator *child = get_child(ObLogicalOperator::first_child);
if (0 == get_num_of_child()) {
card = get_card();
op_cost = get_op_cost();
cost = get_cost();
} else if (OB_ISNULL(get_plan()) || OB_ISNULL(child)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), K(get_plan()), K(child));
} else if (OB_FAIL(SMART_CALL(child->re_est_cost(param, child_card, child_cost)))) {
LOG_WARN("failed to re est cost", K(ret));
} else {
op_cost = ObOptEstCost::cost_sequence(child_card,
nextval_seq_ids_.count(),
get_plan()->get_optimizer_context());
cost = child_cost + op_cost;
card = child_card;
}
return ret;
}
int ObLogSequence::compute_op_parallel_and_server_info()
{
int ret = common::OB_SUCCESS;
if (get_num_of_child() == 0) {
ret = set_parallel_and_server_info_for_match_all();
} else {
ret = ObLogicalOperator::compute_op_parallel_and_server_info();
}
return ret;
}
int ObLogSequence::is_my_fixed_expr(const ObRawExpr *expr, bool &is_fixed)
{
int ret = OB_SUCCESS;
is_fixed = false;
ObSEArray<ObRawExpr*, 8> sequence_exprs;
if (OB_ISNULL(get_stmt())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("stmt is null", K(ret), K(get_stmt()));
} else if (OB_FAIL(get_stmt()->get_sequence_exprs(sequence_exprs))) {
LOG_WARN("fail get sequence exprs", K(ret));
} else {
is_fixed = ObOptimizerUtil::find_item(sequence_exprs, expr);
}
return ret;
}