@@ -45,7 +45,6 @@ use databend_common_sql::executor::PhysicalPlan;
45
45
use databend_common_sql:: executor:: PhysicalPlanBuilder ;
46
46
use databend_common_sql:: plans;
47
47
use databend_common_sql:: plans:: MergeInto as MergePlan ;
48
- use databend_common_sql:: plans:: RelOperator ;
49
48
use databend_common_sql:: IndexType ;
50
49
use databend_common_sql:: ScalarExpr ;
51
50
use databend_common_sql:: TypeCheck ;
@@ -60,7 +59,6 @@ use itertools::Itertools;
60
59
use crate :: interpreters:: common:: dml_build_update_stream_req;
61
60
use crate :: interpreters:: HookOperator ;
62
61
use crate :: interpreters:: Interpreter ;
63
- use crate :: interpreters:: InterpreterPtr ;
64
62
use crate :: pipelines:: PipelineBuildResult ;
65
63
use crate :: schedulers:: build_query_pipeline_without_render_result_set;
66
64
use crate :: sessions:: QueryContext ;
@@ -74,8 +72,8 @@ pub struct MergeIntoInterpreter {
74
72
}
75
73
76
74
impl MergeIntoInterpreter {
77
- pub fn try_create ( ctx : Arc < QueryContext > , plan : MergePlan ) -> Result < InterpreterPtr > {
78
- Ok ( Arc :: new ( MergeIntoInterpreter { ctx, plan } ) )
75
+ pub fn try_create ( ctx : Arc < QueryContext > , plan : MergePlan ) -> Result < MergeIntoInterpreter > {
76
+ Ok ( MergeIntoInterpreter { ctx, plan } )
79
77
}
80
78
}
81
79
@@ -125,7 +123,7 @@ impl Interpreter for MergeIntoInterpreter {
125
123
}
126
124
127
125
impl MergeIntoInterpreter {
128
- async fn build_physical_plan ( & self ) -> Result < ( PhysicalPlan , TableInfo ) > {
126
+ pub async fn build_physical_plan ( & self ) -> Result < ( PhysicalPlan , TableInfo ) > {
129
127
let MergePlan {
130
128
bind_context,
131
129
input,
@@ -145,8 +143,10 @@ impl MergeIntoInterpreter {
145
143
split_idx,
146
144
row_id_index,
147
145
can_try_update_column_only,
146
+ enable_right_broadcast,
148
147
..
149
148
} = & self . plan ;
149
+ let enable_right_broadcast = * enable_right_broadcast;
150
150
let mut columns_set = columns_set. clone ( ) ;
151
151
let table = self . ctx . get_table ( catalog, database, table_name) . await ?;
152
152
let fuse_table = table. as_any ( ) . downcast_ref :: < FuseTable > ( ) . ok_or_else ( || {
@@ -211,16 +211,8 @@ impl MergeIntoInterpreter {
211
211
let table_name = table_name. clone ( ) ;
212
212
let input = input. clone ( ) ;
213
213
214
- // we need to extract join plan, but we need to give this exchange
215
- // back at last.
216
- let ( input, extract_exchange) = if let RelOperator :: Exchange ( _) = input. plan ( ) {
217
- ( Box :: new ( input. child ( 0 ) ?. clone ( ) ) , true )
218
- } else {
219
- ( input, false )
220
- } ;
221
-
222
214
let mut builder = PhysicalPlanBuilder :: new ( meta_data. clone ( ) , self . ctx . clone ( ) , false ) ;
223
- let mut join_input = builder. build ( & input, * columns_set. clone ( ) ) . await ?;
215
+ let join_input = builder. build ( & input, * columns_set. clone ( ) ) . await ?;
224
216
225
217
// find row_id column index
226
218
let join_output_schema = join_input. output_schema ( ) ?;
@@ -265,7 +257,7 @@ impl MergeIntoInterpreter {
265
257
}
266
258
}
267
259
268
- if * distributed && ! * change_join_order {
260
+ if enable_right_broadcast {
269
261
row_number_idx = Some ( join_output_schema. index_of ( ROW_NUMBER_COL_NAME ) ?) ;
270
262
}
271
263
@@ -276,7 +268,7 @@ impl MergeIntoInterpreter {
276
268
) ) ;
277
269
}
278
270
279
- if * distributed && row_number_idx. is_none ( ) && ! * change_join_order {
271
+ if enable_right_broadcast && row_number_idx. is_none ( ) {
280
272
return Err ( ErrorCode :: InvalidRowIdIndex (
281
273
"can't get internal row_number_idx when running merge into" ,
282
274
) ) ;
@@ -285,17 +277,6 @@ impl MergeIntoInterpreter {
285
277
let table_info = fuse_table. get_table_info ( ) . clone ( ) ;
286
278
let catalog_ = self . ctx . get_catalog ( catalog) . await ?;
287
279
288
- if !* distributed && extract_exchange {
289
- join_input = PhysicalPlan :: Exchange ( Exchange {
290
- plan_id : 0 ,
291
- input : Box :: new ( join_input) ,
292
- kind : FragmentKind :: Merge ,
293
- keys : vec ! [ ] ,
294
- allow_adjust_parallelism : true ,
295
- ignore_exchange : false ,
296
- } ) ;
297
- } ;
298
-
299
280
// transform unmatched for insert
300
281
// reference to func `build_eval_scalar`
301
282
// (DataSchemaRef, Option<RemoteExpr>, Vec<RemoteExpr>,Vec<usize>) => (source_schema, condition, value_exprs)
@@ -432,6 +413,7 @@ impl MergeIntoInterpreter {
432
413
can_try_update_column_only : * can_try_update_column_only,
433
414
plan_id : u32:: MAX ,
434
415
merge_into_split_idx,
416
+ enable_right_broadcast,
435
417
} ) )
436
418
} else {
437
419
let merge_append = PhysicalPlan :: MergeInto ( Box :: new ( MergeInto {
@@ -444,23 +426,25 @@ impl MergeIntoInterpreter {
444
426
row_id_idx,
445
427
segments : segments. clone ( ) ,
446
428
distributed : true ,
447
- output_schema : match * change_join_order {
448
- false => DataSchemaRef :: new ( DataSchema :: new ( vec ! [
449
- join_output_schema. fields[ row_number_idx. unwrap( ) ] . clone( ) ,
450
- ] ) ) ,
451
- true => DataSchemaRef :: new ( DataSchema :: new ( vec ! [ DataField :: new(
429
+ output_schema : if let Some ( row_number_idx) = row_number_idx {
430
+ DataSchemaRef :: new ( DataSchema :: new ( vec ! [
431
+ join_output_schema. fields[ row_number_idx] . clone( ) ,
432
+ ] ) )
433
+ } else {
434
+ DataSchemaRef :: new ( DataSchema :: new ( vec ! [ DataField :: new(
452
435
ROW_ID_COL_NAME ,
453
436
databend_common_expression:: types:: DataType :: Number (
454
437
databend_common_expression:: types:: NumberDataType :: UInt64 ,
455
438
) ,
456
- ) ] ) ) ,
439
+ ) ] ) )
457
440
} ,
458
441
merge_type : merge_type. clone ( ) ,
459
442
change_join_order : * change_join_order,
460
443
target_build_optimization : false , // we don't support for distributed mode for now..
461
444
can_try_update_column_only : * can_try_update_column_only,
462
445
plan_id : u32:: MAX ,
463
446
merge_into_split_idx,
447
+ enable_right_broadcast,
464
448
} ) ) ;
465
449
// if change_join_order = true, it means the target is build side,
466
450
// in this way, we will do matched operation and not matched operation
0 commit comments