forked from oceanbase/oceanbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathob_query_range.cpp
More file actions
5117 lines (4951 loc) · 201 KB
/
ob_query_range.cpp
File metadata and controls
5117 lines (4951 loc) · 201 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_REWRITE
#include "lib/timezone/ob_time_convert.h"
#include "lib/container/ob_array_serialization.h"
#include "sql/resolver/dml/ob_dml_stmt.h"
#include "sql/rewrite/ob_query_range.h"
#include "sql/engine/expr/ob_expr_result_type_util.h"
#include "sql/engine/expr/ob_expr_like.h"
#include "common/ob_smart_call.h"
#include "sql/optimizer/ob_optimizer_util.h"
// if cnd is true get full range key part which is always true
// else, get empty key part which is always false
#define GET_ALWAYS_TRUE_OR_FALSE(cnd, out_key_part) \
do { \
if (OB_SUCC(ret)) { \
query_range_ctx_->cur_expr_is_precise_ = false; \
if (OB_ISNULL(table_graph_.key_part_head_)) { \
ret = OB_ERR_NULL_VALUE; \
LOG_WARN("Can not find key_part"); \
} else if (cnd) { \
if (OB_FAIL(alloc_full_key_part(out_key_part))) { \
LOG_WARN("alloc_full_key_part failed", K(ret)); \
} else { \
out_key_part->id_ = table_graph_.key_part_head_->id_; \
out_key_part->pos_ = table_graph_.key_part_head_->pos_; \
} \
} else { \
if (OB_FAIL(alloc_empty_key_part(out_key_part))) { \
LOG_WARN("alloc_empty_key_part failed", K(ret)); \
} else if (OB_ISNULL(out_key_part)) { \
ret = OB_ALLOCATE_MEMORY_FAILED; \
LOG_ERROR("out_key_part is null.", K(ret)); \
} else { \
out_key_part->id_ = table_graph_.key_part_head_->id_; \
out_key_part->pos_ = table_graph_.key_part_head_->pos_; \
} \
} \
} \
} while (0)
namespace oceanbase {
using namespace common;
using namespace share::schema;
namespace sql {
ObQueryRange::ObQueryRange()
: state_(NEED_INIT),
column_count_(0),
contain_row_(false),
inner_allocator_(ObModIds::OB_SQL_QUERY_RANGE),
allocator_(inner_allocator_),
query_range_ctx_(NULL),
key_part_store_(allocator_),
range_exprs_(allocator_),
param_indexs_(allocator_)
{}
ObQueryRange::ObQueryRange(ObIAllocator& alloc)
: state_(NEED_INIT),
column_count_(0),
contain_row_(false),
inner_allocator_(ObModIds::OB_SQL_QUERY_RANGE),
allocator_(alloc),
query_range_ctx_(NULL),
key_part_store_(allocator_),
range_exprs_(allocator_),
param_indexs_(allocator_)
{}
ObQueryRange::~ObQueryRange()
{
reset();
}
ObQueryRange& ObQueryRange::operator=(const ObQueryRange& other)
{
if (this != &other) {
reset();
deep_copy(other);
}
return *this;
}
void ObQueryRange::reset()
{
DLIST_FOREACH_NORET(node, key_part_store_.get_obj_list())
{
if (node != NULL && node->get_obj() != NULL) {
node->get_obj()->~ObKeyPart();
}
}
key_part_store_.destory();
query_range_ctx_ = NULL;
state_ = NEED_INIT;
column_count_ = 0;
contain_row_ = false;
table_graph_.reset();
range_exprs_.reset();
inner_allocator_.reset();
param_indexs_.reset();
}
int ObQueryRange::init_query_range_ctx(
ObIAllocator& allocator, const ColumnIArray& range_columns, const ParamsIArray* params)
{
int ret = OB_SUCCESS;
void* ptr = NULL;
uint64_t table_id = OB_INVALID_ID;
if (range_columns.count() <= 0) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("range column array is empty");
} else if (OB_ISNULL(ptr = allocator.alloc(sizeof(ObQueryRangeCtx)))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("alloc query range context failed");
} else {
query_range_ctx_ = new (ptr) ObQueryRangeCtx(params);
}
for (int64_t i = 0; OB_SUCC(ret) && i < range_columns.count(); ++i) {
const ColumnItem& col = range_columns.at(i);
if (OB_UNLIKELY(col.is_invalid())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("column item is invalid", K_(col.expr));
} else {
ObKeyPartId key_part_id(col.table_id_, col.column_id_);
const ObExprResType* expr_res_type = col.get_column_type();
if (OB_ISNULL(expr_res_type)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("expr result type is null", K(ret));
} else {
ObExprResType tmp_expr_type = *expr_res_type;
if (tmp_expr_type.is_lob_locator()) {
tmp_expr_type.set_type(ObLongTextType);
}
ObKeyPartPos key_part_pos(i, tmp_expr_type);
table_id = (i > 0 ? table_id : col.table_id_);
if (OB_UNLIKELY(table_id != col.table_id_)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("range columns must have the same table id", K(table_id), K_(col.table_id));
} else if (OB_FAIL(key_part_pos.set_enum_set_values(allocator_, col.expr_->get_enum_set_values()))) {
LOG_WARN("fail to set values", K(key_part_pos), K(ret));
} else if (OB_FAIL(query_range_ctx_->key_part_map_.set_refactored(key_part_id, key_part_pos))) {
LOG_WARN("set key part map failed", K(ret), K(key_part_id));
}
}
}
}
if (OB_SUCC(ret)) {
// Add the default range of the index and remember the count of the rowkeys.
// Just to handle the full range case
// E.g.
// select * from t where true;
ObKeyPart* full_key_part = NULL;
if (OB_FAIL(alloc_full_key_part(full_key_part))) {
LOG_WARN("alloc_full_key_part failed", K(ret));
} else if (OB_ISNULL(full_key_part)) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("full_key_part is null.", K(ret));
} else {
full_key_part->id_ = ObKeyPartId(table_id, OB_INVALID_ID);
full_key_part->pos_ = ObKeyPartPos(allocator_, -1);
table_graph_.key_part_head_ = full_key_part;
column_count_ = range_columns.count();
}
}
if (OB_SUCCESS != ret && NULL != query_range_ctx_) {
destroy_query_range_ctx(allocator);
}
return ret;
}
void ObQueryRange::destroy_query_range_ctx(ObIAllocator& ctx_allocator)
{
if (NULL != query_range_ctx_) {
query_range_ctx_->~ObQueryRangeCtx();
ctx_allocator.free(query_range_ctx_);
query_range_ctx_ = NULL;
}
}
int ObQueryRange::preliminary_extract_query_range(const ColumnIArray& range_columns, const ObRawExpr* expr_root,
const ObDataTypeCastParams& dtc_params, const ParamsIArray* params /* = NULL */)
{
int ret = OB_SUCCESS;
ObArenaAllocator ctx_allocator(ObModIds::OB_QUERY_RANGE_CTX);
if (OB_FAIL(init_query_range_ctx(ctx_allocator, range_columns, params))) {
LOG_WARN("init query range context failed", K(ret));
} else if (OB_ISNULL(query_range_ctx_)) {
ret = OB_NOT_INIT;
LOG_WARN("query_range_ctx_ is not inited.", K(ret));
} else {
query_range_ctx_->need_final_extact_ = false;
ObKeyPart* root = NULL;
if (OB_UNLIKELY(NULL == expr_root)) {
//(MIN, MAX), whole range
GET_ALWAYS_TRUE_OR_FALSE(true, root);
} else {
if (OB_FAIL(preliminary_extract(expr_root, root, dtc_params, T_OP_IN == expr_root->get_expr_type()))) {
LOG_WARN("gen table range failed", K(ret));
} else if (query_range_ctx_->cur_expr_is_precise_ && root != NULL) {
// for simple in_expr
int64_t max_pos = -1;
bool is_strict_equal = true;
if (OB_FAIL(is_strict_equal_graph(root, 0, max_pos, is_strict_equal))) {
LOG_WARN("is strict equal graph failed", K(ret));
} else if (is_strict_equal) {
ObRangeExprItem expr_item;
expr_item.cur_expr_ = expr_root;
for (const ObKeyPart* cur_and = root; OB_SUCC(ret) && cur_and != NULL; cur_and = cur_and->and_next_) {
if (OB_FAIL(expr_item.cur_pos_.push_back(cur_and->pos_.offset_))) {
LOG_WARN("push back pos offset failed", K(ret));
}
}
if (OB_SUCC(ret) && OB_FAIL(query_range_ctx_->precise_range_exprs_.push_back(expr_item))) {
LOG_WARN("store precise range exprs failed", K(ret));
}
} else if (NULL == root->and_next_ && is_general_graph(*root)) {
// Because the optimizer can only remove the top filter,
// and the goal of remove filter is to extract conjunctive paradigm
// the standard conjunctive normal form such as (c1>1 or c1<0) and c2=1 expressions
// must be split into multiple expressions in the resolver
// if there is no split, such expressions cannot be removed,
// because the removed expression must be a complete expression every time
ObRangeExprItem expr_item;
expr_item.cur_expr_ = expr_root;
if (OB_FAIL(expr_item.cur_pos_.push_back(root->pos_.offset_))) {
LOG_WARN("push back pos offset failed", K(ret));
} else if (OB_FAIL(query_range_ctx_->precise_range_exprs_.push_back(expr_item))) {
LOG_WARN("store precise range exprs failed", K(ret));
}
}
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(normalize_range_graph(root))) {
LOG_WARN("normalize range graph failed", K(ret));
}
}
if (OB_SUCC(ret) && root != NULL) {
SQL_REWRITE_LOG(DEBUG, "root key part", K(*root));
int64_t max_pos = -1;
table_graph_.key_part_head_ = root;
table_graph_.is_standard_range_ = is_standard_graph(root);
OZ(is_strict_equal_graph(root, 0, max_pos, table_graph_.is_equal_range_));
OZ(check_graph_type());
}
}
if (OB_SUCC(ret)) {
if (query_range_ctx_->need_final_extact_) {
state_ = NEED_PREPARE_PARAMS;
} else {
state_ = CAN_READ;
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(param_indexs_.assign(query_range_ctx_->param_indexs_))) {
LOG_WARN("assign param indexs failed", K(ret), K(query_range_ctx_->param_indexs_));
}
}
destroy_query_range_ctx(ctx_allocator);
return ret;
}
int ObQueryRange::preliminary_extract_query_range(const ColumnIArray& range_columns, const ExprIArray& root_exprs,
const ObDataTypeCastParams& dtc_params, const ParamsIArray* params /* = NULL */)
{
int ret = OB_SUCCESS;
ObKeyPartList and_ranges;
ObKeyPart* temp_result = NULL;
SQL_REWRITE_LOG(DEBUG, "preliminary extract", K(range_columns), K(root_exprs));
ObArenaAllocator ctx_allocator(ObModIds::OB_QUERY_RANGE_CTX);
if (OB_FAIL(init_query_range_ctx(ctx_allocator, range_columns, params))) {
LOG_WARN("init query range context failed", K(ret));
} else if (OB_ISNULL(query_range_ctx_)) {
ret = OB_NOT_INIT;
LOG_WARN("query_range_ctx_ is not inited.", K(ret));
} else {
if (OB_LIKELY(root_exprs.count() > 0)) {
for (int64_t j = 0; OB_SUCC(ret) && j < root_exprs.count(); ++j) {
if (NULL == root_exprs.at(j)) {
// continue
} else if (OB_FAIL(preliminary_extract(
root_exprs.at(j), temp_result, dtc_params, T_OP_IN == root_exprs.at(j)->get_expr_type()))) {
LOG_WARN("Generate table range failed", K(ret));
} else if (NULL == temp_result) {
// ignore the condition from which we can not extract key part range
} else if (!and_ranges.add_last(temp_result)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("Add key part range failed", K(ret));
} else if (query_range_ctx_->cur_expr_is_precise_ && temp_result != NULL) {
if (is_strict_in_graph(temp_result)) {
ObRangeExprItem expr_item;
expr_item.cur_expr_ = root_exprs.at(j);
for (const ObKeyPart* cur_and = temp_result; OB_SUCC(ret) && cur_and != NULL;
cur_and = cur_and->and_next_) {
if (OB_FAIL(expr_item.cur_pos_.push_back(cur_and->pos_.offset_))) {
LOG_WARN("push back pos offset failed", K(ret));
}
}
if (OB_SUCC(ret) && OB_FAIL(query_range_ctx_->precise_range_exprs_.push_back(expr_item))) {
LOG_WARN("store precise range exprs failed", K(ret));
}
} else if (NULL == temp_result->and_next_ && is_general_graph(*temp_result)) {
ObRangeExprItem expr_item;
expr_item.cur_expr_ = root_exprs.at(j);
if (OB_FAIL(expr_item.cur_pos_.push_back(temp_result->pos_.offset_))) {
LOG_WARN("push back pos offset failed", K(ret));
} else if (OB_FAIL(query_range_ctx_->precise_range_exprs_.push_back(expr_item))) {
LOG_WARN("store precise range exprs failed", K(ret));
}
}
}
} // for each where condition
} else {
GET_ALWAYS_TRUE_OR_FALSE(true, temp_result);
if (OB_SUCC(ret)) {
if (!and_ranges.add_last(temp_result)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("add key part range failed", K(ret));
}
}
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(and_range_graph(and_ranges, temp_result))) {
LOG_WARN("And query range failed", K(ret));
} else if (OB_FAIL(normalize_range_graph(temp_result))) {
LOG_WARN("normalize range graph failed", K(ret));
} else if (NULL == temp_result) {
// no range left
} else {
int64_t max_pos = -1;
table_graph_.key_part_head_ = temp_result;
table_graph_.is_standard_range_ = is_standard_graph(temp_result);
if (OB_FAIL(is_strict_equal_graph(temp_result, 0, max_pos, table_graph_.is_equal_range_))) {
LOG_WARN("is strict equal graph failed", K(ret));
} else if (OB_FAIL(check_graph_type())) {
LOG_WARN("check graph type failed", K(ret));
}
}
}
if (OB_SUCC(ret)) {
if (query_range_ctx_->need_final_extact_) {
state_ = NEED_PREPARE_PARAMS;
} else {
state_ = CAN_READ;
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(param_indexs_.assign(query_range_ctx_->param_indexs_))) {
LOG_WARN("assign param indexs failed", K(ret), K(query_range_ctx_->param_indexs_));
}
}
destroy_query_range_ctx(ctx_allocator);
return ret;
}
int ObQueryRange::is_get(bool& is_range_get) const
{
return is_get(column_count_, is_range_get);
}
int ObQueryRange::is_get(int64_t column_count, bool& is_range_get) const
{
int ret = OB_SUCCESS;
is_range_get = true;
if (table_graph_.is_precise_get_) {
// return true
} else if (NULL == table_graph_.key_part_head_) {
is_range_get = false;
} else if (OB_FAIL(check_is_get(*table_graph_.key_part_head_, 0, column_count, is_range_get))) {
LOG_WARN("failed to check is get", K(ret));
}
return ret;
}
int ObQueryRange::check_is_get(ObKeyPart& key_part, const int64_t depth, const int64_t column_count, bool& bret) const
{
int ret = OB_SUCCESS;
if (key_part.pos_.offset_ != depth || !key_part.is_equal_condition()) {
bret = false;
} else {
if (NULL != key_part.and_next_) {
ret = SMART_CALL(check_is_get(*key_part.and_next_, depth + 1, column_count, bret));
} else if (depth < column_count - 1) {
bret = false;
}
if (OB_SUCC(ret) && bret && NULL != key_part.or_next_) {
ret = SMART_CALL(check_is_get(*key_part.or_next_, depth, column_count, bret));
}
}
return ret;
}
int ObQueryRange::check_graph_type()
{
int ret = OB_SUCCESS;
table_graph_.is_precise_get_ = true;
if (OB_ISNULL(query_range_ctx_) || OB_ISNULL(table_graph_.key_part_head_)) {
ret = OB_NOT_INIT;
LOG_WARN("query isn't init", K_(query_range_ctx), K_(table_graph_.key_part_head));
}
if (OB_SUCC(ret)) {
int64_t depth = -1;
int64_t column_count = column_count_;
bool is_terminated = false;
for (ObKeyPart* cur = table_graph_.key_part_head_; !is_terminated && NULL != cur; cur = cur->and_next_) {
if (cur->pos_.offset_ != (++depth)) {
table_graph_.is_precise_get_ = false;
// there is a missing key, the missing key and the following keys are invalid
if (OB_FAIL(remove_precise_range_expr(depth))) {
LOG_WARN("remove precise range expr failed", K(ret));
}
is_terminated = true;
} else if (NULL != cur->or_next_ || NULL != cur->item_next_) {
table_graph_.is_precise_get_ = false;
} else if (cur->is_like_key()) {
table_graph_.is_precise_get_ = false;
} else if (!cur->is_equal_condition()) {
table_graph_.is_precise_get_ = false;
} else {
// do nothing
}
if (OB_SUCC(ret) && !is_terminated) {
if (is_strict_in_graph(cur)) {
// do nothing
} else if (!is_general_graph(*cur)) {
if (OB_FAIL(remove_precise_range_expr(cur->pos_.offset_ + 1))) {
LOG_WARN("remove precise range expr failed", K(ret));
}
is_terminated = true;
} else if (has_scan_key(*cur)) {
if (OB_FAIL(remove_precise_range_expr(cur->pos_.offset_ + 1))) {
LOG_WARN("remove precise range expr failed", K(ret));
}
is_terminated = true;
}
}
}
if (OB_SUCC(ret) && table_graph_.is_precise_get_ && depth != column_count - 1) {
table_graph_.is_precise_get_ = false;
}
}
if (OB_SUCC(ret) && OB_FAIL(range_exprs_.init(query_range_ctx_->precise_range_exprs_.count()))) {
LOG_WARN("init range exprs failed", K(ret));
}
for (int64_t i = 0; OB_SUCC(ret) && i < query_range_ctx_->precise_range_exprs_.count(); ++i) {
const ObRawExpr* cur_expr = query_range_ctx_->precise_range_exprs_.at(i).cur_expr_;
if (NULL != cur_expr) {
if (OB_FAIL(range_exprs_.push_back(const_cast<ObRawExpr*>(cur_expr)))) {
LOG_WARN("push back precise range expr failed", K(ret));
}
}
}
return ret;
}
// this function is used to determine
// whether the column type of the expression to be extracted is compatible with the comparison type of the expression,
// then judge whether the expression should be extracted accurately or enlarged to (min, max)
bool ObQueryRange::can_be_extract_range(ObItemType cmp_type, const ObExprResType& col_type,
const ObExprCalcType& calc_type, ObObjType data_type, bool& always_true)
{
bool bret = true;
always_true = true;
/**
* the prerequisite for determining whether an expression can use our extraction rules is
* whether the range of the collection after extraction is smaller than the value range expressed by the expression.
* for an expression(col compare const), the comparison type(calc_type) contain that a set A
* (the element data type is calc_type),
* the query range needs to find a set B (the element type is column_type) is included by A,
* in this way, the column range extracted by the query range can satisfy this expression.
* Set B is determined by query range through calc_type and column_type and expression extraction rules.
* the extraction rules must be one-to-one, whether it is type conversion or character set conversion.
* For example, int->varchar, 123 is converted to '123', not '0123',
* character set UTF8MB4_GENERAL_CI'A'->UTF8MB4_BIN'A' instead of UTF8MB4_BIN'a'.
* So to satisfy the expression relationship(col compare const),
* if column_type and calc_type are not compatible, need to convert the data type.
* This expression relationship can finally be summarized as: f1(col, calc_type) compare f2(const, calc_type)
* f1 means that the value of col is mapped from column_type to calc_type,
* so to discuss the relationship between set A and set B is to discuss the mapping relationship of f1.
* The factors that affect the range of the collection may be the type and character set,
* and the character set is meaningful only in the string type
* The first case:
* if the type of column_type is same with calc_type and the character set is also the same (if it is a string type),
* and then f1 is a one-to-one mapping relationship, that is set A = set B
* The second case:
* if the character set in column_type is a case-sensitive character set,
* and the character set in calc_type is a case-insensitive character set,
* then f1 is a one-to-many relationship.
* !f1 is a many-to-one relationship, such as general_ci'A'-> bin'a' or bin'A',
* then Set B extracted by the query range rule is included in Set A, which does not satisfy the assumption.
* So in this case, the range is (min, max).
* The third case:
* if column_type is a string type, and calc_type is a non-string type,
* because their collation and conversion rules are different, f1 is a many-to-one relationship,
* such as '0123'->123, '123'->123, then !f1 is a one-to-many relationship, which does not satisfy the assumption,
* so in this case the range is (min, max).
* The fourth case:
* if column_type is a numeric type, and calc_type is a string type,
* we can see from the third case that the mapping f1 from numeric type to string type is one-to-many relationship,
* so !f1 is a many-to-one relationship, and the extraction rule of query range is a one-to-one mapping relationship,
* any element a belonging to set A can uniquely determine a value b to make the expression true in set B,
* so the fourth case can also be extracted by extraction rules
* f1 in other cases is also a one-to-one mapping relationship, set A = set B,
* so the extraction rules can also be used
**/
if (T_OP_NSEQ == cmp_type && ObNullType == data_type) {
bret = true;
}
if (bret && T_OP_NSEQ != cmp_type && ObNullType == data_type) {
// pk cmp null
bret = false;
always_true = false;
}
if (bret && T_OP_LIKE == cmp_type) {
if ((!col_type.is_string_or_lob_locator_type()) || (!calc_type.is_string_or_lob_locator_type())) {
bret = false;
always_true = true;
}
}
if (bret) {
bool is_cast_monotonic = false;
int ret = OB_SUCCESS;
// because cast has special processing for certain value ranges of certain time types,
// resulting in A cast B, which is not necessarily reversible.
// an expression can be extracted, and it needs to be cast monotonous in both directions
if (OB_FAIL(ObObjCaster::is_cast_monotonic(col_type.get_type(), calc_type.get_type(), is_cast_monotonic))) {
LOG_WARN("check is cast monotonic failed", K(ret));
} else if (!is_cast_monotonic) {
bret = false;
always_true = true;
} else if (OB_FAIL(ObObjCaster::is_cast_monotonic(calc_type.get_type(), col_type.get_type(), is_cast_monotonic))) {
LOG_WARN("check is cast monotonic failed", K(ret));
} else if (!is_cast_monotonic) {
bret = false;
always_true = true;
} else if (calc_type.is_string_or_lob_locator_type() && col_type.is_string_or_lob_locator_type()) {
if (col_type.get_collation_type() != calc_type.get_collation_type()) {
bret = false;
always_true = true;
}
}
}
return bret;
}
int ObQueryRange::get_const_key_part(const ObRawExpr* l_expr, const ObRawExpr* r_expr, const ObRawExpr* escape_expr,
ObItemType cmp_type, const ObExprResType& result_type, ObKeyPart*& out_key_part,
const ObDataTypeCastParams& dtc_params)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(l_expr) || OB_ISNULL(r_expr) || (OB_ISNULL(escape_expr) && T_OP_LIKE == cmp_type)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument.", K(ret), KP(l_expr), KP(r_expr));
} else {
const ObConstRawExpr* l_const = static_cast<const ObConstRawExpr*>(l_expr);
const ObConstRawExpr* r_const = static_cast<const ObConstRawExpr*>(r_expr);
const ObExprCalcType& calc_type = result_type.get_calc_meta();
ObCollationType cmp_cs_type = calc_type.get_collation_type();
// '?' is const too, if " '?' cmp const ", we seem it as true now
if (l_expr->has_flag(IS_PARAM) || r_expr->has_flag(IS_PARAM)) {
GET_ALWAYS_TRUE_OR_FALSE(true, out_key_part);
} else if (l_const->get_value().is_null() || r_const->get_value().is_null()) {
if (l_const->get_value().is_null() && r_const->get_value().is_null() && T_OP_NSEQ == cmp_type) {
GET_ALWAYS_TRUE_OR_FALSE(true, out_key_part);
} else {
GET_ALWAYS_TRUE_OR_FALSE(false, out_key_part);
}
} else if (cmp_type >= T_OP_EQ && cmp_type <= T_OP_NE) {
ObObjType compare_type = ObMaxType;
int64_t eq_cmp = 0;
ObCastMode cast_mode = CM_WARN_ON_FAIL;
ObCastCtx cast_ctx(&allocator_, &dtc_params, cast_mode, cmp_cs_type);
if (OB_FAIL(ObExprResultTypeUtil::get_relational_cmp_type(
compare_type, l_const->get_value().get_type(), r_const->get_value().get_type()))) {
LOG_WARN("get compare type failed", K(ret));
} else if (OB_FAIL(ObRelationalExprOperator::compare_nullsafe(
eq_cmp, l_const->get_value(), r_const->get_value(), cast_ctx, compare_type, cmp_cs_type))) {
LOG_WARN("compare obj failed", K(ret));
} else if (T_OP_EQ == cmp_type || T_OP_NSEQ == cmp_type) {
GET_ALWAYS_TRUE_OR_FALSE(0 == eq_cmp, out_key_part);
} else if (T_OP_LE == cmp_type) {
GET_ALWAYS_TRUE_OR_FALSE(eq_cmp <= 0, out_key_part);
} else if (T_OP_LT == cmp_type) {
GET_ALWAYS_TRUE_OR_FALSE(eq_cmp < 0, out_key_part);
} else if (T_OP_GE == cmp_type) {
GET_ALWAYS_TRUE_OR_FALSE(eq_cmp >= 0, out_key_part);
} else if (T_OP_GT == cmp_type) {
GET_ALWAYS_TRUE_OR_FALSE(eq_cmp > 0, out_key_part);
} else {
GET_ALWAYS_TRUE_OR_FALSE(0 != eq_cmp, out_key_part);
}
} else if (T_OP_LIKE == cmp_type) {
if (!escape_expr->is_const_expr()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("escape_expr must be const expr", K(ret));
} else {
const ObConstRawExpr* const_escape = static_cast<const ObConstRawExpr*>(escape_expr);
if (OB_FAIL(get_like_const_range(l_const, r_const, const_escape, cmp_cs_type, out_key_part, dtc_params))) {
LOG_WARN("get like const range failed", K(ret));
}
}
} else {
// do nothing
}
}
return ret;
}
int ObQueryRange::get_column_key_part(const ObRawExpr* l_expr, const ObRawExpr* r_expr, const ObRawExpr* escape_expr,
ObItemType cmp_type, const ObExprResType& result_type, ObKeyPart*& out_key_part,
const ObDataTypeCastParams& dtc_params)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(l_expr) || OB_ISNULL(r_expr) || (OB_ISNULL(escape_expr) && T_OP_LIKE == cmp_type)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument.", K(ret), KP(l_expr), KP(r_expr), KP(cmp_type));
} else {
const ObColumnRefRawExpr* column_item = NULL;
const ObConstRawExpr* const_item = NULL;
const ObRawExpr* const_expr = NULL;
const ObExprCalcType& calc_type = result_type.get_calc_meta();
ObItemType c_type = cmp_type;
if (OB_UNLIKELY(r_expr->has_flag(IS_COLUMN))) {
column_item = static_cast<const ObColumnRefRawExpr*>(r_expr);
const_item = static_cast<const ObConstRawExpr*>(l_expr);
const_expr = l_expr;
c_type = (T_OP_LE == cmp_type
? T_OP_GE
: (T_OP_GE == cmp_type
? T_OP_LE
: (T_OP_LT == cmp_type ? T_OP_GT : (T_OP_GT == cmp_type ? T_OP_LT : cmp_type))));
} else if (l_expr->has_flag(IS_COLUMN)) {
column_item = static_cast<const ObColumnRefRawExpr*>(l_expr);
const_item = static_cast<const ObConstRawExpr*>(r_expr);
const_expr = r_expr;
c_type = cmp_type;
}
if (const_expr->has_flag(IS_PARAM)) {
if (T_OP_LIKE != c_type || NULL == query_range_ctx_->params_) {
// 1. non like condition
// 2. like condition and params_ is NULL
query_range_ctx_->need_final_extact_ = true;
} else {
// like condition and params_ NOT NULL
}
}
ObKeyPartId key_part_id(column_item->get_table_id(), column_item->get_column_id());
ObKeyPartPos key_part_pos(allocator_);
bool b_is_key_part = false;
bool always_true = true;
if (OB_FAIL(is_key_part(key_part_id, key_part_pos, b_is_key_part))) {
LOG_WARN("is_key_part failed", K(ret));
} else if (!b_is_key_part) {
GET_ALWAYS_TRUE_OR_FALSE(true, out_key_part);
} else if (!can_be_extract_range(cmp_type,
key_part_pos.column_type_,
calc_type,
const_expr->get_result_type().get_type(),
always_true)) {
GET_ALWAYS_TRUE_OR_FALSE(always_true, out_key_part);
} else if (OB_ISNULL((out_key_part = create_new_key_part()))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("alloc memory failed", K(ret));
} else {
ObObj val;
out_key_part->id_ = key_part_id;
out_key_part->pos_ = key_part_pos;
out_key_part->null_safe_ = (T_OP_NSEQ == c_type);
if (NULL != const_item) {
// none-ObConstRawExpr does not have value
val = const_item->get_value();
if (val.is_unknown()) {
if (T_OP_LIKE != c_type || NULL == query_range_ctx_->params_) {
// push down? no need to process it
if (!const_expr->has_flag(IS_EXEC_PARAM) &&
OB_FAIL(add_var_to_array_no_dup(query_range_ctx_->param_indexs_, val.get_unknown()))) {
LOG_WARN("store param index in query range context failed", K(ret), K(val));
}
} else if (OB_FAIL(get_param_value(val, *query_range_ctx_->params_))) {
LOG_WARN("failed to get param value", K(ret));
}
}
}
// if current expr can be extracted to range, just store the expr
if (OB_SUCC(ret)) {
if (c_type != T_OP_LIKE) {
if (OB_FAIL(get_normal_cmp_keypart(c_type, val, *out_key_part))) {
LOG_WARN("get normal cmp keypart failed", K(ret));
}
} else {
const ObConstRawExpr* const_escape = static_cast<const ObConstRawExpr*>(escape_expr);
if ((const_expr->has_flag(IS_PARAM) || escape_expr->has_flag(IS_PARAM)) &&
NULL == query_range_ctx_->params_) {
if (OB_FAIL(out_key_part->create_like_key())) {
LOG_WARN("create like key part failed", K(ret));
} else if (OB_FAIL(
ob_write_obj(allocator_, const_item->get_value(), out_key_part->like_keypart_->pattern_))) {
LOG_WARN("deep copy pattern obj failed", K(ret));
} else if (OB_FAIL(
ob_write_obj(allocator_, const_escape->get_value(), out_key_part->like_keypart_->escape_))) {
LOG_WARN("deep copy escape obj failed", K(ret));
}
} else {
ObObj escape_val = const_escape->get_value();
if (escape_val.is_unknown() && OB_ISNULL(query_range_ctx_->params_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else if (escape_val.is_unknown() && OB_FAIL(get_param_value(val, *query_range_ctx_->params_))) {
LOG_WARN("failed to get param value", K(ret));
} else if (OB_FAIL(get_like_range(val, escape_val, *out_key_part, dtc_params))) {
LOG_WARN("get like range failed", K(ret));
}
}
}
if (OB_SUCC(ret) && out_key_part->is_normal_key() && !out_key_part->is_question_mark()) {
if (OB_FAIL(out_key_part->cast_value_type(dtc_params, contain_row_))) {
LOG_WARN("cast keypart value type failed", K(ret));
} else {
// do nothing
}
}
if (OB_SUCC(ret) && key_part_pos.column_type_.is_string_type() && calc_type.is_string_type()) {
if (CS_TYPE_UTF8MB4_GENERAL_CI == key_part_pos.column_type_.get_collation_type() &&
CS_TYPE_UTF8MB4_GENERAL_CI != calc_type.get_collation_type()) {
// in this case, unify the character set into the character set of the target column,
// use general ci to compare, because the character set of calc type is general bin
// Because the general bin is converted to general ci, there is many-to-one,
// so the obtained range may be enlarged, not an accurate range
query_range_ctx_->cur_expr_is_precise_ = false;
}
}
if (OB_SUCC(ret) && is_oracle_mode() && out_key_part->is_normal_key() && NULL != const_expr) {
// c1 char(5), c2 varchar(5) for the value'abc', c1 ='abc', c2 ='abc'
//'abc' in oracle mode !='abc', but c1 = cast('abc' as varchar2(5))
// The range (abc; abc) will be extracted,
// because the storage layer stores strings without padding spaces,
// so this range will cause'abc'
// was selected, so this range is not an accurate range
ObObjType column_type = key_part_pos.column_type_.get_type();
ObObjType const_type = const_expr->get_result_type().get_type();
if ((ObCharType == column_type && ObVarcharType == const_type) ||
(ObNCharType == column_type && ObNVarchar2Type == const_type)) {
query_range_ctx_->cur_expr_is_precise_ = false;
}
}
}
}
}
return ret;
}
int ObQueryRange::get_normal_cmp_keypart(ObItemType cmp_type, const ObObj& val, ObKeyPart& out_keypart) const
{
int ret = OB_SUCCESS;
// precise range expr
if (OB_ISNULL(query_range_ctx_)) {
ret = OB_NOT_INIT;
LOG_WARN("query range context is null");
} else if (OB_FAIL(out_keypart.create_normal_key())) {
LOG_WARN("create normal key failed", K(ret));
} else if (OB_ISNULL(out_keypart.normal_keypart_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("normal keypart is null");
} else if (T_OP_EQ == cmp_type || T_OP_NSEQ == cmp_type) {
out_keypart.normal_keypart_->include_start_ = true;
out_keypart.normal_keypart_->include_end_ = true;
if (share::is_mysql_mode() &&
(out_keypart.pos_.column_type_.is_datetime() || out_keypart.pos_.column_type_.is_date()) &&
out_keypart.pos_.column_type_.is_not_null() && T_OP_NSEQ == cmp_type && val.is_null()) {
ObObj tmp_val;
tmp_val.set_meta_type(out_keypart.pos_.column_type_);
if (out_keypart.pos_.column_type_.is_datetime()) {
tmp_val.set_datetime(ObTimeConverter::ZERO_DATETIME);
} else if (out_keypart.pos_.column_type_.is_date()) {
tmp_val.set_date(ObTimeConverter::ZERO_DATE);
}
out_keypart.normal_keypart_->start_ = tmp_val;
out_keypart.normal_keypart_->end_ = tmp_val;
} else {
// normal action
out_keypart.normal_keypart_->start_ = val;
out_keypart.normal_keypart_->end_ = val;
}
} else if (T_OP_LE == cmp_type || T_OP_LT == cmp_type) {
// index order in storage is, Null is greater than min, less than the value of any meaningful
// c1 < val doesn't contain Null -> (NULL, val)
if (share::is_oracle_mode()) {
out_keypart.normal_keypart_->start_.set_min_value();
} else {
out_keypart.normal_keypart_->start_.set_null();
}
out_keypart.normal_keypart_->end_ = val;
out_keypart.normal_keypart_->include_start_ = false;
out_keypart.normal_keypart_->include_end_ = (T_OP_LE == cmp_type);
} else if (T_OP_GE == cmp_type || T_OP_GT == cmp_type) {
out_keypart.normal_keypart_->start_ = val;
if (share::is_oracle_mode()) {
out_keypart.normal_keypart_->end_.set_null();
} else {
out_keypart.normal_keypart_->end_.set_max_value();
}
out_keypart.normal_keypart_->include_start_ = (T_OP_GE == cmp_type);
out_keypart.normal_keypart_->include_end_ = false;
}
if (OB_SUCC(ret)) {
query_range_ctx_->cur_expr_is_precise_ = true;
out_keypart.normal_keypart_->always_false_ = false;
out_keypart.normal_keypart_->always_true_ = false;
}
return ret;
}
int ObQueryRange::get_row_key_part(const ObRawExpr* l_expr, const ObRawExpr* r_expr, ObItemType cmp_type,
const ObExprResType& result_type, ObKeyPart*& out_key_part, const ObDataTypeCastParams& dtc_params)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(l_expr) || OB_ISNULL(r_expr) || OB_ISNULL(query_range_ctx_)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument.", KP(l_expr), KP(r_expr), K_(query_range_ctx));
} else {
bool row_is_precise = true;
if (T_OP_EQ != cmp_type) {
contain_row_ = true;
row_is_precise = false;
}
ObKeyPartList key_part_list;
ObKeyPart* row_tail = out_key_part;
// resolver makes sure the syntax right, so we don't concern whether the numbers of row are equal
const ObOpRawExpr* l_row = static_cast<const ObOpRawExpr*>(l_expr);
const ObOpRawExpr* r_row = static_cast<const ObOpRawExpr*>(r_expr);
int64_t num = 0;
num = l_row->get_param_count() <= r_row->get_param_count() ? l_row->get_param_count() : r_row->get_param_count();
ObItemType c_type = T_INVALID;
switch (cmp_type) {
case T_OP_LT:
case T_OP_LE:
c_type = T_OP_LE;
break;
case T_OP_GT:
case T_OP_GE:
c_type = T_OP_GE;
break;
default:
// Other compare types are passed on without changes.
// In the vector, the processing logic of T_OP_EQ and T_OP_NSEQ is the same as that of ordinary conditions.
// T_OP_NE extracting range is meaningless,
// and the compare type cannot be changed,
// so that the lower layer can judge and ignore such row compare
// The compare type of the subquery also passes the original compare type,
// so that the lower-level judgment interface can ignore the compare expression of the subquery
c_type = cmp_type;
break;
}
bool b_flag = false;
ObArenaAllocator alloc;
ObExprResType res_type(alloc);
ObKeyPart* tmp_key_part = NULL;
for (int i = 0; OB_SUCC(ret) && !b_flag && i < num; ++i) {
res_type.set_calc_meta(result_type.get_row_calc_cmp_types().at(i));
tmp_key_part = NULL;
if (OB_FAIL(get_basic_query_range(l_row->get_param_expr(i),
r_row->get_param_expr(i),
NULL,
i < num - 1 ? c_type : cmp_type,
res_type,
tmp_key_part,
dtc_params))) {
LOG_WARN("Get basic query key part failed", K(ret), K(*l_row), K(*r_row), K(c_type));
} else if (T_OP_ROW == l_row->get_param_expr(i)->get_expr_type() ||
T_OP_ROW == r_row->get_param_expr(i)->get_expr_type()) {
// ((a,b),(c,d)) = (((1,2),(2,3)),((1,2),(2,3)))
row_is_precise = false;
} else if (T_OP_EQ == cmp_type || T_OP_NSEQ == cmp_type) {
row_is_precise = (row_is_precise && query_range_ctx_->cur_expr_is_precise_);
if (OB_FAIL(add_and_item(key_part_list, tmp_key_part))) {
LOG_WARN("Add basic query key part failed", K(ret));
} else if (num - 1 == i) {
if (OB_FAIL(and_range_graph(key_part_list, out_key_part))) {
LOG_WARN("and basic query key part failed", K(ret));
} else {
b_flag = true;
}
}
} else if (OB_FAIL(add_row_item(row_tail, tmp_key_part))) {
LOG_WARN("Add basic query key part failed", K(ret));
} else {
if (NULL == out_key_part) {
out_key_part = tmp_key_part;
}
if (NULL == tmp_key_part || tmp_key_part->is_always_false()) {
// when find false key part, then no need to do next
// E.g. (10, c1) > (5, 0)
if (NULL == out_key_part) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("out_key_part is null", K(ret));
}
b_flag = true; // break
} else {
row_tail = tmp_key_part;
}
}
}
if (OB_SUCC(ret)) {
query_range_ctx_->cur_expr_is_precise_ = row_is_precise;
}
}
return ret;
}
// Get range from basic compare expression, like 'col >= 30', 'row(c1, c2) > row(1, 2)'
// if this compare expression is not kinds of that we can use,
// return alway true key part, because it may be in OR expression
// E.g.
// case 1:
// key1 > 0 and (key2 < 5 or not_key3 >0)
// currently, we get range from 'not_key3 >0', if we do not generate always true key part for it,
// the result of (key2 < 5 or not_key3 >0) will be 'key2 belongs (min, 5)'
// case 2:
// key1 > 0 and (key2 < 5 or key1+key2 >0)
// case 3:
// key1 > 0 and (key2 < 5 or func(key1) >0)
int ObQueryRange::get_basic_query_range(const ObRawExpr* l_expr, const ObRawExpr* r_expr, const ObRawExpr* escape_expr,
ObItemType cmp_type, const ObExprResType& result_type, ObKeyPart*& out_key_part,
const ObDataTypeCastParams& dtc_params)
{
int ret = OB_SUCCESS;
out_key_part = NULL;
if (OB_ISNULL(query_range_ctx_) || OB_ISNULL(l_expr) || OB_ISNULL(r_expr) ||
(OB_ISNULL(escape_expr) && T_OP_LIKE == cmp_type)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("Wrong input params to get basic query range",
K(ret),
KP(query_range_ctx_),
KP(l_expr),
KP(r_expr),
KP(escape_expr),
K(cmp_type));
} else if ((T_OP_ROW == l_expr->get_expr_type() && T_OP_ROW != r_expr->get_expr_type()) ||
(T_OP_ROW != l_expr->get_expr_type() && T_OP_ROW == r_expr->get_expr_type())) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("Row must compare to row", K(ret));
} else {
query_range_ctx_->cur_expr_is_precise_ = false;
}
if (OB_FAIL(ret)) {
// do nothing
} else if (IS_BASIC_CMP_OP(cmp_type)) {
if (T_OP_ROW != l_expr->get_expr_type()) { // 1. unary compare
bool l_is_lossless = false;
bool r_is_lossless = false;
if (OB_FAIL(ObOptimizerUtil::is_lossless_column_cast(l_expr, l_is_lossless))) {
LOG_WARN("failed to check l_expr is lossless column cast", K(ret));
} else if (OB_FAIL(ObOptimizerUtil::is_lossless_column_cast(r_expr, r_is_lossless))) {
LOG_WARN("failed to check l_expr is lossless column cast", K(ret));
}
if (OB_SUCC(ret)) {
if (l_is_lossless) {
l_expr = l_expr->get_param_expr(0);
}
if (r_is_lossless) {
r_expr = r_expr->get_param_expr(0);
}
if (l_expr->is_const_expr() && r_expr->is_const_expr()) { // const
if (OB_FAIL(
get_const_key_part(l_expr, r_expr, escape_expr, cmp_type, result_type, out_key_part, dtc_params))) {
LOG_WARN("get const key part failed.", K(ret));
}
} else if ((l_expr->has_flag(IS_COLUMN) && (r_expr->is_const_expr() || r_expr->has_flag(IS_PARAM))) ||
((l_expr->is_const_expr() || l_expr->has_flag(IS_PARAM)) && r_expr->has_flag(IS_COLUMN) &&
T_OP_LIKE != cmp_type)) {
if (OB_FAIL(get_column_key_part(
l_expr, r_expr, escape_expr, cmp_type, result_type, out_key_part, dtc_params))) { // column
LOG_WARN("get column key part failed.", K(ret));
}
} else if (l_expr->has_flag(IS_COLUMN) && r_expr->has_flag(IS_COLUMN)) {
GET_ALWAYS_TRUE_OR_FALSE(true, out_key_part);
} else {
GET_ALWAYS_TRUE_OR_FALSE(true, out_key_part);
}
}
} else if (OB_FAIL(get_row_key_part(
l_expr, r_expr, cmp_type, result_type, out_key_part, dtc_params))) { // 2. row compare
LOG_WARN("get row key part failed.", K(ret));