forked from oceanbase/seekdb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathob_log_table_scan.cpp
More file actions
5892 lines (5681 loc) · 279 KB
/
Copy pathob_log_table_scan.cpp
File metadata and controls
5892 lines (5681 loc) · 279 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) 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 "sql/optimizer/ob_log_table_scan.h"
#include "sql/optimizer/ob_log_join.h"
#include "share/vector_index/ob_vector_index_util.h"
#include "share/domain_id/ob_domain_id.h"
using namespace oceanbase::sql;
using namespace oceanbase::common;
using namespace oceanbase::share;
using namespace oceanbase::storage;
using oceanbase::share::schema::ObTableSchema;
using oceanbase::share::schema::ObSchemaGetterGuard;
const char *ObLogTableScan::get_name() const
{
bool is_get = false;
bool is_range = false;
const char *name = NULL;
int ret = OB_SUCCESS;
SampleInfo::SampleMethod sample_method = get_sample_info().method_;
const ObQueryRangeProvider *pre_range = get_pre_graph();
if (NULL != pre_range) {
if (OB_FAIL(pre_range->is_get(is_get))) {
// is_get always return true
LOG_WARN("failed to get is_get", K(ret));
} else if (use_query_range()) {
is_range = true;
}
}
if (sample_method != SampleInfo::NO_SAMPLE) {
if (sample_method == SampleInfo::ROW_SAMPLE) {
name = "TABLE ROW SAMPLE SCAN";
} else if (sample_method == SampleInfo::BLOCK_SAMPLE) {
name = "TABLE BLOCK SAMPLE SCAN";
} else if (sample_method == SampleInfo::HYBRID_SAMPLE) {
name = "TABLE HYBRID SAMPLE SCAN";
} else if (sample_method == SampleInfo::DDL_BLOCK_SAMPLE) {
name = "TABLE DDL BLOCK SAMPLE SCAN";
}
} else if (vector_index_info_.vec_type_ == ObVecIndexType::VEC_INDEX_PRE) {
if (use_index_merge()) {
name = use_das() ? "DISTRIBUTED VECTOR INDEX PRE-FILTER INDEX MERGE SCAN" : "VECTOR INDEX PRE-FILTER INDEX MERGE SCAN";
} else {
name = use_das() ? "DISTRIBUTED VECTOR INDEX PRE-FILTER SCAN" : "VECTOR INDEX PRE-FILTER SCAN";
}
} else if (vector_index_info_.vec_type_ == ObVecIndexType::VEC_INDEX_POST_ITERATIVE_FILTER) {
name = use_das() ? "DISTRIBUTED VECTOR INDEX POST-ITERATIVE-FILTER SCAN" : "VECTOR INDEX POST-ITERATIVE-FILTER SCAN";
} else if (vector_index_info_.vec_type_ == ObVecIndexType::VEC_INDEX_ADAPTIVE_SCAN) {
if (use_index_merge()) {
name = use_das() ? "DISTRIBUTED VECTOR INDEX ADAPTIVE INDEX MERGE SCAN" : "VECTOR INDEX ADAPTIVE INDEX MERGE SCAN";
} else if (vector_index_info_.adaptive_try_path_ == ObVecIdxAdaTryPath::VEC_INDEX_ITERATIVE_FILTER) {
name = use_das() ? "DISTRIBUTED VECTOR INDEX ADAPTIVE SCAN (POST-ITERATIVE-FILTER)" :
"VECTOR INDEX ADAPTIVE SCAN (POST-ITERATIVE-FILTER)";
} else if (vector_index_info_.adaptive_try_path_ == ObVecIdxAdaTryPath::VEC_INDEX_IN_FILTER) {
name = use_das() ? "DISTRIBUTED VECTOR INDEX ADAPTIVE SCAN (IN-FILTER)" :
"VECTOR INDEX ADAPTIVE SCAN (IN-FILTER)";
} else if (vector_index_info_.adaptive_try_path_ == ObVecIdxAdaTryPath::VEC_INDEX_PRE_FILTER) {
name = use_das() ? "DISTRIBUTED VECTOR INDEX ADAPTIVE SCAN (PRE-FILTER)" :
"VECTOR INDEX ADAPTIVE SCAN (PRE-FILTER)";
} else if (vector_index_info_.adaptive_try_path_ == ObVecIdxAdaTryPath::VEC_INDEX_POST_FILTER) {
name = use_das() ? "DISTRIBUTED VECTOR INDEX ADAPTIVE SCAN (POST-FILTER)" :
"VECTOR INDEX ADAPTIVE SCAN (POST-FILTER)";
} else {
name = use_das() ? "DISTRIBUTED VECTOR INDEX ADAPTIVE SCAN (UNCHOSEN)" :
"VECTOR INDEX ADAPTIVE SCAN (UNCHOSEN)";
}
} else if (is_vec_idx_scan_post_filter()) {
name = use_das() ? "DISTRIBUTED VECTOR INDEX SCAN" : "VECTOR INDEX SCAN";
} else if (is_text_retrieval_scan() || has_es_match()) {
name = use_das() ? "DISTRIBUTED TEXT RETRIEVAL SCAN" : "TEXT RETRIEVAL SCAN";
} else if (is_skip_scan()) {
name = use_das() ? "DISTRIBUTED TABLE SKIP SCAN" : "TABLE SKIP SCAN";
} else if (EXTERNAL_TABLE == get_table_type()) {
name = "EXTERNAL TABLE SCAN";
} else if (use_index_merge()) {
name = use_das() ? "DISTRIBUTED INDEX MERGE SCAN" : "INDEX MERGE SCAN";
} else if (use_das()) {
if (is_get) {
name = "DISTRIBUTED TABLE GET";
} else if (is_range) {
name = "DISTRIBUTED TABLE RANGE SCAN";
} else {
name = "DISTRIBUTED TABLE FULL SCAN";
}
} else if (use_column_store()) {
if (is_get) {
name = "COLUMN TABLE GET";
} else if (is_range) {
name = "COLUMN TABLE RANGE SCAN";
} else {
name = "COLUMN TABLE FULL SCAN";
}
} else {
if (is_get) {
name = "TABLE GET";
} else if (is_range) {
name = "TABLE RANGE SCAN";
} else {
name = "TABLE FULL SCAN";
}
}
return name;
}
bool ObLogTableScan::use_query_range() const
{
bool res = false;
const ObRangeNode *head = NULL;
bool cnt_dynamic_param = false;
if (range_conds_.count() > 0) {
// can extract precise range (for old query range)
res = true;
} else {
if (!ranges_.empty()) {
bool valid_range = false;
for (int64_t i = 0; !valid_range && i < ranges_.count(); ++i) {
if (!ranges_.at(i).is_whole_range()) {
valid_range = true;
}
}
res = valid_range;
}
// check pre range graph head for dynamic param
if (!res && OB_NOT_NULL(get_pre_range_graph()) &&
OB_NOT_NULL(head = get_pre_range_graph()->get_range_head())) {
for (int64_t i = 0; !cnt_dynamic_param && i < filter_exprs_.count(); ++i) {
cnt_dynamic_param = OB_NOT_NULL(filter_exprs_.at(i)) &&
filter_exprs_.at(i)->has_flag(CNT_DYNAMIC_PARAM);
}
res = cnt_dynamic_param &&
get_pre_range_graph()->get_skip_scan_offset() == -1 &&
head->min_offset_ == 0 && !head->always_true_;
}
}
return res;
}
int ObLogTableScan::check_is_delete_insert_scan(bool &is_delete_insert_scan) const
{
int ret = OB_SUCCESS;
is_delete_insert_scan = false;
ObSQLSessionInfo *session = NULL;
ObSchemaGetterGuard *schema_guard = nullptr;
const ObTableSchema *table_schema = nullptr;
const int64_t table_id = is_index_scan() ? index_table_id_ : ref_table_id_;
if (OB_ISNULL(get_plan())
|| OB_ISNULL(session = get_plan()->get_optimizer_context().get_session_info())
|| OB_ISNULL(schema_guard = get_plan()->get_optimizer_context().get_schema_guard())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("failed to get table schema", K(ret));
} else if (OB_FAIL(schema_guard->get_table_schema(session->get_effective_tenant_id(), table_id, table_schema))) {
LOG_WARN("failed to get table schema", K(ret));
} else if (OB_UNLIKELY(NULL == table_schema)) {
// may be fake table, skip
LOG_DEBUG("get nullptr table schema", K(ret), K_(table_id), K_(ref_table_id), K(get_stmt()));
} else if (table_schema->is_delete_insert_merge_engine()) {
omt::ObTenantConfigGuard tenant_config(TENANT_CONF(MTL_ID()));
if (OB_LIKELY(tenant_config.is_valid())) {
is_delete_insert_scan = tenant_config->_enable_delete_insert_scan;
}
}
return ret;
}
void ObLogTableScan::set_ref_table_id(uint64_t ref_table_id)
{
ref_table_id_ = ref_table_id;
}
int ObLogTableScan::set_range_columns(const ObIArray<ColumnItem> &range_columns)
{
int ret = OB_SUCCESS;
range_columns_.reset();
if (OB_FAIL(range_columns_.assign(range_columns))) {
LOG_WARN("failed to assign range columns", K(ret));
} else if (!is_virtual_table(ref_table_id_)) {
// banliu.zyd: Virtual table does not guarantee order, only process non-virtual tables
OrderItem item;
int64_t N = range_columns.count();
reset_op_ordering();
common::ObIArray<OrderItem> &op_ordering = get_op_ordering();
for (int64_t i = 0; OB_SUCC(ret) && i < N; ++i) {
item.expr_ = range_columns.at(i).expr_;
item.order_type_ = scan_direction_;
if (OB_FAIL(op_ordering.push_back(item))) {
LOG_WARN("failed to push back item", K(ret));
}
}
} else { /*do nothing*/ }
return ret;
}
int ObLogTableScan::do_re_est_cost(EstimateCostInfo ¶m, double &card, double &op_cost, double &cost)
{
int ret = OB_SUCCESS;
double limit_percent = -1.0;
int64_t limit_count = -1;
int64_t offset_count = 0;
const ObDMLStmt *stmt = NULL;
if (NULL == access_path_) { // table scan create from CteTablePath
card = get_card();
op_cost = get_op_cost();
cost = get_cost();
} else if (OB_ISNULL(get_plan()) || OB_ISNULL(est_cost_info_) ||
OB_ISNULL(stmt = get_plan()->get_stmt()) || OB_ISNULL(stmt->get_query_ctx()) ||
OB_UNLIKELY(1 > param.need_parallel_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected params", K(ret), K(est_cost_info_), K(param));
} else if (OB_FAIL(get_limit_offset_value(NULL, limit_count_expr_, limit_offset_expr_,
limit_percent, limit_count, offset_count))) {
LOG_WARN("failed to get limit offset value", K(ret));
} else {
est_cost_info_->rescan_left_server_list_ = param.rescan_left_server_list_;
card = get_output_row_count();
int64_t part_count = est_cost_info_->index_meta_info_.index_part_count_;
double limit_count_double = static_cast<double>(limit_count);
double offset_count_double = static_cast<double>(offset_count);
if (0 <= limit_count) {
if (!use_das()) {
limit_count_double *= part_count;
offset_count_double *= part_count;
}
double need_row_count = limit_count_double + offset_count_double;
if (param.need_row_count_ < 0) {
param.need_row_count_ = need_row_count;
} else {
param.need_row_count_ = std::min(param.need_row_count_ + offset_count_double, need_row_count);
}
est_cost_info_->limit_rows_ = limit_count;
}
if (ObEnableOptRowGoal::OFF == get_plan()->get_optimizer_context().get_enable_opt_row_goal()) {
param.need_row_count_ = -1;
est_cost_info_->limit_rows_ = -1;
} else if (range_conds_.empty() &&
ObEnableOptRowGoal::AUTO == get_plan()->get_optimizer_context().get_enable_opt_row_goal() &&
(!est_cost_info_->postfix_filters_.empty() ||
!est_cost_info_->table_filters_.empty() ||
!est_cost_info_->ss_postfix_range_filters_.empty())) {
// full scan with table filters
param.need_row_count_ = -1;
}
if (param.need_row_count_ > card) {
param.need_row_count_ = -1;
}
if (access_path_->is_index_merge_path()) {
card = param.need_row_count_ < 0 ? get_card() : std::min(param.need_row_count_, get_card());
op_cost = get_op_cost();
cost = get_cost();
} else if (OB_FAIL(AccessPath::re_estimate_cost(param,
*est_cost_info_,
sample_info_,
get_plan()->get_optimizer_context(),
access_path_->can_batch_rescan_,
card,
op_cost))) {
LOG_WARN("failed to re estimate cost", K(ret));
} else {
est_cost_info_->rescan_left_server_list_ = NULL;
cost = op_cost;
if (0 <= limit_count && param.need_row_count_ == -1) {
// full scan with table filters
card = std::min(limit_count_double + offset_count_double, card);
}
card = std::max(card - offset_count_double, 0.0);
}
}
return ret;
}
int ObLogTableScan::get_op_exprs(ObIArray<ObRawExpr*> &all_exprs)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(get_plan())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else if (OB_FAIL(generate_auto_split_filter())) {
LOG_WARN("failed to generate split filter", K(ret));
} else if (OB_FAIL(generate_access_exprs())) {
LOG_WARN("failed to generate acess exprs", K(ret));
} else if (NULL != auto_split_filter_ &&
OB_FAIL(all_exprs.push_back(auto_split_filter_))) {
LOG_WARN("failed to push back expr", K(ret));
} else if (NULL != limit_count_expr_ &&
OB_FAIL(all_exprs.push_back(limit_count_expr_))) {
LOG_WARN("failed to push back expr", K(ret));
} else if (NULL != limit_offset_expr_ &&
OB_FAIL(all_exprs.push_back(limit_offset_expr_))) {
LOG_WARN("failed to push back expr", K(ret));
} else if (NULL != fq_expr_ && OB_FAIL(all_exprs.push_back(fq_expr_))) {
LOG_WARN("failed to push back expr", K(ret));
} else if (NULL != tablet_id_expr_ && OB_FAIL(all_exprs.push_back(tablet_id_expr_))) {
LOG_WARN("failed to push back expr", K(ret));
} else if (NULL != calc_part_id_expr_ && OB_FAIL(all_exprs.push_back(calc_part_id_expr_))) {
LOG_WARN("failed to push back expr", K(ret));
} else if (OB_FAIL(allocate_lookup_trans_info_expr())) {
LOG_WARN("failed to add lookup trans expr", K(ret));
} else if (NULL != trans_info_expr_ && OB_FAIL(all_exprs.push_back(trans_info_expr_))) {
LOG_WARN("failed to push back expr", K(ret));
} else if (NULL != group_id_expr_ && OB_FAIL(all_exprs.push_back(group_id_expr_))) {
LOG_WARN("failed to push back expr", K(ret));
} else if (is_text_retrieval_scan()
&& OB_FAIL(get_text_retrieval_calc_exprs(get_text_retrieval_info(), all_exprs))) {
LOG_WARN("failed to get text retrieval exprs", K(ret));
}
if (OB_SUCC(ret)) {
for (int i = 0; OB_SUCC(ret) && i < rowkey_id_exprs_.count(); ++i) {
ObRawExpr *expr = rowkey_id_exprs_.at(i).second;
if (OB_FAIL(all_exprs.push_back(expr))) {
LOG_WARN("failed to append rowkey id exprs", K(ret), K(i));
}
}
}
if (OB_FAIL(ret)) {
} else if (has_func_lookup() && OB_FAIL(get_func_lookup_calc_exprs(all_exprs))) {
LOG_WARN("failed to get functional lookup exprs", K(ret));
} else if (has_es_match() && OB_FAIL(get_match_score_calc_exprs(all_exprs))) {
LOG_WARN("failed to get match score calc exprs", K(ret));
} else if (use_index_merge() && OB_FAIL(get_index_merge_calc_exprs(all_exprs))) {
LOG_WARN("failed to get index merge calc exprs", K(ret));
} else if (is_vec_idx_scan() && OB_FAIL(get_vec_idx_calc_exprs(all_exprs))) {
LOG_WARN("failed to get text retrieval exprs", K(ret));
} else if (OB_FAIL(append(all_exprs, pseudo_columnref_exprs_))) {
LOG_WARN("failed to append pseudo_columnref_exprs_", K(ret));
} else if (OB_FAIL(append(all_exprs, access_exprs_))) {
LOG_WARN("failed to append exprs", K(ret));
} else if (OB_FAIL(append(all_exprs, pushdown_aggr_exprs_))) {
LOG_WARN("failed to append exprs", K(ret));
} else if (OB_FAIL(generate_filter_monotonicity())) {
LOG_WARN("failed to analyze filter monotonicity", K(ret));
} else if (OB_FAIL(get_filter_assist_exprs(all_exprs))) {
LOG_WARN("failed to get filter assist expr", K(ret));
} else if (use_index_merge() && OB_FAIL(append_array_no_dup(all_exprs, full_filters_))) {
LOG_WARN("failed to append index merge full filters", 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 ObLogTableScan::allocate_expr_post(ObAllocExprContext &ctx)
{
int ret = OB_SUCCESS;
for (int64_t i = 0; OB_SUCC(ret) && i < access_exprs_.count(); i++) {
ObRawExpr *expr = access_exprs_.at(i);
if (OB_ISNULL(expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("null expr", K(ret));
} else if (OB_FAIL(mark_expr_produced(expr, branch_id_, id_, ctx))) {
LOG_WARN("failed to mark expr as produced", K(*expr), K(branch_id_), K(id_), K(ret));
} else { /*do nothing*/ }
}
for (int64_t i = 0; OB_SUCC(ret) && i < pushdown_aggr_exprs_.count(); i++) {
ObRawExpr *expr = NULL;
if (OB_ISNULL(expr = pushdown_aggr_exprs_.at(i))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get null expr", K(ret));
} else if (OB_FAIL(mark_expr_produced(expr, branch_id_, id_, ctx))) {
LOG_WARN("failed to mark expr as produced", K(*expr), K(branch_id_), K(id_), K(ret));
} else { /*do nothing*/ }
}
for (int64_t i = 0; OB_SUCC(ret) && i < pseudo_columnref_exprs_.count(); i++) {
ObRawExpr *expr = NULL;
if (OB_ISNULL(expr = pseudo_columnref_exprs_.at(i))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get null expr", K(ret));
} else if (OB_FAIL(mark_expr_produced(expr, branch_id_, id_, ctx))) {
LOG_WARN("failed to mark expr as produced", K(*expr), K(branch_id_), K(id_), K(ret));
} else { /*do nothing*/ }
}
for (int64_t i = 0; OB_SUCC(ret) && i < rowkey_id_exprs_.count(); ++i) {
ObRawExpr *expr = rowkey_id_exprs_.at(i).second;
if (OB_ISNULL(expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("null expr", K(ret));
} else if (OB_FAIL(mark_expr_produced(expr, branch_id_, id_, ctx))) {
LOG_WARN("failed to mark expr as produced", K(*expr), K(branch_id_), K(id_), K(ret));
}
}
if (OB_SUCC(ret)) {
// match against relevance expr will be calculated in storage
ObSEArray<ObRawExpr *, 8> tmp_exprs;
if (is_text_retrieval_scan()
&& OB_FAIL(get_text_retrieval_calc_exprs(get_text_retrieval_info(), tmp_exprs))) {
LOG_WARN("failed to get text retrieval calc exprs", K(ret));
} else if (has_func_lookup()
&& OB_FAIL(get_func_lookup_calc_exprs(tmp_exprs))) {
LOG_WARN("failed to get func lookup exprs", K(ret));
} else if (has_es_match()
&& OB_FAIL(get_match_score_calc_exprs(tmp_exprs))) {
LOG_WARN("failed to get match score calc exprs", K(ret));
} else if (use_index_merge()
&& OB_FAIL(get_index_merge_calc_exprs(tmp_exprs))) {
LOG_WARN("failed to get index merge calc exprs", K(ret));
}
for (int64_t i = 0; OB_SUCC(ret) && i < tmp_exprs.count(); ++i) {
ObRawExpr *expr = tmp_exprs.at(i);
if (OB_ISNULL(expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("null expr", K(ret));
} else if (OB_FAIL(mark_expr_produced(expr, branch_id_, id_, ctx))) {
LOG_WARN("failed to mark expr as produced", K(*expr), K(branch_id_), K(id_), K(ret));
} else { /*do nothing*/ }
}
}
// check if we can produce some more exprs, such as 1 + 'c1' after we have produced 'c1'
if (OB_SUCC(ret)) {
if (!is_plan_root() && OB_FAIL(append(output_exprs_, access_exprs_))) {
LOG_WARN("failed to append exprs", K(ret));
} else if (OB_FAIL(append(output_exprs_, pushdown_aggr_exprs_))) {
LOG_WARN("failed to append exprs", K(ret));
} else if (OB_FAIL(ObLogicalOperator::allocate_expr_post(ctx))) {
LOG_WARN("failed to allocate expr post", K(ret));
} else { /*do nothing*/ }
}
// add special exprs to all exprs
if (OB_SUCC(ret)) {
ObRawExprUniqueSet &all_exprs = get_plan()->get_optimizer_context().get_all_exprs();
if (NULL != part_expr_ && OB_FAIL(all_exprs.append(part_expr_))) {
LOG_WARN("failed to get part expr", K(ret));
} else if (NULL != subpart_expr_ && OB_FAIL(all_exprs.append(subpart_expr_))) {
LOG_WARN("failed to get subpart expr", K(ret));
} else if (OB_FAIL(all_exprs.append(range_conds_))) {
LOG_WARN("failed to append range exprs", K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < real_expr_map_.count(); ++i) {
if (OB_FAIL(all_exprs.append(real_expr_map_.at(i).second))) {
LOG_WARN("failed to append real expr", K(ret));
}
}
}
}
return ret;
}
int ObLogTableScan::check_output_dependance(common::ObIArray<ObRawExpr *> &child_output, PPDeps &deps)
{
int ret = OB_SUCCESS;
ObSEArray<ObRawExpr*, 8> exprs;
LOG_TRACE("start to check output exprs", K(type_), K(child_output), K(deps));
ObRawExprCheckDep dep_checker(child_output, deps, true);
if (OB_FAIL(append(exprs, filter_exprs_))) {
LOG_WARN("failed to append exprs", K(ret));
} else if (OB_FAIL(append_array_no_dup(exprs, output_exprs_))) {
LOG_WARN("failed to append exprs", K(ret));
} else if (OB_FAIL(append_array_no_dup(exprs, rowkey_exprs_))) {
LOG_WARN("failed to append exprs", K(ret));
} else if (OB_FAIL(append_array_no_dup(exprs, part_exprs_))) {
LOG_WARN("failed to append exprs", K(ret));
} else if (OB_FAIL(append_array_no_dup(exprs, spatial_exprs_))) {
LOG_WARN("failed to append exprs", K(ret));
} else if (use_group_id() && nullptr != group_id_expr_
&& OB_FAIL(add_var_to_array_no_dup(exprs, group_id_expr_))) {
LOG_WARN("failed to push back group id expr", K(ret));
} else if (index_back_ &&
nullptr != trans_info_expr_ &&
OB_FAIL(add_var_to_array_no_dup(exprs, trans_info_expr_))) {
LOG_WARN("fail to add lookup trans info expr", K(ret));
} else if (OB_FAIL(dep_checker.check(exprs))) {
LOG_WARN("failed to check op_exprs", K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < child_output.count(); i++) {
if (OB_ISNULL(child_output.at(i))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected error", K(ret));
} else if (child_output.at(i)->get_expr_type() == T_PSEUDO_EXTERNAL_FILE_URL) {
if (OB_FAIL(deps.del_member(i))) {
LOG_WARN("del member failed", K(ret));
}
}
}
LOG_TRACE("succeed to check output exprs", K(exprs), K(type_), K(deps));
}
return ret;
}
int ObLogTableScan::extract_file_column_exprs_recursively(ObRawExpr *expr)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("expr is null", K(ret));
} else if (T_PSEUDO_EXTERNAL_FILE_COL == expr->get_expr_type() ||
T_PSEUDO_PARTITION_LIST_COL == expr->get_expr_type() ||
T_PSEUDO_EXTERNAL_FILE_URL == expr->get_expr_type()) {
auto pseudo_col_expr = static_cast<ObPseudoColumnRawExpr*>(expr);
if (pseudo_col_expr->get_table_id() != table_id_) {
//table id may be changed because of rewrite
pseudo_col_expr->set_table_id(table_id_);
}
if (OB_FAIL(add_var_to_array_no_dup(ext_file_column_exprs_, expr))) {
LOG_WARN("failed to add var to array", K(ret));
}
} else {
for (int i = 0; OB_SUCC(ret) && i < expr->get_param_count(); ++i) {
if (OB_FAIL(extract_file_column_exprs_recursively(expr->get_param_expr(i)))) {
LOG_WARN("fail to extract file column expr", K(ret));
}
}
}
return ret;
}
// If the filter is indexed before returning to the table,
// and there are generated columns, deep copy is required
int ObLogTableScan::copy_filter_before_index_back()
{
int ret = OB_SUCCESS;
ObIArray<ObRawExpr*> &filters = get_filter_exprs();
const auto &flags = get_filter_before_index_flags();
if (use_index_merge()) {
// need to copy filter conclude virtual generated column for each index scan in index merge
if (OB_FAIL(copy_filter_for_index_merge())) {
LOG_WARN("failed to copy filter for index merge", K(ret));
}
} else if (OB_FAIL(filter_before_index_back_set())) {
LOG_WARN("Failed to filter_before_index_back_set", K(ret));
} else if (get_index_back() && !flags.empty()) {
for (int64_t i = 0; OB_SUCC(ret) && i < filters.count(); ++i) {
if (filters.at(i)->has_flag(CNT_PL_UDF)) {
// do nothing.
} else if (flags.at(i)) {
if (get_index_back() && get_is_index_global() && filters.at(i)->has_flag(CNT_SUB_QUERY)) {
// do nothing.
} else {
bool is_contain_vir_gen_column = false;
// ObArray<ObRawExpr *> column_exprs;
// scan_pushdown before index back conclude virtual generated column
// need copy for avoiding shared expression.
if (OB_FAIL(ObRawExprUtils::contain_virtual_generated_column(filters.at(i), is_contain_vir_gen_column))) {
LOG_WARN("fail to contain virtual gen column", K(ret));
} else if (is_contain_vir_gen_column) {
ObArray<ObRawExpr *> vir_gen_par_exprs;
if (OB_FAIL(ObRawExprUtils::extract_virtual_generated_column_parents(filters.at(i), filters.at(i), vir_gen_par_exprs))) {
LOG_WARN("failed to extract virtual generated column parents", K(ret), K(i));
} else {
ObRawExprCopier copier(get_plan()->get_optimizer_context().get_expr_factory());
for (int64_t j = 0; OB_SUCC(ret) && j < vir_gen_par_exprs.count(); ++j) {
ObRawExpr *copied_expr = NULL;
ObRawExpr *old_expr = filters.at(i);
if (OB_FAIL(get_plan()->get_optimizer_context().get_expr_factory().create_raw_expr(
vir_gen_par_exprs.at(j)->get_expr_class(),
vir_gen_par_exprs.at(j)->get_expr_type(),
copied_expr))) {
LOG_WARN("failed to create raw expr", K(ret));
} else if (OB_FAIL(copied_expr->deep_copy(copier, *vir_gen_par_exprs.at(j)))) {
LOG_WARN("failed to assign old expr", K(ret));
} else if (OB_FAIL(copier.add_replaced_expr(vir_gen_par_exprs.at(j), copied_expr))) {
LOG_WARN("failed to add replaced expr", K(ret));
} else if (OB_FAIL(copier.copy_on_replace(filters.at(i), filters.at(i)))) {
LOG_WARN("failed to copy exprs", K(ret));
} else if (filters.at(i)->get_expr_type() == T_OP_RUNTIME_FILTER
|| filters.at(i)->get_expr_type() == T_OP_PUSHDOWN_TOPN_FILTER) {
// record runtime filter, also replace it in join filter use operator
if (OB_FAIL(get_plan()->gen_col_replacer().add_replace_expr(old_expr,
filters.at(i)))) {
LOG_WARN("failed to add replace expr");
}
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(copier.copy_on_replace(filters.at(i), filters.at(i)))) {
LOG_WARN("failed to copy exprs", K(ret));
}
}
}
}
}
}
}
}
return ret;
}
int ObLogTableScan::copy_filter_for_index_merge()
{
int ret = OB_SUCCESS;
// each index scan only involves range conds for now in index merge
for (int64_t i = 0; OB_SUCC(ret) && i < index_range_conds_.count(); i++) {
common::ObIArray<ObRawExpr*> &range_conds = index_range_conds_.at(i);
for (int64_t i = 0; OB_SUCC(ret) && i < range_conds.count(); ++i) {
if (range_conds.at(i)->has_flag(CNT_PL_UDF)) {
// do nothing.
} else {
bool contain_vir_gen_column = false;
if (OB_FAIL(ObRawExprUtils::contain_virtual_generated_column(range_conds.at(i), contain_vir_gen_column))) {
LOG_WARN("fail to check contain virtual gen column", K(ret));
} else if (contain_vir_gen_column) {
ObArray<ObRawExpr *> vir_gen_par_exprs;
if (OB_FAIL(ObRawExprUtils::extract_virtual_generated_column_parents(range_conds.at(i), range_conds.at(i), vir_gen_par_exprs))) {
LOG_WARN("failed to extract virtual generated column parents", K(ret), K(i));
} else {
ObRawExprCopier copier(get_plan()->get_optimizer_context().get_expr_factory());
for (int64_t j = 0; OB_SUCC(ret) && j < vir_gen_par_exprs.count(); ++j) {
ObRawExpr *copied_expr = NULL;
ObRawExpr *old_expr = range_conds.at(i);
if (OB_FAIL(get_plan()->get_optimizer_context().get_expr_factory().create_raw_expr(
vir_gen_par_exprs.at(j)->get_expr_class(),
vir_gen_par_exprs.at(j)->get_expr_type(),
copied_expr))) {
LOG_WARN("failed to create raw expr", K(ret));
} else if (OB_FAIL(copied_expr->deep_copy(copier, *vir_gen_par_exprs.at(j)))) {
LOG_WARN("failed to assign old expr", K(ret));
} else if (OB_FAIL(copier.add_replaced_expr(vir_gen_par_exprs.at(j), copied_expr))) {
LOG_WARN("failed to add replaced expr", K(ret));
} else if (OB_FAIL(copier.copy_on_replace(range_conds.at(i), range_conds.at(i)))) {
LOG_WARN("failed to copy exprs", K(ret));
} else if (range_conds.at(i)->get_expr_type() == T_OP_RUNTIME_FILTER
|| range_conds.at(i)->get_expr_type() == T_OP_PUSHDOWN_TOPN_FILTER) {
// record runtime filter, also replace it in join filter use operator
if (OB_FAIL(get_plan()->gen_col_replacer().add_replace_expr(old_expr,
range_conds.at(i)))) {
LOG_WARN("failed to add replace expr");
}
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(copier.copy_on_replace(range_conds.at(i), range_conds.at(i)))) {
LOG_WARN("failed to copy exprs", K(ret));
}
}
}
}
}
}
}
return ret;
}
int ObLogTableScan::generate_access_exprs()
{
int ret = OB_SUCCESS;
const ObDMLStmt *stmt = NULL;
ObSEArray<ObRawExpr*, 8> temp_exprs;
if (OB_ISNULL(get_plan()) || OB_ISNULL(stmt = get_stmt())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(get_plan()), K(get_stmt()), K(ret));
} else if (OB_FAIL(copy_filter_before_index_back())) {
LOG_WARN("failed to copy filter before index back", K(ret));
// Note: if it exists the fts with no_docid, we need the rowkey exprs
// So, we need to generate the rowkey exprs before generate the fts exprs
} else if (OB_FAIL(generate_necessary_rowkey_and_partkey_exprs())) {
LOG_WARN("failed to generate rowkey and part exprs", K(ret));
} else if (is_text_retrieval_scan() && OB_FAIL(prepare_text_retrieval_dep_exprs(get_text_retrieval_info()))) {
LOG_WARN("failed to copy text retrieval aggr exprs", K(ret));
} else if (is_vec_idx_scan() && OB_FAIL(prepare_vector_access_exprs())) {
LOG_WARN("failed to copy vec idx scan exprs", K(ret));
} else if (is_tsc_with_domain_id() && OB_FAIL(prepare_rowkey_domain_id_dep_exprs())) {
LOG_WARN("failed to prepare table scan with doc id info", K(ret));
} else if ((has_func_lookup() || (is_vec_idx_scan() && (is_text_retrieval_scan() || get_merge_tr_infos().count() > 0))) && OB_FAIL(prepare_func_lookup_dep_exprs())) {
LOG_WARN("failed to prepare functional lookup dependent exprs", K(ret));
} else if (use_index_merge() && OB_FAIL(prepare_index_merge_dep_exprs())) {
LOG_WARN("failed to prepare index merge dependent exprs", K(ret));
} else if (has_es_match() && OB_FAIL(prepare_match_dep_exprs())) {
LOG_WARN("failed to prepare match dependent exprs", K(ret));
} else if (OB_FAIL(generate_necessary_domain_exprs())) {
LOG_WARN("failed to generate domain exprs", K(ret));
} else if (OB_FAIL(allocate_group_id_expr())) {
LOG_WARN("failed to allocate group id expr", K(ret));
} else if (NULL != group_id_expr_ && use_batch_ && OB_FAIL(access_exprs_.push_back(group_id_expr_))) {
LOG_WARN("failed to push back expr", K(ret));
} else if (OB_FAIL(append_array_no_dup(access_exprs_, rowkey_exprs_))) {
LOG_WARN("failed to push back exprs", K(ret));
} else if (OB_FAIL(append_array_no_dup(access_exprs_, part_exprs_))) {
LOG_WARN("failed to push back exprs", K(ret));
} else if (is_spatial_index_ && OB_FAIL(append_array_no_dup(access_exprs_, spatial_exprs_))) {
LOG_WARN("failed to push back exprs", K(ret));
} else if (OB_FAIL(append_array_no_dup(access_exprs_, domain_exprs_))) {
LOG_WARN("failed to append domain exprs", K(ret));
} else if (is_index_global_ && index_back_) {
if (OB_FAIL(ObRawExprUtils::extract_column_exprs(filter_exprs_, temp_exprs, false, false))) {
LOG_WARN("failed to extract column exprs", K(ret));
} else if (OB_FAIL(append_array_no_dup(access_exprs_, temp_exprs))) {
LOG_WARN("failed to append array no dup", K(ret));
} else { /*do nothing*/}
}
if (OB_SUCC(ret) && nullptr != auto_split_filter_) {
ObSEArray<ObRawExpr*, 8> temp_col_exprs;
if (OB_FAIL(ObRawExprUtils::extract_column_exprs(auto_split_filter_, temp_col_exprs, false, false))) {
LOG_WARN("failed to extract column exprs", K(ret));
} else if (OB_FAIL(append_array_no_dup(access_exprs_, temp_col_exprs))) {
LOG_WARN("failed to append array no dup", K(ret));
} else { /*do nothing*/}
}
if (OB_SUCC(ret)) {
for (int64_t i = 0; OB_SUCC(ret) && i < stmt->get_column_size(); i++) {
const ColumnItem *col_item = stmt->get_column_item(i);
if (OB_ISNULL(col_item) || OB_ISNULL(col_item->expr_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(col_item), K(ret));
} else if (col_item->table_id_ != table_id_ || !col_item->expr_->is_explicited_reference()) {
//do nothing
} else if (col_item->expr_->is_only_referred_by_stored_gen_col()) {
//skip if is only referred by stored generated columns which don't need to be recalculated
} else if (col_item->expr_->is_column_ref_expr() &&
static_cast<const ObColumnRefRawExpr*>(col_item->expr_)->is_pseudo_column_ref()) {
if (OB_FAIL(add_var_to_array_no_dup(pseudo_columnref_exprs_,
static_cast<ObRawExpr*>(col_item->expr_)))) {
LOG_WARN("fail to push back expr into pseudo_columnref_exprs_", K(ret));
}
} else if (is_index_scan() && !get_index_back() && !col_item->expr_->is_referred_by_normal()) {
//skip the dependant columns of partkeys and generated columns if index_back is false in index scan
} else if (OB_FAIL(temp_exprs.push_back(col_item->expr_))) {
LOG_WARN("failed to push back expr", K(ret));
} else { /*do nothing*/}
}
if (OB_FAIL(ret)) {
/*do nothing*/
} else if (OB_FAIL(append_array_no_dup(access_exprs_, temp_exprs))) {
LOG_WARN("failed to append exprs", K(ret));
} else { /*do nothing*/ }
if (OB_SUCC(ret) && use_index_merge() && !full_filters_.empty()) {
ObArray<ObRawExpr*> column_exprs;
if (OB_FAIL(ObRawExprUtils::extract_column_exprs(full_filters_, column_exprs))) {
LOG_WARN("failed to extract column exprs", K(full_filters_), K(ret));
} else if (OB_FAIL(append_array_no_dup(access_exprs_, column_exprs))) {
LOG_WARN("failed to append array no dup", K(column_exprs), K(ret));
}
}
for (int64_t i = 0; OB_SUCC(ret) && i < stmt->get_pseudo_column_like_exprs().count(); i++) {
ObRawExpr *expr = stmt->get_pseudo_column_like_exprs().at(i);
if (OB_ISNULL(expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else if (static_cast<ObPseudoColumnRawExpr*>(expr)->get_table_id() != table_id_) {
/* do nothing */
} else if (T_ORA_ROWSCN != expr->get_expr_type()
&& T_PSEUDO_EXTERNAL_FILE_URL != expr->get_expr_type()
&& T_PSEUDO_OLD_NEW_COL != expr->get_expr_type()) {
/* do nothing */
} else if (OB_FAIL(access_exprs_.push_back(expr))) {
LOG_WARN("fail to push back expr", K(ret));
} else if (T_PSEUDO_EXTERNAL_FILE_URL == expr->get_expr_type()) {
if (OB_FAIL(add_var_to_array_no_dup(ext_file_column_exprs_, expr))) {
LOG_WARN("fail to push back expr", K(ret));
} else if (OB_FAIL(add_var_to_array_no_dup(output_exprs_, expr))) {
LOG_WARN("fail to push back expr", K(ret));
}
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(add_mapping_columns_for_vt(access_exprs_))) {
LOG_WARN("failed to add mapping columns for vt", K(ret));
} else {
LOG_TRACE("succeed to generate access exprs", K(access_exprs_), K(ext_file_column_exprs_));
}
}
}
return ret;
}
int ObLogTableScan::replace_gen_col_op_exprs(ObRawExprReplacer &replacer)
{
int ret = OB_SUCCESS;
if (!need_replace_gen_column()) {
// do nothing.
} else if (!replacer.empty()) {
FOREACH_CNT_X(it, get_op_ordering(), OB_SUCC(ret)) {
if (OB_FAIL(replace_expr_action(replacer, it->expr_))) {
LOG_WARN("replace agg expr failed", K(ret));
}
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(replace_exprs_action(replacer, get_output_exprs()))) {
LOG_WARN("failed to replace agg expr", K(ret));
} else if (NULL != limit_offset_expr_ &&
OB_FAIL(replace_expr_action(replacer, limit_count_expr_))) {
LOG_WARN("failed to replace limit count expr", K(ret));
} else if (NULL != limit_offset_expr_ &&
OB_FAIL(replace_expr_action(replacer, limit_offset_expr_))) {
LOG_WARN("failed to replace limit offset expr ", K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < pushdown_aggr_exprs_.count(); ++i) {
ObAggFunRawExpr *pushdown_aggr_expr = pushdown_aggr_exprs_.at(i);
for (int64_t j = 0; OB_SUCC(ret) && j < pushdown_aggr_expr->get_param_count(); j++) {
if (OB_ISNULL(pushdown_aggr_expr->get_param_expr(j))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("param_expr is NULL", K(j), K(ret));
} else if (OB_FAIL(replace_expr_action(replacer,
pushdown_aggr_expr->get_param_expr(j)))) {
LOG_WARN("Fail to replace push down aggr expr", K(i), K(j), K(ret));
}
}
}
}
// Scenario processing without index table.
// for is_primary_vec_idx_scan, is_index_back = true,but filter should add to scan ctdef
if (OB_SUCC(ret) && (!get_index_back() || is_primary_vec_idx_scan())) {
if (NULL != part_expr_ &&
OB_FAIL(replace_expr_action(replacer, part_expr_))) {
LOG_WARN("failed to replace part expr ", K(ret));
} else if (NULL != subpart_expr_ && OB_FAIL(replace_expr_action(replacer,
subpart_expr_))) {
LOG_WARN("failed to replace subpart expr ", K(ret));
} else if (OB_FAIL(replace_exprs_action(replacer, get_filter_exprs()))) {
LOG_WARN("failed to replace agg expr", K(ret));
}
}
// Index back to table scene processing
if (OB_SUCC(ret) && get_index_back()) {
if (OB_FAIL(replace_index_back_pushdown_filters(replacer))) {
LOG_WARN("failed to replace pushdown exprs", K(ret));
}
}
} else { /* Do nothing */ }
return ret;
}
int ObLogTableScan::replace_index_back_pushdown_filters(ObRawExprReplacer &replacer)
{
int ret = OB_SUCCESS;
ObArray<ObRawExpr*> non_pushdown_expr;
ObArray<ObRawExpr*> scan_pushdown_filters;
ObArray<ObRawExpr*> lookup_pushdown_filters;
if (OB_UNLIKELY(!get_index_back())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("go wrong way", K(ret));
} else if (OB_FAIL(extract_pushdown_filters(non_pushdown_expr,
scan_pushdown_filters,
lookup_pushdown_filters))) {
LOG_WARN("extract pushdown filters failed", K(ret));
} else if (OB_FAIL(replace_exprs_action(replacer, non_pushdown_expr))) {
LOG_WARN("failed to replace non pushdown expr", K(ret));
} else if (OB_FAIL(replace_exprs_action(replacer, lookup_pushdown_filters))) {
LOG_WARN("failed to replace lookup pushdown expr", K(ret));
} else if (OB_UNLIKELY(use_index_merge())) {
// when use index merge, we need to replace the filter exprs related to virtual generated columns
// for those main table participates as a branch of merge.
IndexMergePath *path = static_cast<IndexMergePath*>(access_path_);
if (OB_ISNULL(path)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null index merge path", K(ret));
} else if (OB_FAIL(replace_index_merge_pushdown_filters(path->root_, replacer))) {
LOG_WARN("failed to replace index merge pushdown filters", K(ret));
}
} else { /* do nothing */ }
return ret;
}
int ObLogTableScan::replace_index_merge_pushdown_filters(ObIndexMergeNode *node, ObRawExprReplacer &replacer)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(node)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("invalid null index merge node", K(ret), KPC(node));
} else if (node->is_scan_node()) {
if (OB_ISNULL(node->ap_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("invalid null index merge access path", K(ret), KPC(node));
} else if (node->ap_->index_id_ == ref_table_id_) {
// main table participates as a branch of merge
ObArray<ObRawExpr*> scan_pushdown_filters;
if (OB_FAIL(get_index_filters(node->scan_node_idx_, scan_pushdown_filters))) {
LOG_WARN("failed to get index scan pushdown filters", K(node->ap_->index_id_), K(ret));
} else if (OB_FAIL(replace_exprs_action(replacer, scan_pushdown_filters))) {
LOG_WARN("failed to replace index scan pushdown filters", K(ret));
}
}
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < node->children_.count(); ++i) {
if (OB_FAIL(SMART_CALL(replace_index_merge_pushdown_filters(node->children_.at(i), replacer)))) {
LOG_WARN("failed to replace index merge pushdown filters", K(ret));
}
}
}
return ret;
}
int ObLogTableScan::has_nonpushdown_filter(bool &has_npd_filter)
{
int ret = OB_SUCCESS;
has_npd_filter = false;
ObArray<ObRawExpr*> nonpushdown_filters;
ObArray<ObRawExpr*> scan_pushdown_filters;
ObArray<ObRawExpr*> lookup_pushdown_filters;
if (OB_FAIL(extract_pushdown_filters(nonpushdown_filters,
scan_pushdown_filters,
lookup_pushdown_filters,
true /*ignore pushdown filters*/))) {
LOG_WARN("extract pushdnow filters failed", K(ret));
} else if (!nonpushdown_filters.empty()) {
has_npd_filter = true;
}
return ret;
}
int ObLogTableScan::extract_pushdown_filters(ObIArray<ObRawExpr*> &nonpushdown_filters,
ObIArray<ObRawExpr*> &scan_pushdown_filters,
ObIArray<ObRawExpr*> &lookup_pushdown_filters,
bool ignore_pd_filter /*= false */) const
{
int ret = OB_SUCCESS;
const ObIArray<ObRawExpr*> &filters = get_filter_exprs();
const auto &flags = get_filter_before_index_flags();
if (get_contains_fake_cte() ||
is_virtual_table(get_ref_table_id()) ||
EXTERNAL_TABLE == get_table_type()) {
//all filters can not push down to storage
if (OB_FAIL(nonpushdown_filters.assign(filters))) {
LOG_WARN("store non-pushdown filters failed", K(ret));
}
} else {
//part of filters can push down to storage
//scan_pushdown_filters means that:
//1. index scan filter when TSC use index scan directly or
//(TSC use index scan and lookup the data table)
//2. data table scan filter when TSC use the data table scan directly
//lookup_pushdown_filters means that the data table filter when
//TSC use index scan and lookup the data table
bool contains_part_id_columnref = false;
for (int64_t i = 0; OB_SUCC(ret) && i < filters.count(); ++i) {
bool add_to_scan_filter = false;
if (use_batch() && filters.at(i)->has_flag(CNT_DYNAMIC_PARAM)) {
//In Batch table scan the dynamic param filter do not push down to storage
if (OB_FAIL(nonpushdown_filters.push_back(filters.at(i)))) {
LOG_WARN("push dynamic filter to store non-pushdown filter failed", K(ret), K(i));
}
} else if (filters.at(i)->has_flag(CNT_PL_UDF) ||
filters.at(i)->has_flag(CNT_OBJ_ACCESS_EXPR)) {
//User Define Function/obj access expr filter do not push down to storage
if (OB_FAIL(nonpushdown_filters.push_back(filters.at(i)))) {
LOG_WARN("push UDF/obj access filter store non-pushdown filter failed", K(ret), K(i));
}
} else if (filters.at(i)->has_flag(CNT_DYNAMIC_USER_VARIABLE)
|| filters.at(i)->has_flag(CNT_ASSIGN_EXPR)) {
if (OB_FAIL(nonpushdown_filters.push_back(filters.at(i)))) {
LOG_WARN("push variable assign filter store non-pushdown filter failed", K(ret), K(i));
}
} else if ((has_func_lookup() || (is_vec_idx_scan() && is_text_retrieval_scan())) && (filters.at(i)->has_flag(CNT_MATCH_EXPR))) {
// for filter with match expr in functional lookup, need to be evaluated after func lookup
// push-down filter on main-table lookup with functional lookup not supported by executor
if (OB_FAIL(nonpushdown_filters.push_back(filters.at(i)))) {
LOG_WARN("push func-lookup match filter to non-pushdown array failed", K(ret), K(i));
} else if (is_vec_adaptive_scan()) {
add_to_scan_filter = true;
}
} else if (is_text_retrieval_scan() && need_text_retrieval_calc_relevance()) {
if (OB_FAIL(nonpushdown_filters.push_back(filters.at(i)))) {
LOG_WARN("push text retrieval scan store non-pushdown filter failed", K(ret), K(i));
} else if (is_vec_adaptive_scan()) {
add_to_scan_filter = true;
}
} else if (has_es_match()) {
if (OB_FAIL(nonpushdown_filters.push_back(filters.at(i)))) {
LOG_WARN("push text retrieval scan store non-pushdown filter failed", K(ret), K(i));
}
} else if (ignore_pd_filter) {
//ignore_pd_filter: only extract non-pushdown filters, ignore others
} else if (OB_FAIL(ObOptimizerUtil::check_contain_part_id_columnref_expr(filters.at(i),
contains_part_id_columnref))) {
LOG_WARN("check_contain_part_id_columnref_expr failed", K(ret));
} else if (contains_part_id_columnref) {
if (OB_FAIL(nonpushdown_filters.push_back(filters.at(i)))) {
LOG_WARN("push variable assign filter store non-pushdown filter failed", K(ret), K(i));
} else {
LOG_TRACE("check for not pushdown partid columnref filter here");
}
} else if (!get_index_back()) {
add_to_scan_filter = true;
if (OB_FAIL(scan_pushdown_filters.push_back(filters.at(i)))) {
LOG_WARN("store pushdown filter failed", K(ret));
}
} else if (flags.empty() || i >= flags.count()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("filter before index flag is invalid", K(ret), K(i), K(flags), K(filters));
} else if (flags.at(i) || (is_primary_vec_idx_scan() && !has_func_lookup())) {
if (get_index_back() && get_is_index_global() && filters.at(i)->has_flag(CNT_SUB_QUERY)) {
if (OB_FAIL(lookup_pushdown_filters.push_back(filters.at(i)))) {
LOG_WARN("store lookup pushdown filter failed", K(ret), K(i));
}
} else if (OB_FALSE_IT(add_to_scan_filter = true)) {
} else if (OB_FAIL(scan_pushdown_filters.push_back(filters.at(i)))) {
LOG_WARN("store scan pushdown filter failed", K(ret), K(i));
}
} else if ((has_func_lookup() || (is_vec_idx_scan() && is_text_retrieval_scan())) && !flags.at(i)) {
// push-down filter on main-table lookup with functional lookup not supported by executor