forked from oceanbase/oceanbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathob_log_join.cpp
More file actions
2063 lines (1990 loc) · 80.9 KB
/
ob_log_join.cpp
File metadata and controls
2063 lines (1990 loc) · 80.9 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 "share/system_variable/ob_sys_var_class_type.h"
#include "sql/optimizer/ob_log_join.h"
#include "sql/optimizer/ob_log_subplan_scan.h"
#include "sql/optimizer/ob_log_plan.h"
#include "sql/optimizer/ob_log_operator_factory.h"
#include "sql/optimizer/ob_log_sort.h"
#include "sql/optimizer/ob_log_exchange.h"
#include "sql/optimizer/ob_log_table_scan.h"
#include "sql/optimizer/ob_optimizer_util.h"
#include "sql/optimizer/ob_log_granule_iterator.h"
#include "sql/rewrite/ob_transform_utils.h"
using namespace oceanbase;
using namespace sql;
using namespace oceanbase::common;
using namespace oceanbase::share;
using namespace oceanbase::sql::log_op_def;
using oceanbase::share::schema::ObTableSchema;
using share::schema::ObSchemaGetterGuard;
int ObLogJoin::copy_without_child(ObLogicalOperator*& out)
{
int ret = OB_SUCCESS;
out = NULL;
ObLogicalOperator* op = NULL;
ObLogJoin* join = NULL;
if (OB_FAIL(clone(op))) {
LOG_WARN("failed to clone join operator", K(ret));
} else if (OB_ISNULL(join = static_cast<ObLogJoin*>(op))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("join is null", K(ret));
} else {
if (OB_FAIL(join->set_join_conditions(join_conditions_))) {
LOG_WARN("failed to set join conditions for copy", K(ret));
} else if (OB_FAIL(join->set_join_filters(join_filters_))) {
LOG_WARN("failed to set join filters for copy", K(ret));
} else if (OB_FAIL(join->set_nl_params(nl_params_))) {
LOG_WARN("failed to set nl params for copy", K(ret));
} else if (OB_FAIL(join->set_exec_params(exec_params_))) {
LOG_WARN("failed to set nl params for copy", K(ret));
} else if (OB_FAIL(append(join->merge_directions_, merge_directions_))) {
LOG_WARN("failed to set merge directions for copy", K(ret));
} else if (OB_FAIL(append(join->left_expected_ordering_, left_expected_ordering_))) {
LOG_WARN("failed to set left expected_ordering for copy", K(ret));
} else if (OB_FAIL(append(join->right_expected_ordering_, right_expected_ordering_))) {
LOG_WARN("failed to set right expected_ordering for copy", K(ret));
} else if (OB_FAIL(join->set_connect_by_prior_exprs(connect_by_prior_exprs_))) {
LOG_WARN("Failed to set cby prior exprs", K(ret));
} else if (OB_FAIL(join->set_connect_by_extra_exprs(connect_by_extra_exprs_))) {
LOG_WARN("fialed to set connect by extra exprs", K(ret));
} else {
join->set_join_type(join_type_);
join->set_join_algo(join_algo_);
join->set_late_mat(late_mat_);
join->set_join_distributed_method(join_dist_algo_);
join->set_anti_or_semi_sel(anti_or_semi_sel_);
out = join;
}
}
return ret;
}
int ObLogJoin::allocate_exchange_post(AllocExchContext* ctx)
{
int ret = OB_SUCCESS;
bool is_basic = false;
uint64_t candidate_method = 0;
EqualSets sharding_input_esets;
ObLogicalOperator* left_child = NULL;
ObLogicalOperator* right_child = NULL;
// join keys and types for hash-hash distribution
ObSEArray<ObRawExpr*, 4> hash_left_join_keys;
ObSEArray<ObRawExpr*, 4> hash_right_join_keys;
ObSEArray<ObExprCalcType, 4> hash_calc_types;
// set keys for non-hash-hash distribution
ObSEArray<ObRawExpr*, 4> left_join_keys;
ObSEArray<ObRawExpr*, 4> right_join_keys;
if (OB_ISNULL(ctx) || OB_ISNULL(get_plan()) || OB_ISNULL(left_child = get_child(first_child)) ||
OB_ISNULL(right_child = get_child(second_child))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), K(ctx), K(get_plan()), K(left_child), K(right_child));
} else if (OB_FAIL(compute_basic_sharding_info(ctx, is_basic))) {
LOG_WARN("failed to compute basic sharding info", K(ret));
} else if (is_basic) {
LOG_TRACE("is basic sharding info", K(sharding_info_));
} else if (OB_FAIL(get_join_keys(*ctx, left_join_keys, right_join_keys))) {
LOG_WARN("failed to get join key", K(ret));
} else if (OB_FAIL(get_hash_hash_distribution_info(hash_left_join_keys, hash_right_join_keys, hash_calc_types))) {
LOG_WARN("failed to get calc types", K(ret));
} else if (OB_FAIL(get_sharding_input_equal_sets(sharding_input_esets))) {
LOG_WARN("failed to get sharding input esets", K(ret));
} else if (OB_FAIL(get_candidate_join_distribution_method(
*get_plan(), sharding_input_esets, left_join_keys, right_join_keys, candidate_method))) {
LOG_WARN("failed to get valid dist method", K(ret));
} else if (OB_FAIL(choose_best_distribution_method(
*ctx, candidate_method, pq_map_hint_, join_dist_algo_, slave_mapping_type_))) {
LOG_WARN("failed to choose best distribution method", K(ret));
} else if (OB_FAIL(compute_sharding_and_allocate_exchange(ctx,
sharding_input_esets,
hash_left_join_keys,
hash_right_join_keys,
hash_calc_types,
left_join_keys,
right_join_keys,
*left_child,
*right_child,
join_dist_algo_,
slave_mapping_type_,
join_type_,
sharding_info_))) {
LOG_WARN("failed to compute sharding and allocate exchange", K(ret));
} else {
is_partition_wise_ = (join_dist_algo_ == JoinDistAlgo::DIST_PARTITION_WISE) && !use_slave_mapping();
}
if (OB_SUCC(ret)) {
if (is_nlj_without_param_down() && join_type_ != CONNECT_BY_JOIN &&
(!left_child->get_is_at_most_one_row() || join_dist_algo_ != JoinDistAlgo::DIST_PULL_TO_LOCAL) &&
OB_FAIL(check_and_allocate_material(second_child))) {
LOG_WARN("failed to check whether need material", K(ret));
} else if (OB_FAIL(update_weak_part_exprs(ctx))) {
LOG_WARN("failed to update weak part exprs", K(ret));
} else {
sharding_info_.set_can_reselect_replica(false);
}
}
return ret;
}
int ObLogJoin::build_gi_partition_pruning()
{
int ret = OB_SUCCESS;
ObLogicalOperator* op = NULL;
if (OB_FAIL(get_child(second_child)->find_first_recursive(LOG_GRANULE_ITERATOR, op))) {
LOG_WARN("find granule iterator in right failed", K(ret));
} else if (NULL == op) {
// granule iterator not found, do nothing
} else {
static_cast<ObLogGranuleIterator*>(op)->add_flag(GI_ENABLE_PARTITION_PRUNING);
}
return ret;
}
int ObLogJoin::get_join_keys(
const AllocExchContext& ctx, ObIArray<ObRawExpr*>& left_key, ObIArray<ObRawExpr*>& right_key)
{
int ret = OB_SUCCESS;
ObSEArray<ObRawExpr*, 8> conditions;
ObSEArray<ObRawExpr*, 8> normal_conds;
ObSEArray<ObRawExpr*, 8> nullsafe_conds;
ObSEArray<ObRawExpr*, 8> nullsafe_left_key;
ObSEArray<ObRawExpr*, 8> nullsafe_right_key;
ObLogicalOperator* left_child = NULL;
ObLogicalOperator* right_child = NULL;
if (OB_ISNULL(left_child = get_child(first_child)) || OB_ISNULL(right_child = get_child(second_child))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(left_child), K(right_child), K(ret));
} else if (OB_FAIL(append(conditions, get_equal_join_conditions())) ||
OB_FAIL(append(conditions, get_other_join_conditions())) ||
OB_FAIL(append(conditions, right_child->get_pushdown_filter_exprs()))) {
LOG_WARN("failed to get all conditions", K(ret));
} else if (OB_FAIL(ObOptimizerUtil::classify_equal_conds(conditions, normal_conds, nullsafe_conds))) {
LOG_WARN("failed to classify equal conditions", K(ret));
} else if (OB_FAIL(ObOptimizerUtil::get_equal_keys(normal_conds, left_child->get_table_set(), left_key, right_key))) {
LOG_WARN("failed to get equal keys", K(ret));
} else if (OB_FAIL(ObOptimizerUtil::get_equal_keys(
nullsafe_conds, left_child->get_table_set(), nullsafe_left_key, nullsafe_right_key))) {
LOG_WARN("failed to get equal keys", K(ret));
} else if (OB_FAIL(prune_weak_part_exprs(ctx, nullsafe_left_key, nullsafe_right_key, left_key, right_key))) {
LOG_WARN("failed to prune weak part exprs", K(ret));
}
return ret;
}
int ObLogJoin::get_hash_hash_distribution_info(
ObIArray<ObRawExpr*>& left_keys, ObIArray<ObRawExpr*>& right_keys, ObIArray<ObExprCalcType>& calc_types)
{
int ret = OB_SUCCESS;
ObLogicalOperator* left_child = NULL;
if (OB_ISNULL(left_child = get_child(first_child))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(left_child), K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < join_conditions_.count(); i++) {
ObRawExpr* expr = NULL;
ObRawExpr* left_expr = NULL;
ObRawExpr* right_expr = NULL;
if (OB_ISNULL(expr = join_conditions_.at(i))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else if (!expr->has_flag(IS_JOIN_COND)) {
/*do nothing*/
} else if (OB_UNLIKELY(2 != expr->get_param_count()) || OB_ISNULL(left_expr = expr->get_param_expr(0)) ||
OB_ISNULL(right_expr = expr->get_param_expr(1))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), K(left_expr), K(right_expr), K(expr->get_param_count()));
} else if (OB_FAIL(calc_types.push_back(expr->get_result_type().get_calc_meta()))) {
LOG_WARN("failed to push back result type", K(ret));
} else {
if (!left_expr->get_relation_ids().is_subset(left_child->get_table_set())) {
std::swap(left_expr, right_expr);
}
if (OB_FAIL(left_keys.push_back(left_expr))) {
LOG_WARN("failed to push back exprs", K(ret));
} else if (OB_FAIL(right_keys.push_back(right_expr))) {
LOG_WARN("failed to push back expr", K(ret));
} else { /*do nothing*/
}
}
}
}
return ret;
}
// only merge join will invoke this func to construct ordering of new_added sorting
int ObLogJoin::make_sort_keys(ObIArray<ObRawExpr*>& sort_expr, ObIArray<OrderItem>& order_keys)
{
int ret = OB_SUCCESS;
int64_t sort_expr_count = sort_expr.count();
int64_t direction_count = merge_directions_.count();
if (MERGE_JOIN != get_join_algo()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("only merge join will invoke this function", K(get_join_algo()), K(ret));
} else if (direction_count <= 0) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("in merge join direction count should be positive", K(direction_count), K(ret));
} else if (sort_expr_count < direction_count) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("sort expr count should no less than direction count", K(sort_expr_count), K(direction_count), K(ret));
} else {
OrderItem order_item;
for (int64_t i = 0; OB_SUCC(ret) && i < direction_count; ++i) {
order_item.reset();
order_item.expr_ = sort_expr.at(i);
order_item.order_type_ = merge_directions_.at(i);
if (OB_FAIL(order_keys.push_back(order_item))) {
LOG_WARN("failed to push back order item", K(i), K(order_item), K(ret));
}
}
for (int64_t j = direction_count; OB_SUCC(ret) && j < sort_expr_count; ++j) {
order_item.reset();
order_item.expr_ = sort_expr.at(j);
order_item.order_type_ = default_asc_direction();
if (OB_FAIL(order_keys.push_back(order_item))) {
LOG_WARN("failed to push back order item", K(j), K(order_item), K(ret));
}
}
}
return ret;
}
int ObLogJoin::allocate_expr_pre(ObAllocExprContext& ctx)
{
int ret = OB_SUCCESS;
ObSEArray<ObRawExpr*, 8> exprs;
ObSEArray<ObRawExpr*, 8> left_join_exprs;
ObSEArray<ObRawExpr*, 8> right_join_exprs;
ObLogicalOperator* first_child = NULL;
ObLogicalOperator* second_child = NULL;
uint64_t left_producer_id = OB_INVALID_ID;
uint64_t right_producer_id = OB_INVALID_ID;
if (OB_ISNULL(first_child = get_child(0)) || OB_ISNULL(second_child = get_child(1)) || OB_ISNULL(get_stmt())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(first_child), K(second_child), K(get_stmt()), K(ret));
} else if (OB_FAIL(get_next_producer_id(first_child, left_producer_id))) {
LOG_WARN("failed to get next producer id", K(ret));
} else if (OB_FAIL(get_next_producer_id(second_child, right_producer_id))) {
LOG_WARN("failed to get next producer id", K(ret));
} else if (OB_FAIL(append(exprs, join_filters_))) {
LOG_WARN("failed to append exprs", K(ret));
} else if (OB_FAIL(append(exprs, join_conditions_))) {
LOG_WARN("failed to append exprs", K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < nl_params_.count(); i++) {
if (OB_ISNULL(nl_params_.at(i).second)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else if (OB_FAIL(exprs.push_back(nl_params_.at(i).second))) {
LOG_WARN("failed to push back expr", K(ret));
} else { /*do nothing*/
}
}
for (int64_t i = 0; OB_SUCC(ret) && i < join_conditions_.count(); i++) {
ObRawExpr* raw_expr = NULL;
if (OB_ISNULL(raw_expr = join_conditions_.at(i))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else {
for (int64_t j = 0; OB_SUCC(ret) && j < raw_expr->get_param_count(); j++) {
ObRawExpr* temp_expr = NULL;
if (OB_ISNULL(temp_expr = raw_expr->get_param_expr(j))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else if (temp_expr->has_flag(IS_COLUMN)) {
/*do nothing*/
} else if (temp_expr->get_relation_ids().is_subset(first_child->get_table_set())) {
ret = left_join_exprs.push_back(temp_expr);
} else if (temp_expr->get_relation_ids().is_subset(second_child->get_table_set())) {
ret = right_join_exprs.push_back(temp_expr);
} else {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected error",
K(temp_expr->get_relation_ids()),
K(first_child->get_table_set()),
K(second_child->get_table_set()),
K(ret));
}
}
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(add_exprs_to_ctx(ctx, exprs))) {
LOG_WARN("failed to add exprs to ctx", K(ret));
} else if (OB_FAIL(ObLogicalOperator::allocate_expr_pre(ctx))) {
LOG_WARN("failed to allocate expr", K(ret));
} else if (OB_FAIL(add_exprs_to_ctx(ctx, left_join_exprs, left_producer_id))) {
LOG_WARN("failed to add exprs to ctx", K(ret));
} else if (OB_FAIL(add_exprs_to_ctx(ctx, right_join_exprs, right_producer_id))) {
LOG_WARN("faiiled to add exprs to ctx", K(ret));
}
}
if (OB_SUCC(ret) && CONNECT_BY_JOIN == join_type_ && get_stmt()->is_select_stmt()) {
ObSelectStmt* select_stmt = static_cast<ObSelectStmt*>(get_stmt());
ObSEArray<ObRawExpr*, 4> left_extra_exprs;
ObSEArray<ObRawExpr*, 4> right_extra_exprs;
int64_t child_expr_count = connect_by_extra_exprs_.count() / 2;
if (OB_UNLIKELY(child_expr_count * 2 != connect_by_extra_exprs_.count())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("invalid child expr size", K(ret));
}
for (int64_t i = 0; OB_SUCC(ret) && i < child_expr_count; ++i) {
ObRawExpr* left = connect_by_extra_exprs_.at(i);
ObRawExpr* right = connect_by_extra_exprs_.at(i + child_expr_count);
if (OB_ISNULL(left) || OB_ISNULL(right)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("invalid extra expr", K(ret));
} else if (OB_FAIL(left_extra_exprs.push_back(left))) {
LOG_WARN("failed to push left expr", K(ret));
} else if (OB_FAIL(right_extra_exprs.push_back(right))) {
LOG_WARN("failed to push right expr", K(ret));
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(add_exprs_to_ctx(ctx, left_extra_exprs, left_producer_id))) {
LOG_WARN("failed to add exprs to ctx", K(ret));
} else if (OB_FAIL(add_exprs_to_ctx(ctx, right_extra_exprs, right_producer_id))) {
LOG_WARN("failed to add exprs to ctx", K(ret));
}
}
if (OB_SUCC(ret)) {
ObSEArray<ObRawExpr*, 8> param_exprs;
for (int64_t i = 0; OB_SUCC(ret) && i < ctx.expr_producers_.count(); ++i) {
ExprProducer& producer = ctx.expr_producers_.at(i);
if (OB_ISNULL(producer.expr_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else if (OB_INVALID_ID == producer.producer_id_ &&
((producer.expr_->has_flag(IS_CONNECT_BY_ROOT)) ||
(producer.expr_->has_flag(IS_SYS_CONNECT_BY_PATH)) || (producer.expr_->has_flag(IS_PRIOR)) ||
(producer.expr_->has_flag(IS_PSEUDO_COLUMN) &&
static_cast<const ObPseudoColumnRawExpr*>(producer.expr_)
->is_hierarchical_query_type()))) {
producer.producer_id_ = id_;
for (int64_t j = 0; OB_SUCC(ret) && j < producer.expr_->get_param_count(); j++) {
bool should_add = false;
ObRawExpr* param_expr = const_cast<ObRawExpr*>(producer.expr_->get_param_expr(j));
if (OB_ISNULL(param_expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("param expr is null", K(ret));
} else if (OB_FAIL(check_param_expr_should_be_added(param_expr, should_add))) {
LOG_WARN("failed to check whether param expr can be added", K(ret));
} else if (should_add && OB_FAIL(param_exprs.push_back(param_expr))) {
LOG_WARN("array push back failed", K(ret));
}
}
}
}
if (OB_SUCC(ret) && OB_FAIL(add_exprs_to_ctx(ctx, param_exprs))) {
LOG_WARN("failed to add exprs to ctx", K(ret));
}
}
}
if (OB_SUCC(ret) && get_plan() && can_enable_gi_partition_pruning()) {
if (OB_FAIL(alloc_partition_id_column(ctx))) {
LOG_WARN("fail alloc part id expr for gi pruning", K(ret));
}
}
}
return ret;
}
uint64_t ObLogJoin::hash(uint64_t seed) const
{
seed = ObOptimizerUtil::hash_exprs(seed, join_conditions_);
seed = ObOptimizerUtil::hash_exprs(seed, join_filters_);
seed = do_hash(join_type_, seed);
seed = do_hash(join_algo_, seed);
seed = do_hash(late_mat_, seed);
HASH_ARRAY(merge_directions_, seed);
for (int64_t i = 0; i < nl_params_.count(); i++) {
seed = do_hash(nl_params_.at(i).first, seed);
if (NULL != nl_params_.at(i).second) {
seed = do_hash(*nl_params_.at(i).second, seed);
}
}
HASH_PTR_ARRAY(pseudo_columns_, seed);
seed = ObOptimizerUtil::hash_exprs(seed, connect_by_prior_exprs_);
HASH_ARRAY(left_expected_ordering_, seed);
HASH_ARRAY(right_expected_ordering_, seed);
seed = ObLogicalOperator::hash(seed);
seed = ObOptimizerUtil::hash_exprs(seed, connect_by_extra_exprs_);
return seed;
}
int32_t ObLogJoin::get_explain_name_length() const
{
int32_t length = 0;
if (NESTED_LOOP_JOIN == join_algo_) {
length += (int32_t)strlen("NESTED-LOOP ");
} else if (HASH_JOIN == join_algo_) {
length += (int32_t)strlen("HASH ");
} else {
length += (int32_t)strlen("MERGE ");
}
length += (int32_t)strlen(ob_join_type_str(join_type_));
if (is_cartesian()) {
++length;
length += (int32_t)strlen("CARTESIAN");
}
return length;
}
int ObLogJoin::get_explain_name_internal(char* buf, const int64_t buf_len, int64_t& pos)
{
int ret = OB_SUCCESS;
if (NESTED_LOOP_JOIN == join_algo_) {
ret = BUF_PRINTF("NESTED-LOOP ");
} else if (HASH_JOIN == join_algo_) {
ret = BUF_PRINTF("HASH ");
} else {
ret = BUF_PRINTF("MERGE ");
}
if (OB_SUCC(ret)) {
ret = BUF_PRINTF("%s", ob_join_type_str(join_type_));
} else { /* Do nothing */
}
if (OB_SUCC(ret) && is_cartesian()) {
ret = BUF_PRINTF(" ");
if (OB_SUCC(ret)) {
ret = BUF_PRINTF("CARTESIAN");
} else { /* Do nothing */
}
} else { /* Do nothing */
}
if (OB_FAIL(ret)) {
LOG_WARN("BUF_PRINTF fails unexpectedly", K(ret));
} else { /* Do nothing */
}
return ret;
}
int ObLogJoin::print_my_plan_annotation(char* buf, int64_t& buf_len, int64_t& pos, ExplainType type)
{
int ret = OB_SUCCESS;
if (OB_FAIL(BUF_PRINTF(", "))) {
LOG_WARN("BUF_PRINTF fails", K(ret));
} else if (OB_FAIL(BUF_PRINTF("\n "))) {
LOG_WARN("BUF_PRINTF fails", K(ret));
} else { /* Do nothing */
}
if (OB_SUCC(ret)) {
if (NESTED_LOOP_JOIN == get_join_algo()) {
const ObIArray<ObRawExpr*>& conds = get_other_join_conditions();
EXPLAIN_PRINT_EXPRS(conds, type);
if (OB_SUCC(ret)) {
if (OB_FAIL(BUF_PRINTF(", "))) {
LOG_WARN("BUF_PRINTF fails", K(ret));
} else { /* Do nothing */
}
} else { /* Do nothing */
}
if (OB_SUCC(ret)) {
EXPLAIN_PRINT_EXEC_PARAMS(nl_params_, type);
} else { /* Do nothing */
}
if (OB_SUCC(ret) && (EXPLAIN_EXTENDED == type || EXPLAIN_EXTENDED_NOADDR == type)) {
bool use_batch_nlj = false;
if (OB_FAIL(can_use_batch_nlj(use_batch_nlj))) {
LOG_WARN("Failed to check use batch nlj", K(ret));
} else if (OB_FAIL(BUF_PRINTF(", "))) {
LOG_WARN("BUF_PRINTF fails", K(ret));
} else if (OB_FAIL(BUF_PRINTF("batch_join=%s", use_batch_nlj ? "true" : "false"))) {
LOG_WARN("BUF_PRINTF fails", K(ret));
} else { /* Do nothing */
}
}
} else if (HASH_JOIN == get_join_algo()) {
const ObIArray<ObRawExpr*>& equal_conds = get_equal_join_conditions();
EXPLAIN_PRINT_EXPRS(equal_conds, type);
if (OB_SUCC(ret)) {
if (OB_FAIL(BUF_PRINTF(", "))) {
LOG_WARN("BUF_PRINTF fails", K(ret));
} else { /* Do nothing */
}
} else { /* Do nothing */
}
const ObIArray<ObRawExpr*>& other_conds = get_other_join_conditions();
EXPLAIN_PRINT_EXPRS(other_conds, type);
} else {
const ObIArray<ObRawExpr*>& equal_conds = get_equal_join_conditions();
EXPLAIN_PRINT_EXPRS(equal_conds, type);
if (OB_SUCC(ret)) {
if (OB_FAIL(BUF_PRINTF(", "))) {
LOG_WARN("BUF_PRINTF fails", K(ret));
} else { /* Do nothing */
}
} else { /* Do nothing */
}
const ObIArray<ObRawExpr*>& other_conds = get_other_join_conditions();
EXPLAIN_PRINT_EXPRS(other_conds, type);
if (OB_SUCC(ret) && EXPLAIN_EXTENDED == type) {
const ObIArray<ObOrderDirection>& merge_directions = get_merge_directions();
if (OB_FAIL(BUF_PRINTF(", "))) {
LOG_WARN("BUF_PRINTF fails", K(ret));
} else if (OB_FAIL(BUF_PRINTF("\n "))) {
LOG_WARN("BUF_PRINTF fails", K(ret));
} else { /* Do nothing */
}
if (OB_SUCC(ret)) {
EXPLAIN_PRINT_MERGE_DIRECTIONS(merge_directions);
} else { /* Do nothing */
}
} else { /* Do nothing */
}
}
} else { /* Do nothing */
}
return ret;
}
int ObLogJoin::check_output_dep_specific(ObRawExprCheckDep& checker)
{
int ret = OB_SUCCESS;
// join conditions
for (int64_t i = 0; OB_SUCC(ret) && i < join_conditions_.count(); i++) {
if (OB_ISNULL(join_conditions_.at(i))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("join_conditions_.at(i) is null", K(ret), K(i));
} else if (OB_FAIL(checker.check(*join_conditions_.at(i)))) {
LOG_WARN("failed to check join_conditions expr", K(ret), K(i));
} else {
}
}
// join filters
for (int64_t i = 0; OB_SUCC(ret) && i < join_filters_.count(); i++) {
if (OB_ISNULL(join_filters_.at(i))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("join_filters_.at(i) is null", K(ret), K(i));
} else if (OB_FAIL(checker.check(*join_filters_.at(i)))) {
LOG_WARN("failed to check join_filters expr", K(ret), K(i));
} else {
}
}
// nl params
for (int64_t i = 0; OB_SUCC(ret) && i < nl_params_.count(); i++) {
if (OB_ISNULL(nl_params_.at(i).second)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("nl_params_.at(i).second is null", K(ret), K(i));
} else if (OB_FAIL(checker.check(*nl_params_.at(i).second))) {
LOG_WARN("failed to check nl params expr", K(ret), K(i));
} else {
}
}
// nlj right gi pruning feature
if (OB_SUCC(ret) && is_enable_gi_partition_pruning()) {
if (OB_ISNULL(partition_id_expr_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("null unexpected", K(ret));
} else if (OB_FAIL(checker.check(*partition_id_expr_))) {
LOG_WARN("fail to check partition id expr", K(ret));
}
}
// add extra output exprs for connect join
if (CONNECT_BY_JOIN == join_type_) {
for (int64_t i = 0; OB_SUCC(ret) && i < connect_by_extra_exprs_.count(); i++) {
if (OB_ISNULL(connect_by_extra_exprs_.at(i))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else if (OB_FAIL(checker.check(*connect_by_extra_exprs_.at(i)))) {
LOG_WARN("failed to check extra output expr", K(ret));
} else { /*do nothing*/
}
}
}
return ret;
}
int ObLogJoin::inner_replace_generated_agg_expr(const ObIArray<std::pair<ObRawExpr*, ObRawExpr*> >& to_replace_exprs)
{
int ret = OB_SUCCESS;
if (OB_FAIL(replace_exprs_action(to_replace_exprs, get_join_conditions()))) {
LOG_WARN("failed to extract subplan params in log join_conditions", K(ret));
} else if (OB_FAIL(replace_exprs_action(to_replace_exprs, get_join_filters()))) {
LOG_WARN("failed to extract subplan params in log join_filters", K(ret));
} else {
int64_t N = get_nl_params().count();
for (int64_t i = 0; OB_SUCC(ret) && i < N; ++i) {
ObRawExpr*& cur_expr = get_nl_params().at(i).second;
if (OB_FAIL(replace_expr_action(to_replace_exprs, cur_expr))) {
LOG_WARN("failed to extract subplan params in log join_filters", K(ret));
} else { /* Do nothing */
}
}
}
return ret;
}
int ObLogJoin::set_left_expected_ordering(const common::ObIArray<OrderItem>& left_expected_ordering)
{
int ret = OB_SUCCESS;
left_expected_ordering_.reset();
for (int i = 0; OB_SUCC(ret) && i < left_expected_ordering.count(); ++i) {
if (OB_FAIL(left_expected_ordering_.push_back(left_expected_ordering.at(i)))) {
LOG_WARN("failed to push back order item", K(ret));
}
}
return ret;
}
int ObLogJoin::set_right_expected_ordering(const common::ObIArray<OrderItem>& right_expected_ordering)
{
int ret = OB_SUCCESS;
right_expected_ordering_.reset();
for (int i = 0; OB_SUCC(ret) && i < right_expected_ordering.count(); ++i) {
if (OB_FAIL(right_expected_ordering_.push_back(right_expected_ordering.at(i)))) {
LOG_WARN("failed to push back order item", K(ret));
}
}
return ret;
}
int ObLogJoin::transmit_op_ordering()
{
int ret = OB_SUCCESS;
reset_op_ordering();
reset_local_ordering();
ObLogicalOperator* left_child = get_child(first_child);
ObLogicalOperator* right_child = get_child(second_child);
if (OB_ISNULL(left_child) || OB_ISNULL(right_child)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("left_child or right_child is null", K(ret));
} else if (NESTED_LOOP_JOIN == get_join_algo()) { // nl keep left
if (OB_FAIL(set_op_ordering(left_child->get_op_ordering()))) {
LOG_WARN("failed to set op ordering", K(ret));
} else { /*do nothing*/
}
} else if (HASH_JOIN == get_join_algo()) { // hash join can not keep order
/*do nothing*/
} else if (MERGE_JOIN == get_join_algo()) { // merge
bool left_need_sort = true;
bool right_need_sort = true;
if (OB_FAIL(check_need_sort_below_node(0, left_expected_ordering_, left_need_sort))) {
LOG_WARN("failed to check need sort", K(ret));
} else if (left_need_sort) {
if (OB_FAIL(allocate_sort_below(0, left_expected_ordering_))) { // include set op ordering
LOG_WARN("failed to allocate implicit sort", K(ret));
}
}
if (OB_SUCC(ret)) { // check right
if (OB_FAIL(check_need_sort_below_node(1, right_expected_ordering_, right_need_sort))) {
LOG_WARN("failed to check if need sort", K(ret));
} else if (right_need_sort) {
if (OB_FAIL(allocate_sort_below(1, right_expected_ordering_))) {
LOG_WARN("failed to allocate implicit sort", K(ret));
}
}
}
if (OB_SUCC(ret)) { // set merge join's op_ordering
if (INNER_JOIN == join_type_ || LEFT_OUTER_JOIN == join_type_ || LEFT_SEMI_JOIN == join_type_ ||
LEFT_ANTI_JOIN == join_type_) {
if (left_need_sort) {
if (OB_FAIL(set_op_ordering(left_expected_ordering_))) {
LOG_WARN("failed to set op ordering", K(ret));
}
} else if (OB_FAIL(set_op_ordering(get_child(first_child)->get_op_ordering()))) {
LOG_WARN("failed to set op ordering", K(ret));
}
}
}
}
return ret;
}
int ObLogJoin::re_calc_cost()
{
int ret = OB_SUCCESS;
JoinAlgo algo = get_join_algo();
const ObLogicalOperator* first_child = get_child(ObLogicalOperator::first_child);
const ObLogicalOperator* second_child = get_child(ObLogicalOperator::second_child);
if (OB_ISNULL(get_plan()) || OB_ISNULL(first_child) || OB_ISNULL(second_child)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(first_child), K(second_child), K(get_plan()), K(ret));
} else if (MERGE_JOIN == algo || HASH_JOIN == algo ||
(NESTED_LOOP_JOIN == algo && LOG_MATERIAL == second_child->get_type())) {
set_cost(first_child->get_cost() + second_child->get_cost() + get_op_cost());
} else {
double op_cost = 0;
double nl_cost = 0;
bool need_mat = (log_op_def::LOG_MATERIAL == second_child->get_type());
double anti_or_semi_sel;
if (join_type_ == LEFT_SEMI_JOIN || join_type_ == LEFT_ANTI_JOIN) {
anti_or_semi_sel = anti_or_semi_sel_;
} else {
anti_or_semi_sel = 1.0;
}
ObCostNLJoinInfo est_cost_info(first_child->get_card(),
first_child->get_cost(),
first_child->get_width(),
second_child->get_card(),
second_child->get_cost(),
second_child->get_width(),
first_child->get_table_set(),
second_child->get_table_set(),
join_type_,
anti_or_semi_sel,
nl_params_.count() > 0,
need_mat,
join_conditions_,
join_filters_,
get_est_sel_info());
if (OB_FAIL(
ObOptEstCost::cost_nestloop(est_cost_info, op_cost, nl_cost, &get_plan()->get_predicate_selectivities()))) {
LOG_WARN("failed to get nestloop cost", K(ret));
} else {
cost_ = nl_cost;
op_cost_ = op_cost;
}
}
return ret;
}
int ObLogJoin::re_est_cost(const ObLogicalOperator* parent, double need_row_count, bool& re_est)
{
int ret = OB_SUCCESS;
UNUSED(parent);
re_est = false;
bool left_child_re_est = false;
bool right_child_re_est = false;
ObLogicalOperator* left_child = NULL;
ObLogicalOperator* right_child = NULL;
if (OB_ISNULL(get_plan())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("null plan", K(get_plan()));
} else if (need_row_count >= get_card()) {
/* do nothing */
} else if (OB_ISNULL(left_child = get_child(first_child)) || OB_ISNULL(right_child = get_child(second_child))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), K(left_child), K(right_child));
} else if (MERGE_JOIN == join_algo_) {
double left_need_rows = sqrt(need_row_count / get_card()) * left_child->get_card();
double right_need_rows = sqrt(need_row_count / get_card()) * right_child->get_card();
if (OB_FAIL(left_child->re_est_cost(this, left_need_rows, left_child_re_est))) {
LOG_WARN("re-estimate cost left child failed", K(ret));
} else if (OB_FAIL(right_child->re_est_cost(this, right_need_rows, right_child_re_est))) {
LOG_WARN("re-estimate cost right child failed", K(ret));
} else {
ObSEArray<OrderItem, 4, ModulePageAllocator, true> dummy_need_ordering;
ObIArray<OrderItem>* left_need_ordering = &dummy_need_ordering;
ObIArray<OrderItem>* right_need_ordering = &dummy_need_ordering;
if (left_child->get_type() == LOG_SORT) {
left_need_ordering = &(static_cast<ObLogSort*>(left_child)->get_sort_keys());
}
if (right_child->get_type() == LOG_SORT) {
right_need_ordering = &(static_cast<ObLogSort*>(right_child)->get_sort_keys());
}
ObCostMergeJoinInfo est_cost_info(left_child->get_card(),
left_child->get_cost(),
left_child->get_width(),
right_child->get_card(),
right_child->get_cost(),
right_child->get_width(),
left_child->get_table_set(),
right_child->get_table_set(),
join_type_,
join_conditions_,
join_filters_,
*left_need_ordering,
*right_need_ordering,
get_est_sel_info());
double op_cost = 0.0;
double mj_cost = 0.0;
if (OB_ISNULL(get_plan())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("plan is NULL", K(ret));
} else if (OB_FAIL(ObOptEstCost::cost_mergejoin(
est_cost_info, op_cost, mj_cost, &get_plan()->get_predicate_selectivities()))) {
LOG_WARN("cost merge failed", K(ret));
} else if (OB_UNLIKELY(op_cost > mj_cost)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("op cost > all merge join cost, unexpected", K(ret));
} else {
op_cost_ = op_cost;
cost_ = mj_cost;
card_ = need_row_count;
}
}
} else if (HASH_JOIN == join_algo_) {
if (LEFT_SEMI_JOIN == join_type_ || LEFT_ANTI_JOIN == join_type_) {
// do nothing
} else {
double op_cost = 0.0;
double hash_cost = 0.0;
double right_need_rows = (need_row_count / get_card()) * right_child->get_card();
if (OB_FAIL(right_child->re_est_cost(this, right_need_rows, right_child_re_est))) {
LOG_WARN("Failed to re est cost", K(ret));
} else {
ObCostHashJoinInfo est_cost_info(left_child->get_card(),
left_child->get_cost(),
left_child->get_width(),
right_child->get_card(),
right_child->get_cost(),
right_child->get_width(),
left_child->get_table_set(),
right_child->get_table_set(),
join_type_,
join_conditions_,
join_filters_,
get_est_sel_info());
if (OB_FAIL(ObOptEstCost::cost_hashjoin(
est_cost_info, op_cost, hash_cost, &get_plan()->get_predicate_selectivities()))) {
LOG_WARN("failed to get hashjoin cost", K(ret));
} else {
cost_ = hash_cost;
op_cost_ = op_cost;
card_ = need_row_count;
re_est = true;
}
}
}
} else if (NESTED_LOOP_JOIN == join_algo_) {
double left_need_rows = (need_row_count / get_card()) * left_child->get_card();
double op_cost = 0.0;
double nl_cost = 0.0;
double anti_or_semi_sel;
if (join_type_ == LEFT_SEMI_JOIN || join_type_ == LEFT_ANTI_JOIN) {
anti_or_semi_sel = anti_or_semi_sel_;
} else {
anti_or_semi_sel = 1.0;
}
if (OB_FAIL(left_child->re_est_cost(this, left_need_rows, left_child_re_est))) {
LOG_WARN("Failed to re est cost", K(ret));
} else {
double right_child_cost = right_child->get_cost();
bool need_mat = (log_op_def::LOG_MATERIAL == right_child->get_type());
if (need_mat) {
if (OB_ISNULL(right_child->get_child(first_child))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("material child should not be NULL", K(ret));
} else {
right_child_cost = right_child->get_child(first_child)->get_cost();
}
}
if (OB_FAIL(ret)) {
// do nothing
} else {
ObCostNLJoinInfo est_cost_info(left_need_rows,
left_child->get_cost(),
left_child->get_width(),
right_child->get_card(),
right_child_cost,
right_child->get_width(),
left_child->get_table_set(),
right_child->get_table_set(),
join_type_,
anti_or_semi_sel,
nl_params_.count() > 0,
need_mat,
join_conditions_,
join_filters_,
get_est_sel_info());
if (OB_FAIL(ObOptEstCost::cost_nestloop(
est_cost_info, op_cost, nl_cost, &get_plan()->get_predicate_selectivities()))) {
LOG_WARN("failed to get nestloop cost", K(ret));
} else {
cost_ = nl_cost;
op_cost_ = op_cost;
card_ = need_row_count;
re_est = true;
}
}
}
} else {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unrecognized type of join algorithm", K(ret), K_(join_algo));
}
return ret;
}
int ObLogJoin::print_use_late_materialization(planText& plan_text)
{
int ret = OB_SUCCESS;
char* buf = plan_text.buf;
int64_t& buf_len = plan_text.buf_len;
int64_t& pos = plan_text.pos;
bool is_one_line = plan_text.is_oneline_;
OutlineType outline_type = plan_text.outline_type_;
if (OB_ISNULL(stmt_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("stmt is NULL");
} else if (is_late_mat()) {
ObStmtHint& stmt_hint = stmt_->get_stmt_hint();
if (OUTLINE_DATA == outline_type ||
(USED_HINT == outline_type && stmt_hint.use_late_mat_ == OB_USE_LATE_MATERIALIZATION)) {
stmt_hint.use_late_mat_ = OB_USE_LATE_MATERIALIZATION;
if (!is_one_line && OB_FAIL(BUF_PRINTF("\n"))) {
} else if (OB_FAIL(BUF_PRINTF(ObStmtHint::get_outline_indent(is_one_line)))) {
} else if (OB_FAIL(BUF_PRINTF(ObStmtHint::USE_LATE_MATERIALIZATION))) {
LOG_WARN("fail to print outline", K(ret));
} else { /*do thing*/
}
}
}
return ret;
}
int ObLogJoin::print_outline(planText& plan_text)
{
int ret = OB_SUCCESS;
if (GET_MIN_CLUSTER_VERSION() < CLUSTER_VERSION_3100 && OB_FAIL(print_use_late_materialization(plan_text))) {
LOG_WARN("fail to print use late materialization", K(ret));
} else if (is_added_outline_) { // do nothing.
} else if (OB_FAIL(print_leading(plan_text, LEFT_DEEP))) {
LOG_WARN("fail to print leading", K(ret));
} else if (OB_FAIL(print_use_join(plan_text, LEFT_DEEP, false))) {
LOG_WARN("fail to print join method", K(ret));
} else if (OB_FAIL(print_pq_distribute(plan_text, LEFT_DEEP, false))) {
LOG_WARN("fail to print pq distribute", K(ret));
} else if (OB_FAIL(print_material_nl(plan_text, LEFT_DEEP, false))) {
LOG_WARN("fail to print material nl", K(ret));
} else if (OB_FAIL(print_pq_map(plan_text, LEFT_DEEP, false))) {
LOG_WARN("fail to print pq distribute", K(ret));
} else { /*do nothing*/
}
return ret;
}
int ObLogJoin::print_material_nl(planText& plan_text, JoinTreeType join_tree_type, bool is_need_print)
{
int ret = OB_SUCCESS;
char* buf = plan_text.buf;
int64_t& buf_len = plan_text.buf_len;
int64_t& pos = plan_text.pos;
bool is_oneline = plan_text.is_oneline_;
if (OB_ISNULL(stmt_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("stmt is NULL", K(ret));
} else {
bool is_need = false;
bool need_mat = false;
ObStmtHint& stmt_hint = stmt_->get_stmt_hint();
if (OB_FAIL(is_need_print_material_nl(plan_text, stmt_hint, is_need, need_mat))) {
LOG_WARN("fail to judge whether need print use join", K(ret));
} else if (!is_need) {
} else if (!is_oneline && OB_FAIL(BUF_PRINTF("\n"))) {
} else if (OB_FAIL(BUF_PRINTF(ObStmtHint::get_outline_indent(is_oneline)))) {
} else if (need_mat && OB_FAIL(BUF_PRINTF(ObStmtHint::USE_NL_MATERIAL))) {
} else if (!need_mat && OB_FAIL(BUF_PRINTF(ObStmtHint::NO_USE_NL_MATERIAL))) {
} else if (OB_FAIL(BUF_PRINTF("("))) {
} else if (OB_FAIL(print_qb_name(plan_text))) {
LOG_WARN("fail to print query block name", K(ret));
} else if (OB_FAIL(BUF_PRINTF(" ("))) {
} else if (OB_FAIL(traverse_join_plan_pre(plan_text, MATERIAL_NL, join_tree_type, is_need_print))) {