File tree Expand file tree Collapse file tree 4 files changed +32
-11
lines changed
sql/src/planner/optimizer/rule/rewrite
tests/sqllogictests/suites/mode/standalone/explain Expand file tree Collapse file tree 4 files changed +32
-11
lines changed Original file line number Diff line number Diff line change @@ -100,8 +100,9 @@ pub fn register(registry: &mut FunctionRegistry) {
100100 FunctionProperty :: default ( ) ,
101101 |_| FunctionDomain :: MayThrow ,
102102 |a, ctx| {
103- if let Some ( s) = a. as_scalar ( ) {
104- let duration = Duration :: try_from_secs_f64 ( val. into ( ) ) . map_err ( |x| x. to_string ( ) ) ;
103+ if let Some ( val) = a. as_scalar ( ) {
104+ let duration =
105+ Duration :: try_from_secs_f64 ( ( * val) . into ( ) ) . map_err ( |x| x. to_string ( ) ) ;
105106 match duration {
106107 Ok ( duration) => {
107108 if duration. gt ( & Duration :: from_secs ( 300 ) ) {
@@ -110,20 +111,18 @@ pub fn register(registry: &mut FunctionRegistry) {
110111 duration
111112 ) ;
112113 ctx. set_error ( 0 , err) ;
113- Ok ( Value :: Scalar ( Scalar :: Null ( NullType :: UInt8 ) ) )
114114 } else {
115115 std:: thread:: sleep ( duration) ;
116- Ok ( Value :: Scalar ( Scalar :: Value ( UInt8Type :: from ( 1 ) ) ) )
117116 }
118117 }
119118 Err ( e) => {
120119 ctx. set_error ( 0 , e) ;
121- Ok ( Value :: Scalar ( Scalar :: Null ( NullType :: UInt8 ) ) )
122120 }
123121 }
124122 } else {
125123 ctx. set_error ( 0 , "Must be constant value" ) ;
126124 }
125+ Value :: Scalar ( 0_u8 )
127126 } ,
128127 ) ;
129128
Original file line number Diff line number Diff line change @@ -94,15 +94,18 @@ impl Rule for RulePushDownFilterScan {
9494 let filter: Filter = s_expr. plan ( ) . clone ( ) . try_into ( ) ?;
9595 let mut get: Scan = s_expr. child ( 0 ) ?. plan ( ) . clone ( ) . try_into ( ) ?;
9696
97- if get. push_down_predicates . is_some ( ) {
98- return Ok ( ( ) ) ;
99- }
97+ if get. push_down_predicates . is_some ( ) { }
10098
101- get . push_down_predicates = Some ( self . find_push_down_predicates ( & filter. predicates ) ?) ;
99+ let add_filters = self . find_push_down_predicates ( & filter. predicates ) ?;
102100
103- let result = SExpr :: create_unary ( filter. into ( ) , SExpr :: create_leaf ( get. into ( ) ) ) ;
104- state. add_result ( result) ;
101+ match get. push_down_predicates . as_mut ( ) {
102+ Some ( vs) => vs. extend ( add_filters) ,
103+ None => get. push_down_predicates = Some ( add_filters) ,
104+ }
105105
106+ let mut result = SExpr :: create_unary ( filter. into ( ) , SExpr :: create_leaf ( get. into ( ) ) ) ;
107+ result. set_applied_rule ( & self . id ) ;
108+ state. add_result ( result) ;
106109 Ok ( ( ) )
107110 }
108111
Original file line number Diff line number Diff line change @@ -159,3 +159,21 @@ TableScan
159159├── partitions scanned: 1
160160├── push downs: [filters: [], limit: NONE]
161161└── estimated rows: 1.00
162+
163+
164+
165+ query T
166+ explain select * from (select * from numbers(100) where number> 33 ) where 1=2;
167+ ---
168+ ----
169+ Filter
170+ ├── filters: [false, numbers.number (#0) > 33]
171+ ├── estimated rows: 11.11
172+ └── TableScan
173+ ├── table: default.system.numbers
174+ ├── read rows: 0
175+ ├── read bytes: 0
176+ ├── partitions total: 0
177+ ├── partitions scanned: 0
178+ ├── push downs: [filters: [false], limit: NONE]
179+ └── estimated rows: 100.00
Original file line number Diff line number Diff line change 5858 ├── output columns: [a]
5959 └── estimated rows: 0.00
6060
61+
6162statement ok
6263drop table if exists t1;
You can’t perform that action at this time.
0 commit comments