forked from oceanbase/oceanbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathob_sql_utils.cpp
More file actions
3859 lines (3682 loc) · 152 KB
/
ob_sql_utils.cpp
File metadata and controls
3859 lines (3682 loc) · 152 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* 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 "sql/ob_sql_utils.h"
#include "sql/ob_sql.h"
#include <sys/time.h>
#include <openssl/md5.h>
#include "lib/string/ob_sql_string.h"
#include "lib/timezone/ob_time_convert.h"
#include "common/sql_mode/ob_sql_mode_utils.h"
#include "share/ob_i_data_access_service.h"
#include "share/stat/ob_stat_manager.h"
#include "share/stat/ob_table_stat.h"
#include "storage/ob_partition_service.h"
#include "sql/parser/ob_parser.h"
#include "sql/parser/parse_malloc.h"
#include "sql/parser/parse_node.h"
#include "sql/code_generator/ob_expr_generator_impl.h"
#include "sql/code_generator/ob_code_generator_impl.h"
#include "sql/resolver/expr/ob_raw_expr_util.h"
#include "sql/resolver/ob_resolver_utils.h"
#include "sql/resolver/dml/ob_sql_hint.h"
#include "sql/resolver/ob_stmt_type.h"
#include "sql/resolver/expr/ob_raw_expr_precalc_analyzer.h"
#include "sql/engine/ob_exec_context.h"
#include "sql/engine/expr/ob_expr_func_part_hash.h"
#include "sql/engine/expr/ob_expr_column_conv.h"
#include "sql/rewrite/ob_query_range.h"
#include "sql/session/ob_basic_session_info.h"
#include "sql/plan_cache/ob_sql_parameterization.h"
#include "sql/ob_select_stmt_printer.h"
#include "sql/ob_insert_stmt_printer.h"
#include "sql/ob_update_stmt_printer.h"
#include "sql/ob_delete_stmt_printer.h"
#include "sql/ob_merge_stmt_printer.h"
#include "sql/executor/ob_task_executor_ctx.h"
#include "sql/optimizer/ob_route_policy.h"
#include "sql/rewrite/ob_transform_rule.h"
#include "common/ob_smart_call.h"
#include "observer/omt/ob_tenant_timezone_mgr.h"
#include "share/schema/ob_schema_printer.h"
#include "sql/resolver/expr/ob_raw_expr.h"
using namespace oceanbase;
using namespace oceanbase::sql;
using namespace oceanbase::obmysql;
using namespace oceanbase::common;
using namespace oceanbase::share;
using namespace oceanbase::share::schema;
bool ObSQLUtils::is_trans_commit_need_disconnect_err(int err)
{
bool bool_ret = true;
if (OB_SUCCESS == err || OB_TRANS_KILLED == err || OB_TRANS_CTX_NOT_EXIST == err || OB_TRANS_TIMEOUT == err ||
OB_TRANS_STMT_TIMEOUT == err || OB_TRANS_NEED_ROLLBACK == err || OB_TRANS_ROLLBACKED == err ||
OB_NOT_MASTER == err || OB_TRANS_IS_EXITING == err) {
bool_ret = false;
}
return bool_ret;
}
void ObSQLUtils::check_if_need_disconnect_after_end_trans(
const int end_trans_err, const bool is_rollback, const bool is_explicit, bool& is_need_disconnect)
{
is_need_disconnect = false;
if (is_rollback) {
// rollback
if (OB_UNLIKELY(OB_SUCCESS != end_trans_err && is_explicit)) {
is_need_disconnect = true;
LOG_WARN("fail to rollback explicitly, disconnect", K(end_trans_err));
} else {
is_need_disconnect = false;
}
} else {
// commit
if (OB_UNLIKELY(ObSQLUtils::is_trans_commit_need_disconnect_err(end_trans_err))) {
is_need_disconnect = true;
LOG_WARN("fail to commit, and error number is unexpected, disconnect", K(end_trans_err), K(lbt()));
} else {
is_need_disconnect = false;
}
}
}
int ObSQLUtils::md5(const ObString& stmt, char* sql_id, int32_t len)
{
const int32_t MD5_LENGTH = 16;
int ret = OB_SUCCESS;
if (sql_id == NULL || len < 32) {
ret = OB_INVALID_ARGUMENT;
SQL_PC_LOG(WARN, "invalid args", KP(sql_id), K(len));
}
char md5_sum_buf[MD5_LENGTH];
ObString::obstr_size_t md5_sum_len = MD5_LENGTH;
if (OB_SUCC(ret)) {
unsigned char* res = MD5(reinterpret_cast<const unsigned char*>(stmt.ptr()),
stmt.length(),
reinterpret_cast<unsigned char*>(md5_sum_buf));
if (OB_ISNULL(res)) {
// MD5() in openssl always return an pointer not NULL, so we need not check return value.
// see:
// http://www.openssl.org/docs/crypto/md5.html#DESCRIPTION
// http://www.openssl.org/docs/crypto/md5.html#RETURN_VALUES
// Even so, we HAVE TO check it here. You know it.
ret = OB_ERR_UNEXPECTED;
LOG_WARN("md5 res null pointer", K(ret), K(res));
} else if (OB_FAIL(to_hex_cstr(md5_sum_buf, md5_sum_len, sql_id, len))) {
LOG_WARN("transform to hex str error", K(ret));
} else {
} // do nothing
}
return ret;
}
int ObSQLUtils::calc_partition_ids(const ObIArray<ObNewRange*>& ranges, const ObSqlExpression& partition_func,
const uint64_t part_num, ObIArray<uint64_t>& partition_ids)
{
int ret = OB_SUCCESS;
ObSEArray<uint64_t, 16> par_ids; // for keeping the perhaps duplicate partition ids
ObNewRow calc_row;
ObExprCtx expr_ctx;
ObObj result;
ObArenaAllocator allocator(common::ObModIds::OB_SQL_EXPR_CALC);
expr_ctx.calc_buf_ = &allocator;
int64_t N = ranges.count();
for (int64_t i = 0; OB_SUCC(ret) && i < N; ++i) {
// calculate
ObNewRange* range = ranges.at(i);
if (OB_ISNULL(range)) {
ret = OB_ERR_UNEXPECTED;
SQL_EXE_LOG(WARN, "invalid argument", K(ret));
} else {
calc_row.reset();
result.reset();
int64_t result_par_id = 0;
// assuming all ranges are single-value
calc_row.cells_ = const_cast<ObObj*>(range->start_key_.get_obj_ptr());
calc_row.count_ = (range->start_key_.get_obj_cnt());
if (OB_FAIL(partition_func.calc(expr_ctx, calc_row, result))) {
SQL_EXE_LOG(WARN, "fail to calc hash expr", K(ret), K(calc_row));
} else if (OB_FAIL(result.get_int(result_par_id))) {
SQL_EXE_LOG(WARN, "fail to get int64 from result", K(ret), K(result));
} else if (OB_FAIL(par_ids.push_back(result_par_id % part_num))) {
SQL_EXE_LOG(WARN, "fail to push back partition id into array", K(ret));
}
}
}
if (OB_SUCC(ret)) {
for (int64_t i = 0; OB_SUCC(ret) && i < par_ids.count(); ++i) {
bool duplicated = false;
for (int64_t j = 0; !duplicated && j < partition_ids.count(); ++j) {
if (par_ids.at(i) == partition_ids.at(j)) {
duplicated = true;
}
}
if (!duplicated) {
if (OB_FAIL(partition_ids.push_back(par_ids.at(i)))) {
SQL_EXE_LOG(WARN, "fail to push back partition id into array", K(ret));
}
}
}
}
return ret;
}
int ObSQLUtils::get_phy_plan_type(
ObIArray<share::ObPartitionLocation>& part_location_set, const ObAddr& my_address, ObPhyPlanType& plan_type)
{
int ret = OB_SUCCESS;
bool is_same = true;
int64_t N = part_location_set.count();
if (0 == N) {
plan_type = OB_PHY_PLAN_LOCAL;
LOG_TRACE("no tables used, thus local plan");
} else {
ObReplicaLocation replica_first;
if (OB_FAIL(part_location_set.at(0).get_strong_leader(replica_first))) {
SQL_EXE_LOG(WARN, "failed to get leader replica location", K(ret));
} else {
SQL_EXE_LOG(DEBUG, "part_location_set first replica", K(ret), K(replica_first));
for (int64_t i = 1; OB_SUCC(ret) && true == is_same && i < N; ++i) {
ObReplicaLocation replica_location;
if (OB_FAIL(part_location_set.at(i).get_strong_leader(replica_location))) {
SQL_EXE_LOG(WARN, "failed to get leader replica location", K(ret));
} else {
is_same = is_same && (replica_location.server_ == replica_first.server_);
SQL_EXE_LOG(DEBUG, "part_location_set replica", K(ret), K(i), K(replica_location));
}
}
if (OB_SUCC(ret)) {
if (is_same) {
if (my_address == replica_first.server_) {
plan_type = OB_PHY_PLAN_LOCAL;
} else {
plan_type = OB_PHY_PLAN_REMOTE;
}
} else {
plan_type = OB_PHY_PLAN_DISTRIBUTED;
}
}
}
}
return ret;
}
int ObSQLUtils::has_local_leader_replica(
const ObPartitionLocationIArray& part_array, const ObAddr& addr, ObPartitionKey& key, bool& has_local)
{
int ret = OB_SUCCESS;
// get first local partition
has_local = false;
// init with firt partition key
if (part_array.count() > 0) {
if (OB_FAIL(part_array.at(0).get_partition_key(key))) {
LOG_WARN("Get partition key error", "partition", part_array.at(0), K(ret));
}
}
for (int64_t i = 0; !has_local && OB_SUCCESS == ret && i < part_array.count(); i++) {
ObReplicaLocation replica_leader;
if (OB_FAIL(part_array.at(i).get_strong_leader(replica_leader))) {
LOG_WARN("Get leader error", K(ret));
} else if (addr == replica_leader.server_) { // local partition
if (OB_FAIL(part_array.at(i).get_partition_key(key))) {
LOG_WARN("Get partition key error", "partition", part_array.at(i), K(ret));
} else {
has_local = true;
}
}
}
return ret;
}
int ObSQLUtils::has_local_replica(const ObPhyPartitionLocationInfoIArray& part_loc_info_array,
const common::ObAddr& addr, common::ObPartitionKey& key, bool& has_local)
{
int ret = OB_SUCCESS;
has_local = false;
// init with firt partition key
if (part_loc_info_array.count() > 0) {
if (OB_FAIL(part_loc_info_array.at(0).get_partition_location().get_partition_key(key))) {
LOG_WARN("Get partition key error", "partition info", part_loc_info_array.at(0), K(ret));
}
}
for (int64_t i = 0; !has_local && OB_SUCC(ret) && i < part_loc_info_array.count(); ++i) {
const ObOptPartLoc& part_loc = part_loc_info_array.at(i).get_partition_location();
const ObIArray<ObRoutePolicy::CandidateReplica>& replica_loc_array = part_loc.get_replica_locations();
for (int64_t j = 0; !has_local && OB_SUCC(ret) && j < replica_loc_array.count(); ++j) {
const ObReplicaLocation& replica_location = replica_loc_array.at(j);
if (addr == replica_location.server_) {
if (OB_FAIL(part_loc.get_partition_key(key))) {
LOG_WARN("Get partition key error", K(part_loc), K(ret));
} else {
has_local = true;
}
}
}
}
if (OB_FAIL(ret)) {
LOG_TRACE("[FIND LOCAL REPLICA] ret is failed", K(ret), K(key), K(addr), K(has_local));
} else if (has_local) {
LOG_TRACE("[FIND LOCAL REPLICA] has local replica", K(key), K(addr));
} else {
LOG_TRACE("[FIND LOCAL REPLICA] no local replica", K(addr));
}
return ret;
}
int ObSQLUtils::find_all_local_replica(const ObPhyPartitionLocationInfoIArray& part_loc_info_array,
const common::ObAddr& addr, common::ObIArray<common::ObPartitionKey>& keys)
{
int ret = OB_SUCCESS;
for (int64_t i = 0; OB_SUCC(ret) && i < part_loc_info_array.count(); ++i) {
const ObOptPartLoc& part_loc = part_loc_info_array.at(i).get_partition_location();
const ObIArray<ObRoutePolicy::CandidateReplica>& replica_loc_array = part_loc.get_replica_locations();
ObPartitionKey temp_key;
bool has_local = false;
for (int64_t j = 0; OB_SUCC(ret) && !has_local && j < replica_loc_array.count(); j++) {
const ObReplicaLocation& replica_location = replica_loc_array.at(j);
if (addr == replica_location.server_) {
if (OB_FAIL(part_loc.get_partition_key(temp_key))) {
LOG_WARN("Get partition key error", K(part_loc), K(ret));
} else if (OB_FAIL(keys.push_back(temp_key))) {
LOG_WARN("failed to push back temp key", K(ret));
} else {
has_local = true;
}
}
}
}
return ret;
}
int ObSQLUtils::replace_questionmarks(ParseNode* tree, const ParamStore& params)
{
int ret = OB_SUCCESS;
bool is_stack_overflow = false;
if (OB_FAIL(check_stack_overflow(is_stack_overflow))) {
LOG_WARN("failed to check stack overflow", K(ret), K(is_stack_overflow));
} else if (is_stack_overflow) {
ret = OB_SIZE_OVERFLOW;
LOG_WARN("too deep recursive", K(ret), K(is_stack_overflow));
} else if (NULL != tree) {
// replace ? with given params
if (T_QUESTIONMARK == tree->type_) {
const ObObj& param = params.at(tree->value_);
switch (param.get_type()) {
case ObIntType:
tree->value_ = param.get_int();
tree->type_ = T_INT;
break;
case ObDateTimeType:
tree->value_ = param.get_datetime();
tree->type_ = T_DATETIME;
break;
case ObTimestampType:
tree->value_ = param.get_timestamp();
tree->type_ = T_TIMESTAMP;
break;
case ObDateType:
tree->value_ = param.get_date();
tree->type_ = T_DATE;
break;
case ObTimeType:
tree->value_ = param.get_time();
tree->type_ = T_TIME;
break;
case ObYearType:
tree->value_ = param.get_year();
tree->type_ = T_YEAR;
break;
case ObVarcharType:
tree->str_value_ = param.get_varchar().ptr();
tree->str_len_ = param.get_varchar().length();
tree->type_ = T_VARCHAR;
break;
case ObTinyIntType:
tree->value_ = param.get_bool();
tree->type_ = T_BOOL;
break;
case ObNumberType:
tree->str_value_ = param.get_number().format();
tree->type_ = T_NUMBER;
break;
default:
LOG_WARN("never reach here", "type", param.get_type());
break;
}
}
for (int32_t i = 0; OB_SUCC(ret) && i < tree->num_child_; ++i) {
if (OB_ISNULL(tree->children_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("invalid argument");
} else {
ret = SMART_CALL(replace_questionmarks(tree->children_[i], params));
}
}
}
return ret;
}
int ObSQLUtils::calc_const_or_calculable_expr(const stmt::StmtType stmt_type, ObSQLSessionInfo* session,
const ObRawExpr* raw_expr, ObObj& result, const ParamStore* params, ObIAllocator& allocator)
{
int ret = OB_SUCCESS;
ObRawExprFactory expr_factory(allocator);
if (OB_ISNULL(raw_expr) || OB_ISNULL(params)) {
ret = OB_INVALID_ARGUMENT;
SQL_LOG(WARN, "Input arguments error", K(raw_expr), K(params), K(ret));
} else if (raw_expr->is_const_expr()) {
bool need_check = false;
if (OB_FAIL(calc_const_expr(raw_expr, params, result, need_check))) {
SQL_LOG(WARN, "failed to calc const expr", K(ret));
} else { /*do nothing*/
}
} else if (raw_expr->has_flag(IS_CALCULABLE_EXPR)) {
if (OB_FAIL(calc_calculable_expr(stmt_type, session, raw_expr, result, &allocator, *params))) {
SQL_LOG(WARN, "Get calculable expr value without addr to parition id error", K(ret));
}
} else {
ret = OB_INVALID_ARGUMENT;
SQL_LOG(WARN, "Expr should be const_expr or calculable_expr", K(*raw_expr), K(ret));
}
return ret;
}
int ObSQLUtils::calc_simple_expr_without_row(const stmt::StmtType stmt_type, ObSQLSessionInfo* session,
const ObRawExpr* raw_expr, ObObj& result, const ParamStore* params, ObIAllocator& allocator)
{
int ret = OB_SUCCESS;
ObRawExprFactory expr_factory(allocator);
if (OB_ISNULL(raw_expr) || OB_ISNULL(params)) {
ret = OB_INVALID_ARGUMENT;
SQL_LOG(WARN, "Input arguments error", K(raw_expr), K(params), K(ret));
} else if (raw_expr->is_const_expr()) {
bool need_check = false;
if (OB_FAIL(calc_const_expr(raw_expr, params, result, need_check))) {
SQL_LOG(WARN, "failed to calc const expr", KPC(raw_expr), K(ret));
} else { /*do nothing*/
}
} else if (OB_FAIL(calc_const_expr(stmt_type, session, *raw_expr, result, allocator, *params))) {
SQL_LOG(WARN, "Get const_expr value error", KPC(raw_expr), K(ret));
}
return ret;
}
int ObSQLUtils::calc_raw_expr_without_row(ObExecContext& exec_ctx, const ObRawExpr* raw_expr, ObObj& result,
const ParamStore* params, ObIAllocator& allocator)
{
int ret = OB_SUCCESS;
bool is_overflow = false;
if (OB_FAIL(check_stack_overflow(is_overflow))) {
LOG_WARN("failed to check stack overflow", K(ret));
} else if (is_overflow) {
ret = OB_SIZE_OVERFLOW;
LOG_WARN("too deep recusive", K(ret));
}
if (OB_FAIL(ret)) {
// do nothing
} else if (OB_ISNULL(raw_expr)) {
ret = OB_INVALID_ARGUMENT;
SQL_LOG(WARN, "Input arguments error", K(raw_expr), K(ret));
} else if (raw_expr->is_const_expr()) {
bool need_check = false;
if (OB_FAIL(calc_const_expr(raw_expr, params, result, need_check))) {
SQL_LOG(WARN, "failed to calc const expr", K(ret));
} else { /*do nothing*/
}
} else {
ParamStore empty_params;
if (OB_FAIL(calc_const_expr(
stmt::T_NONE, exec_ctx, raw_expr, result, &allocator, NULL == params ? empty_params : *params))) {
SQL_LOG(WARN, "Get calculable expr value without addr to parition id error", K(ret));
} else { /*do nothing*/
}
}
return ret;
}
int ObSQLUtils::calc_sql_expression_without_row(ObExecContext& exec_ctx, const ObISqlExpression& expr, ObObj& result)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(exec_ctx.get_physical_plan_ctx())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("physical plan context is NULL", K(ret));
} else if (OB_ISNULL(exec_ctx.get_my_session())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("session is NULL", K(ret));
} else {
ObExprCtx expr_ctx;
ObNewRow empty_row;
exec_ctx.get_physical_plan_ctx()->set_cur_time(ObTimeUtility::current_time()); // set the current time
if (OB_FAIL(wrap_expr_ctx(stmt::T_NONE, exec_ctx, exec_ctx.get_allocator(), expr_ctx))) {
LOG_WARN("Failed to wrap expr ctx", K(ret));
} else if (OB_FAIL(expr.calc(expr_ctx, empty_row, result))) {
LOG_WARN("failed to calc expression", K(ret), K(expr));
}
}
return ret;
}
int ObSQLUtils::calc_const_expr(
const ObRawExpr* expr, const ParamStore* params, common::ObObj& result, bool& need_check)
{
int ret = OB_SUCCESS;
const ObConstRawExpr* const_expr = NULL;
need_check = false;
if (OB_ISNULL(expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(expr), K(ret));
} else if (OB_UNLIKELY(!expr->is_const_expr())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("not const expr", K(expr->get_expr_type()), K(ret));
} else if (FALSE_IT(const_expr = static_cast<const ObConstRawExpr*>(expr))) {
// do nothing
} else if (T_QUESTIONMARK == const_expr->get_expr_type()) {
if (OB_ISNULL(params)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(params), K(ret));
} else if (OB_FAIL(get_param_value(const_expr->get_value(), *params, result, need_check))) {
LOG_WARN("get param value error", K(ret));
} else { /*do nothing*/
}
} else {
need_check = true;
result = const_expr->get_value();
}
return ret;
}
int ObSQLUtils::get_param_value(
const common::ObObj& param, const ParamStore& params_array, ObObjParam& result, bool& need_check)
{
return get_param_value<ObObjParam>(param, params_array, result, need_check);
}
int ObSQLUtils::get_param_value(
const common::ObObj& param, const ParamStore& params_array, common::ObObj& result, bool& need_check)
{
return get_param_value<ObObj>(param, params_array, result, need_check);
}
template <class T>
int ObSQLUtils::get_param_value(const ObObj& param, const ParamStore& params_array, T& result, bool& need_check)
{
int ret = OB_SUCCESS;
int64_t param_idx = -1;
need_check = false;
if (param.is_unknown()) {
if (OB_FAIL(param.get_unknown(param_idx))) {
SQL_LOG(WARN, "get question mark value failed", K(param), K(ret));
} else if (param_idx < 0 || param_idx >= params_array.count()) {
ret = OB_ERR_ILLEGAL_INDEX;
SQL_LOG(WARN, "Wrong index of question mark position", K(ret), K(param_idx));
} else {
need_check = params_array.at(param_idx).need_to_check_bool_value();
result = params_array.at(param_idx);
if (result.is_nop_value()) {
ret = OB_ERR_NOP_VALUE;
}
}
}
return ret;
}
int ObSQLUtils::calc_calculable_expr(const stmt::StmtType stmt_type, ObSQLSessionInfo* session, const ObRawExpr* expr,
ObObj& result, ObIAllocator* allocator, const ParamStore& params_array)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(expr) || OB_ISNULL(allocator)) {
ret = OB_INVALID_ARGUMENT;
SQL_LOG(WARN, "Invalid arguments", K(expr), K(allocator));
} else if (!expr->has_flag(IS_CALCULABLE_EXPR)) {
ret = OB_INVALID_ARGUMENT;
SQL_LOG(WARN, "expr should be calculabe expr", K(*expr), K(ret));
} else if (OB_FAIL(calc_const_expr(stmt_type, session, *expr, result, *allocator, params_array))) {
SQL_LOG(WARN, "failed to calc const expr", K(*expr), K(ret));
} else { /*do nothing*/
}
return ret;
}
int ObSQLUtils::calc_const_expr(const stmt::StmtType stmt_type, ObExecContext& exec_ctx, const ObRawExpr* expr,
ObObj& result, ObIAllocator* allocator, const ParamStore& params_array)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(expr) || OB_ISNULL(allocator)) {
ret = OB_INVALID_ARGUMENT;
SQL_LOG(WARN, "Invalid arguments", K(expr), K(allocator));
} else if (OB_FAIL(calc_const_expr(
stmt_type, exec_ctx.get_my_session(), *expr, result, *allocator, params_array, &exec_ctx))) {
SQL_LOG(WARN, "failed to calc const expr", K(*expr), K(ret));
} else { /*do nothing*/
}
return ret;
}
int ObSQLUtils::calc_const_expr(const stmt::StmtType stmt_type, ObSQLSessionInfo* session, const ObRawExpr& expr,
ObObj& result, ObIAllocator& allocator, const ParamStore& params_array, ObExecContext* exec_ctx)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(session)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid null session", K(ret));
} else if (session->use_static_typing_engine()) {
if (OB_FAIL(calc_const_expr(session, &expr, params_array, allocator, result))) {
LOG_WARN("failed to calc const expr", K(ret));
}
} else {
ObPhysicalPlan phy_plan;
ObPhysicalPlanCtx phy_plan_ctx(allocator);
ObSqlExpression sql_expr(allocator, 0);
SMART_VAR(ObExecContext, exec_ctx_dummy)
{
ObExecContext* exec_ctx_p = exec_ctx;
ObExprCtx expr_ctx;
RowDesc row_desc;
ObNewRow empty_row;
ObExprGeneratorImpl expr_generator(0, 0, NULL, row_desc);
if (OB_ISNULL(exec_ctx_p)) {
exec_ctx_dummy.set_my_session(session);
exec_ctx_p = &exec_ctx_dummy;
}
phy_plan_ctx.set_cur_time(ObTimeUtility::current_time(), *session);
if (OB_FAIL(wrap_expr_ctx(stmt_type, *exec_ctx_p, allocator, expr_ctx))) {
LOG_WARN("fail to wrap expr ctx", K(ret));
}
for (int64_t i = 0; OB_SUCC(ret) && i < params_array.count(); i++) {
if (OB_FAIL(phy_plan_ctx.get_param_store_for_update().push_back(params_array.at(i)))) {
SQL_LOG(WARN, "Add param to param_store failed", K(ret));
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(expr_generator.generate(const_cast<ObRawExpr&>(expr), sql_expr))) {
SQL_LOG(WARN, "Generate post_expr error", K(ret));
} else {
phy_plan.set_regexp_op_count(expr_generator.get_cur_regexp_op_count());
phy_plan.set_like_op_count(expr_generator.get_cur_like_op_count());
phy_plan_ctx.set_phy_plan(&phy_plan);
expr_ctx.phy_plan_ctx_ = &phy_plan_ctx;
if (OB_FAIL(sql_expr.calc(expr_ctx, empty_row, result))) {
SQL_LOG(WARN, "Fail to calc expression", K(sql_expr), K(ret));
}
}
}
}
}
return ret;
}
int ObSQLUtils::calc_const_expr(ObSQLSessionInfo* session, const ObRawExpr* expr, const ParamStore& params,
ObIAllocator& allocator, common::ObObj& result)
{
int ret = OB_SUCCESS;
OB_ASSERT(NULL != session);
lib::ContextParam param;
param.set_mem_attr(session->get_effective_tenant_id(), ObModIds::OB_SQL_EXECUTOR, ObCtxIds::DEFAULT_CTX_ID)
.set_properties(lib::USE_TL_PAGE_OPTIONAL)
.set_page_size(OB_MALLOC_BIG_BLOCK_SIZE);
CREATE_WITH_TEMP_CONTEXT(param)
{
ObIAllocator& tmp_allocator = CURRENT_CONTEXT.get_arena_allocator();
ObPhysicalPlanCtx phy_plan_ctx(tmp_allocator);
for (int i = 0; OB_SUCC(ret) && i < params.count(); i++) {
if (OB_FAIL(phy_plan_ctx.get_param_store_for_update().push_back(params.at(i)))) {
LOG_WARN("failed to push back element", K(ret));
}
} // end for
if (OB_FAIL(ret)) {
// do nothing
} else if (OB_FAIL(phy_plan_ctx.init_datum_param_store())) {
LOG_WARN("failed to init datum param store", K(ret));
} else {
ObExecContext exec_ctx(tmp_allocator);
exec_ctx.set_my_session(session);
exec_ctx.set_physical_plan_ctx(&phy_plan_ctx);
void* frame_buf = NULL;
ObPreCalcExprFrameInfo* pre_calc_frame = NULL;
ObStaticEngineExprCG expr_cg(tmp_allocator, &phy_plan_ctx.get_datum_param_store());
ObRawExpr* copied_expr = NULL;
ObRawExprFactory expr_factory(tmp_allocator);
int org_obj_cnt = phy_plan_ctx.get_param_store().count();
if (OB_FAIL(ObRawExprUtils::copy_expr(expr_factory, expr, copied_expr, COPY_REF_DEFAULT))) {
LOG_WARN("failed to copy raw expr", K(ret));
} else if (OB_ISNULL(copied_expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected null expr", K(ret), K(copied_expr));
} else if (OB_ISNULL(frame_buf = tmp_allocator.alloc(sizeof(ObPreCalcExprFrameInfo)))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("failed to allocate memory", K(ret));
} else {
pre_calc_frame = new (frame_buf) ObPreCalcExprFrameInfo(tmp_allocator);
expr_cg.init_operator_cg_ctx(&exec_ctx);
if (OB_FAIL(expr_cg.generate_calculable_expr(copied_expr, *pre_calc_frame))) {
LOG_WARN("failed to generate calculable expr", K(ret));
// set current time before do pre calculation
} else if (FALSE_IT(phy_plan_ctx.set_cur_time(ObTimeUtility::current_time(), *session))) {
// do nothing
} else if (OB_FAIL(ObCacheObject::pre_calculation(false, *pre_calc_frame, exec_ctx))) {
LOG_WARN("failed to pre calculate", K(ret));
} else if (OB_UNLIKELY(org_obj_cnt + 1 != phy_plan_ctx.get_param_store().count())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unpected param store", K(phy_plan_ctx.get_param_store()), K(org_obj_cnt));
} else if (OB_FAIL(deep_copy_obj(allocator, phy_plan_ctx.get_param_store().at(org_obj_cnt), result))) {
LOG_WARN("failed to deep copy obj", K(ret));
} else {
// do nothing
}
}
}
}
return ret;
}
int ObSQLUtils::convert_calculable_expr_to_question_mark(ObDMLStmt& stmt, ObRawExpr*& expr, ObTransformerCtx& ctx)
{
int ret = OB_SUCCESS;
int64_t old_idx = stmt.get_calculable_exprs().count();
int64_t old_pre_param_size = stmt.get_pre_param_size();
ObSEArray<ObHiddenColumnItem, 4> calculable_exprs;
if (OB_ISNULL(ctx.exec_ctx_) || OB_ISNULL(ctx.phy_plan_) || OB_ISNULL(ctx.expr_factory_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("NULL param", K(ret), K(ctx.exec_ctx_), K(ctx.phy_plan_));
} else {
ObRawExprPrecalcAnalyzer pre_calc_analyzer(*ctx.expr_factory_, ctx.exec_ctx_->get_my_session());
if (OB_FAIL(pre_calc_analyzer.analyze_expr_tree(expr, stmt))) {
LOG_WARN("analyze stmt all expr failed", K(ret));
}
}
// pre calculable
if (OB_FAIL(ret)) {
} else if (OB_FAIL(extract_calc_exprs(stmt, expr, old_idx, old_pre_param_size, calculable_exprs))) {
LOG_WARN("failed to extract calc exprs", K(ret));
} else if (OB_FAIL(ObSql::calc_pre_calculable_exprs(calculable_exprs, *ctx.exec_ctx_, stmt, *ctx.phy_plan_))) {
LOG_WARN("Failed to calc_pre_calculable_exprs", K(ret));
}
return ret;
}
int ObSQLUtils::extract_calc_exprs(ObDMLStmt& stmt, ObRawExpr* expr, int64_t old_idx, int64_t old_pre_param_size,
ObIArray<ObHiddenColumnItem>& calc_exprs)
{
int ret = OB_SUCCESS;
ObSEArray<ObRawExpr*, 4> record_exprs;
bool is_need_adjust = false;
ObIArray<ObHiddenColumnItem>& stmt_calc_exprs = stmt.get_calculable_exprs();
if (OB_UNLIKELY(old_idx > stmt_calc_exprs.count())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get invalid argument", K(ret), K(old_idx), K(stmt_calc_exprs.count()));
} else if (1 == stmt_calc_exprs.count() - old_idx) {
if (OB_FAIL(calc_exprs.push_back(stmt_calc_exprs.at(old_idx)))) {
LOG_WARN("Failed to push back calculable_exprs", K(ret));
} else { /*do nothing*/
}
} else if (stmt_calc_exprs.count() - old_idx > 1) {
if (OB_FAIL(recursively_extract_calc_exprs(
stmt_calc_exprs, expr, old_idx, old_pre_param_size, record_exprs, is_need_adjust, calc_exprs))) {
LOG_WARN("failed to recursively extract calc exprs", K(ret));
} else if (is_need_adjust) {
if (OB_UNLIKELY(calc_exprs.count() + old_idx != stmt_calc_exprs.count())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), K(stmt_calc_exprs.count()), K(calc_exprs.count() + old_idx));
} else {
for (int64_t i = 0; i < calc_exprs.count(); ++i) {
stmt.get_calculable_exprs().at(old_idx + i) = calc_exprs.at(i);
}
}
} else { /*do nothing*/
}
} else { /*do nothing*/
}
return ret;
}
int ObSQLUtils::recursively_extract_calc_exprs(ObIArray<ObHiddenColumnItem>& stmt_calc_exprs, ObRawExpr* expr,
int64_t old_idx, int64_t old_pre_param_size, ObIArray<ObRawExpr*>& record_exprs, bool& is_need_adjust,
ObIArray<ObHiddenColumnItem>& calc_exprs)
{
int ret = OB_SUCCESS;
bool is_stack_overflow = false;
if (OB_ISNULL(expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), K(expr));
} else if (OB_FAIL(check_stack_overflow(is_stack_overflow))) {
LOG_WARN("failed to check stack overflow", K(ret), K(is_stack_overflow));
} else if (is_stack_overflow) {
ret = OB_SIZE_OVERFLOW;
LOG_WARN("too deep recursive", K(ret), K(is_stack_overflow));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < expr->get_param_count(); ++i) {
ObRawExpr* param_expr = expr->get_param_expr(i);
if (OB_ISNULL(param_expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("failed to get unexpected null", K(ret), K(param_expr));
} else if (ObRawExprUtils::find_expr(record_exprs, param_expr)) {
/*do nothing*/
} else if (T_QUESTIONMARK == param_expr->get_expr_type()) {
int64_t idx = -1;
ObObj& question_value = static_cast<ObConstRawExpr*>(param_expr)->get_value();
if (OB_FAIL(question_value.get_unknown(idx))) {
LOG_WARN("failed to get unknown", K(ret));
} else if (-1 == idx || OB_UNLIKELY(idx - old_pre_param_size + old_idx >= stmt_calc_exprs.count())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get invalid argument", K(ret), K(idx - old_pre_param_size + old_idx), K(stmt_calc_exprs.count()));
} else if (idx < old_pre_param_size) {
/*do nothing*/
} else {
ObHiddenColumnItem& hidden_col = stmt_calc_exprs.at(idx - old_pre_param_size + old_idx);
int64_t old_calculable_exprs_size = calc_exprs.count();
if (OB_ISNULL(hidden_col.expr_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("failed to get unexpected null", K(ret), K(hidden_col.expr_));
} else if (OB_FAIL(SMART_CALL(recursively_extract_calc_exprs(stmt_calc_exprs,
hidden_col.expr_,
old_idx,
old_pre_param_size,
record_exprs,
is_need_adjust,
calc_exprs)))) {
LOG_WARN("failed to recursively extract calc exprs", K(ret));
} else if (old_calculable_exprs_size != calc_exprs.count() ||
idx != calc_exprs.count() + old_pre_param_size) {
hidden_col.hidden_idx_ = calc_exprs.count() + old_pre_param_size;
ObObjParam val;
val.set_unknown(hidden_col.hidden_idx_);
val.set_param_meta();
const ObExprResType result_type = param_expr->get_result_type();
static_cast<ObConstRawExpr*>(param_expr)->set_value(val);
param_expr->set_result_type(result_type);
if (OB_FAIL(calc_exprs.push_back(hidden_col))) {
LOG_WARN("failed to push back item", K(ret));
} else if (OB_FAIL(record_exprs.push_back(param_expr))) {
LOG_WARN("failed to push back item", K(ret));
} else {
is_need_adjust = true;
}
} else if (OB_FAIL(calc_exprs.push_back(hidden_col))) {
LOG_WARN("failed to push back item", K(ret));
} else if (OB_FAIL(record_exprs.push_back(param_expr))) {
LOG_WARN("failed to push back item", K(ret));
} else { /*do nothing*/
}
}
} else if (param_expr->has_flag(CNT_PARAM)) {
if (OB_FAIL(SMART_CALL(recursively_extract_calc_exprs(
stmt_calc_exprs, param_expr, old_idx, old_pre_param_size, record_exprs, is_need_adjust, calc_exprs)))) {
LOG_WARN("failed to recursively extract calc exprs", K(ret));
} else { /*do nothing*/
}
} else { /*do nothing*/
}
}
}
return ret;
}
int ObSQLUtils::make_generated_expression_from_str(const common::ObString& expr_str,
const share::schema::ObTableSchema& schema, const share::schema::ObColumnSchemaV2& gen_col,
const common::ObIArray<share::schema::ObColDesc>& col_ids, common::ObIAllocator& allocator,
common::ObISqlExpression*& expression)
{
int ret = OB_SUCCESS;
const bool make_column_expression = false; // return ObSqlExpression
ObSQLSessionInfo default_session;
if (OB_FAIL(default_session.init(0, 0, 0, &allocator))) {
LOG_WARN("init empty session failed", K(ret));
} else if (OB_FAIL(default_session.load_default_sys_variable(false, false))) {
LOG_WARN("session load default system variable failed", K(ret));
} else if (OB_FAIL(make_generated_expression_from_str(
expr_str, default_session, schema, gen_col, col_ids, allocator, expression, make_column_expression))) {
LOG_WARN("make generated expression failed", K(ret), K(expr_str));
}
return ret;
}
int ObSQLUtils::make_generated_expression_from_str(const common::ObString& expr_str, ObSQLSessionInfo& session,
const share::schema::ObTableSchema& schema, const share::schema::ObColumnSchemaV2& gen_col,
const common::ObIArray<share::schema::ObColDesc>& col_ids, common::ObIAllocator& allocator,
common::ObISqlExpression*& expression, const bool make_column_expression)
{
int ret = OB_SUCCESS;
ObRawExprFactory expr_factory(allocator);
ObRawExpr* expr = NULL;
RowDesc row_desc;
ObArray<ObQualifiedName> columns;
if (OB_FAIL(ObRawExprUtils::build_generated_column_expr(expr_str, expr_factory, session, expr, columns))) {
LOG_WARN("get generated column expr failed", K(ret));
} else if (OB_ISNULL(expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("expr is null");
} else if (OB_FAIL(row_desc.init())) {
LOG_WARN("Failed to init row desc", K(ret));
} else {
// create row_desc
for (int64_t i = 0; OB_SUCC(ret) && i < col_ids.count(); ++i) {
ObColumnRefRawExpr* col_ref = NULL;
const ObColumnSchemaV2* col_schema = NULL;
if (OB_ISNULL(col_schema = schema.get_column_schema(col_ids.at(i).col_id_))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get column schema failed", K_(col_ids.at(i).col_id));
} else if (OB_FAIL(ObRawExprUtils::build_column_expr(expr_factory, *col_schema, col_ref))) {
LOG_WARN("build column expr failed", K(ret));
} else if (OB_FAIL(row_desc.add_column(col_ref))) {
LOG_WARN("add column to row desc failed", K(ret));
} else { /*do nothing*/
}
for (int64_t j = 0; OB_SUCC(ret) && j < columns.count(); ++j) {
ObQualifiedName& q_name = columns.at(j);
if (!q_name.database_name_.empty() || !q_name.tbl_name_.empty()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("expr is not based on single table", K(q_name));
} else if (ObCharset::case_insensitive_equal(q_name.col_name_, col_schema->get_column_name_str())) {
if (OB_FAIL(ObRawExprUtils::replace_ref_column(expr, q_name.ref_expr_, col_ref))) {
LOG_WARN("replace reference column failed", K(ret));
}
} else { /*do nothing*/
}
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(expr->formalize(&session))) {
LOG_WARN("formalize expression failed", K(ret));
}
}
if (OB_SUCC(ret)) {
ObExprResType dest_type;
dest_type.set_meta(gen_col.get_meta_type());
dest_type.set_accuracy(gen_col.get_accuracy());
if (ObRawExprUtils::need_column_conv(dest_type, *expr)) {
if (OB_FAIL(ObRawExprUtils::build_column_conv_expr(expr_factory, &gen_col, expr, &session))) {
LOG_WARN("create column convert expr failed", K(ret));
}
}
}
if (OB_SUCC(ret)) {
ObSqlExpressionFactory sql_expression_factory(allocator);
ObExprOperatorFactory expr_op_factory(allocator);
ObExprGeneratorImpl expr_gen(expr_op_factory, 0, 0, NULL, row_desc);
ObSqlExpression* sql_expr = NULL;
ObColumnExpression* col_expr = NULL;
if (!make_column_expression) {
if (OB_FAIL(sql_expression_factory.alloc(sql_expr))) {
LOG_WARN("alloc sql expression failed", K(ret));
}
} else {
if (OB_FAIL(sql_expression_factory.alloc(col_expr))) {
LOG_WARN("alloc column expression failed", K(ret));
} else {
sql_expr = col_expr;
}
}
if (OB_FAIL(ret)) {
} else if (OB_UNLIKELY(NULL == sql_expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("Failed to alloc sql expression", K(ret));
} else if (OB_FAIL(expr_gen.generate(*expr, *sql_expr))) {
LOG_WARN("fail to fill sql expression", K(ret));
} else {
expression = sql_expr;
}
}
}
return ret;
}
int ObSQLUtils::make_default_expr_context(ObIAllocator& allocator, ObExprCtx& expr_ctx)
{
int ret = OB_SUCCESS;
ObSQLSessionInfo* default_session = static_cast<ObSQLSessionInfo*>(allocator.alloc(sizeof(ObSQLSessionInfo)));
if (OB_ISNULL(default_session)) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("allocate memory failed", K(ret));
} else {
default_session = new (default_session) ObSQLSessionInfo();
if (OB_FAIL(default_session->init(0, 0, 0, &allocator))) {
LOG_WARN("init default session failed", K(ret));
} else if (OB_FAIL(default_session->load_default_sys_variable(false, false))) {
LOG_WARN("load default system variable to session failed", K(ret));
} else {
expr_ctx.my_session_ = default_session;
}
}
if (OB_SUCC(ret)) {
ObPhysicalPlanCtx* phy_plan_ctx = static_cast<ObPhysicalPlanCtx*>(allocator.alloc(sizeof(ObPhysicalPlanCtx)));
if (OB_ISNULL(phy_plan_ctx)) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("allocate memory failed", K(ret));
} else {
phy_plan_ctx = new (phy_plan_ctx) ObPhysicalPlanCtx(allocator);
expr_ctx.phy_plan_ctx_ = phy_plan_ctx;
}
}
if (OB_SUCC(ret)) {
ObPhysicalPlan* phy_plan = static_cast<ObPhysicalPlan*>(allocator.alloc(sizeof(ObPhysicalPlan)));
if (OB_ISNULL(phy_plan)) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("allocate memory failed", K(ret));
} else {
phy_plan = new (phy_plan) ObPhysicalPlan();
expr_ctx.phy_plan_ctx_->set_phy_plan(phy_plan);
}
}
if (OB_SUCC(ret)) {
ObExecContext* exec_ctx = static_cast<ObExecContext*>(allocator.alloc(sizeof(ObExecContext)));
if (OB_ISNULL(exec_ctx)) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("allocate memory failed", K(ret));
} else {
exec_ctx = new (exec_ctx) ObExecContext();
expr_ctx.exec_ctx_ = exec_ctx;
}
}
if (OB_SUCC(ret)) {
expr_ctx.calc_buf_ = &allocator;
}
if (OB_SUCC(ret)) {
if (OB_FAIL(wrap_column_convert_ctx(expr_ctx, expr_ctx.column_conv_ctx_))) {
LOG_WARN("wrap column convert ctx failed", K(ret));
}
}