File tree Expand file tree Collapse file tree 4 files changed +21
-7
lines changed Expand file tree Collapse file tree 4 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ use crate::executor::physical_plans::MutationOrganize;
58
58
use crate :: executor:: physical_plans:: MutationSplit ;
59
59
use crate :: executor:: physical_plans:: RowFetch ;
60
60
use crate :: executor:: PhysicalPlanBuilder ;
61
+ use crate :: optimizer:: ir:: RelExpr ;
61
62
use crate :: optimizer:: ir:: SExpr ;
62
63
use crate :: parse_computed_expr;
63
64
use crate :: plans:: BoundColumnRef ;
@@ -283,11 +284,21 @@ impl PhysicalPlanBuilder {
283
284
} ) ) ;
284
285
}
285
286
287
+ let already_enable_lazy_read = {
288
+ let settings = self . ctx . get_settings ( ) ;
289
+ let lazy_read_threshold = settings. get_nondeterministic_update_lazy_read_threshold ( ) ?;
290
+ let rel_expr = RelExpr :: with_s_expr ( s_expr) ;
291
+ let cardinality = rel_expr. derive_cardinality_child ( 0 ) ?;
292
+
293
+ lazy_read_threshold != 0 && lazy_read_threshold >= cardinality. cardinality as u64
294
+ } ;
295
+
286
296
// Construct row fetch plan for lazy columns.
287
- if let Some ( lazy_columns) = self
288
- . metadata
289
- . read ( )
290
- . get_table_lazy_columns ( target_table_index)
297
+ if !already_enable_lazy_read
298
+ && let Some ( lazy_columns) = self
299
+ . metadata
300
+ . read ( )
301
+ . get_table_lazy_columns ( target_table_index)
291
302
&& !lazy_columns. is_empty ( )
292
303
{
293
304
plan = PhysicalPlan :: RowFetch ( build_mutation_row_fetch (
Original file line number Diff line number Diff line change @@ -88,8 +88,8 @@ impl PhysicalPlanBuilder {
88
88
return Err ( ErrorCode :: Internal ( "Internal column _row_id is not found" ) ) ;
89
89
} ;
90
90
91
- let lazy_columns = metadata
92
- . lazy_columns ( )
91
+ let lazy_columns = row_fetch
92
+ . lazy_columns
93
93
. iter ( )
94
94
. filter ( |index| !input_schema. has_field ( & index. to_string ( ) ) ) // If the column is already in the input schema, we don't need to fetch it.
95
95
. cloned ( )
@@ -114,7 +114,8 @@ impl PhysicalPlanBuilder {
114
114
} )
115
115
. collect ( ) ;
116
116
117
- let source = input_plan. try_find_single_data_source ( ) ;
117
+ let metadata = self . metadata . read ( ) ;
118
+ let source = metadata. get_table_source ( & row_fetch. fetch_table_index ) ;
118
119
debug_assert ! ( source. is_some( ) ) ;
119
120
let source_info = source. cloned ( ) . unwrap ( ) ;
120
121
let table_schema = source_info. source_info . schema ( ) ;
Original file line number Diff line number Diff line change @@ -355,6 +355,7 @@ impl Binder {
355
355
need_wrap_nullable : false ,
356
356
row_id_index : row_id. index ,
357
357
lazy_columns : fields_bindings. iter ( ) . map ( |x| x. index ) . collect ( ) ,
358
+ fetch_table_index : mutation. target_table_index ,
358
359
} ) ) ;
359
360
}
360
361
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ pub struct RowFetch {
30
30
31
31
pub lazy_columns : ColumnSet ,
32
32
pub row_id_index : IndexType ,
33
+ pub fetch_table_index : IndexType ,
33
34
}
34
35
35
36
impl Operator for RowFetch {
You can’t perform that action at this time.
0 commit comments