forked from oceanbase/seekdb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_sizeof.cpp
More file actions
221 lines (211 loc) · 8.16 KB
/
Copy pathtest_sizeof.cpp
File metadata and controls
221 lines (211 loc) · 8.16 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
* 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.
*/
#include <gtest/gtest.h>
#include "common/object/ob_object.h"
#include "common/row/ob_row.h"
#include "sql/ob_sql_init.h"
#include "sql/engine/expr/ob_sql_expression.h"
#include "sql/engine/ob_phy_operator.h"
#include "sql/engine/ob_single_child_phy_operator.h"
#include "sql/engine/ob_no_children_phy_operator.h"
#include "sql/engine/ob_physical_plan.h"
#include "sql/engine/aggregate/ob_merge_groupby.h"
#include "sql/engine/ob_exec_context.h"
#include "sql/session/ob_sql_session_info.h"
using namespace oceanbase;
using namespace oceanbase::sql;
using namespace oceanbase::common;
using namespace ::testing;
class MockSqlExpression : public common::ObDLinkBase<ObSqlExpression>
{
public:
static ObSqlExpression *alloc();
static void free(ObSqlExpression *ptr);
protected:
friend class ::ObAggregateFunctionTest;
// data members
ObPostfixExpression post_expr_;
};
typedef common::ObGlobalFactory<MockSqlExpression, 1, common::ObModIds::OB_SQL_EXPR>
MockSqlExpressionFactory;
typedef common::ObTCFactory < MockSqlExpression, 1, common::ObModIds::OB_SQL_EXPR, 1 << 24,
8192 > MockSqlExpressionTCFactory;
inline MockSqlExpression *MockSqlExpression::alloc()
{
return MockSqlExpressionTCFactory::get_instance()->get(MockSqlExpression::EXPR_TYPE_SQL);
}
inline void MockSqlExpression::free(MockSqlExpression *expr)
{
if (OB_LIKELY(expr)) {
expr->prev_ = expr->next_ = NULL;
}
MockSqlExpressionTCFactory::get_instance()->put(expr);
}
class mockPhysicalPlan
{
public:
mockPhysicalPlan() {}
~mockPhysicalPlan() {}
int destory()
{
int ret = OB_SUCCESS;
DLIST_FOREACH(node, sql_expression_) {
MockSqlExpression::free(node);
}
return ret;
}
int store_sql_expresion(MockSqlExpression *sql)
{
return sql_expression_.add_last(sql);
}
private:
ObDList<MockSqlExpression> sql_expression_;
};
class ObPhyOperatorTest: public ::testing::Test
{
public:
ObPhyOperatorTest();
virtual ~ObPhyOperatorTest();
virtual void SetUp();
virtual void TearDown();
private:
// disallow copy
ObPhyOperatorTest(const ObPhyOperatorTest &other);
ObPhyOperatorTest& operator=(const ObPhyOperatorTest &other);
private:
// data members
};
ObPhyOperatorTest::ObPhyOperatorTest()
{
}
ObPhyOperatorTest::~ObPhyOperatorTest()
{
}
void ObPhyOperatorTest::SetUp()
{
}
void ObPhyOperatorTest::TearDown()
{
}
TEST_F(ObPhyOperatorTest, physical_plan_size)
{
typedef oceanbase::common::ObFixedArray<ObPhysicalPlan::ObTableVersion, common::ObIAllocator> BaseTableStore;
typedef oceanbase::common::ObFixedArray<ObPhysicalPlan::ObTableVersion, common::ObIAllocator> ViewTableStore;
typedef oceanbase::common::ObFixedArray<common::ObField, common::ObIAllocator> ParamsFieldArray;
typedef oceanbase::common::ObFixedArray<common::ObField, common::ObIAllocator> ColumnsFieldArray;
struct MockPhysicalPlan
{
common::ObArenaAllocator inner_alloc_;
common::ObArenaAllocator &allocator_;
int64_t prepare_count_;
volatile int64_t ref_count_;
int64_t schema_version_;
uint64_t plan_id_;
int64_t hint_timeout_us_;
ObPhyOperator *main_query_;
BaseTableStore table_store_;
ViewTableStore view_table_store_;
int64_t param_count_;
int64_t merged_version_;
common::ObDList<ObSqlExpression> pre_calc_exprs_;
common::ObFixedArray<ObParamInfo, common::ObIAllocator> params_info_;
uint64_t signature_;
ColumnsFieldArray field_columns_;
ParamsFieldArray param_columns_;
common::ObFixedArray<share::AutoincParam, common::ObIAllocator> autoinc_params_; //auto-incrment param
share::schema::ObStmtNeedPrivs stmt_need_privs_;
common::ObFixedArray<ObVarInfo, common::ObIAllocator> vars_;
ObPhyOperatorFactory op_factory_;
ObSqlExpressionFactory sql_expression_factory_;
ObExprOperatorFactory expr_op_factory_;
stmt::StmtType stmt_type_;
stmt::StmtType literal_stmt_type_; // meaning refers to the corresponding definition in ObBasicStmt
ObPhyPlanType plan_type_;
common::ObConsistencyLevel hint_consistency_;
uint32_t next_phy_operator_id_; //share val
// for regexp expression's compilation
int16_t regexp_op_count_;
bool is_sfu_;
bool fetch_cur_time_;
bool is_contain_virtual_table_;//for virtual table service, if it is determined that the statement involves a virtual table
bool is_require_sys_tenant_priv_;
//if the stmt contains user variable assignment
//such as @a:=123
//we may need to serialize the map to remote server
bool is_contains_assignment_;
bool affected_last_insert_id_; //No need to serialize remotely, only needed when generating execution plan and opening result set locally
bool is_affect_found_row_; //not need serialize
};
printf("output mock physical plan = %ld, ModulePageAllocator=%ld\n", sizeof(MockPhysicalPlan), sizeof(ModulePageAllocator));
ObPhysicalPlan plan;
printf("output plan size=%ld\n", sizeof(plan));
common::ObConsistencyLevel hint_consistency;
printf("output enum size = %ld\n", sizeof(hint_consistency));
common::ObDList<ObSqlExpression> sql_expression;
printf("output dlist size=%ld\n", sizeof(sql_expression));
//printf("output fixarray = %ld, IArray=%ld\n", sizeof(common::ObFixedArray), sizeof(common::ObIArray));
printf("output IArray=%ld\n", sizeof(common::ObIArray<int>));
printf("output fixarray = %ld\n", sizeof(common::ObFixedArray<int, common::ObArenaAllocator>));
printf("output physical plan size=%ld\n", sizeof(ObPhysicalPlan));
printf("output factory=%ld, sql_expression=%ld\n", sizeof(ObPhyOperatorFactory), sizeof(ObSqlExpression));
printf("output sql_factory=%ld, expr_op=%ld\n", sizeof(ObSqlExpressionFactory), sizeof(ObExprOperatorFactory));
common::ObArenaAllocator alloc;
common::ObArenaAllocator &a = alloc;
common::ObArenaAllocator *p = &alloc;
printf("output referrence =%ld, Obiallocator=%ld\n", sizeof(common::ObArenaAllocator &), sizeof(common::ObIAllocator &));
printf("output alloc =%ld, refference=%ld, point=%ld\n", sizeof(alloc), sizeof(a), sizeof(p));
printf("output pramInfo before=%ld\n", sizeof(ObParamInfo));
struct MockParamInfo
{
common::ObObjType type_;
common::ObScale scale_;
common::ObObjParam::ParamFlag flag_;
};
printf("output MockParamInfo after=%ld\n", sizeof(MockParamInfo));
printf("output ObPostItem size before=%ld, obj=%ld\n", sizeof(ObPostExprItem),sizeof(common::ObObj));
class MockPostExprItem
{
common::ObObj v1_; // const
union
{
int64_t query_id_;
int64_t cell_index_; // column reference, aka cell index in ObRow
ObExprOperator *op_; // expression operator
ObSetVar::SetScopeType sys_var_scope_;
} v2_;
common::ObAccuracy accuracy_; // for const, column, questionmark
ObItemType item_type_;
};
printf("output MockPostItem size=%ld\n", sizeof(MockPostExprItem));
printf("output ObSqlExpression size=%ld, ObPostfixExpression=%ld\n", sizeof(ObSqlExpression), sizeof(ObPostfixExpression));
printf("output ObDList size=%ld, ObNode size=%ld\n", sizeof(ObDList<int>), sizeof(ObDLinkBase<int>));
printf("output phy_operator =%ld", sizeof(ObPhyOperator));
printf("start to test tc_factory");
mockPhysicalPlan mock_plan;
MockSqlExpression *sql1 = MockSqlExpression::alloc();
MockSqlExpression *sql2 = MockSqlExpression::alloc();
EXPECT_NE(NULL, sql1);
EXPECT_NE(NULL, sql2);
EXPECT_EQ(OB_SUCCESS, mock_plan.store_sql_expresion(sql1));
EXPECT_EQ(OB_SUCCESS, mock_plan.store_sql_expresion(sql2));
mock_plan.destory();
}
int main(int argc, char **argv)
{
init_sql_factories();
::testing::InitGoogleTest(&argc,argv);
return RUN_ALL_TESTS();
}