Skip to content

Commit bb5461d

Browse files
authored
Merge pull request #10662 from sundy-li/sleep
chore(planner): support multi filter pushdown into scan
2 parents f4d21a8 + 367e6ae commit bb5461d

File tree

5 files changed

+51
-28
lines changed

5 files changed

+51
-28
lines changed

src/query/functions/src/scalars/other.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,31 @@ pub fn register(registry: &mut FunctionRegistry) {
9999
"sleep",
100100
FunctionProperty::default(),
101101
|_| FunctionDomain::MayThrow,
102-
vectorize_with_builder_1_arg::<Float64Type, UInt8Type>(move |val, output, ctx| {
103-
let duration = Duration::try_from_secs_f64(val.into()).map_err(|x| x.to_string());
104-
match duration {
105-
Ok(duration) => {
106-
if duration.gt(&Duration::from_secs(300)) {
107-
let err = format!(
108-
"The maximum sleep time is 300 seconds. Requested: {:?}",
109-
duration
110-
);
111-
ctx.set_error(output.len(), err);
112-
output.push(0);
113-
} else {
114-
std::thread::sleep(duration);
115-
output.push(1);
102+
|a, ctx| {
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());
106+
match duration {
107+
Ok(duration) => {
108+
if duration.gt(&Duration::from_secs(300)) {
109+
let err = format!(
110+
"The maximum sleep time is 300 seconds. Requested: {:?}",
111+
duration
112+
);
113+
ctx.set_error(0, err);
114+
} else {
115+
std::thread::sleep(duration);
116+
}
117+
}
118+
Err(e) => {
119+
ctx.set_error(0, e);
116120
}
117121
}
118-
Err(e) => {
119-
ctx.set_error(output.len(), e);
120-
output.push(0);
121-
}
122+
} else {
123+
ctx.set_error(0, "Must be constant value");
122124
}
123-
}),
125+
Value::Scalar(0_u8)
126+
},
124127
);
125128

126129
registry.register_0_arg_core::<NumberType<F64>, _, _>(

src/query/functions/tests/it/scalars/testdata/other.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ output : "DOUBLE"
134134
ast : sleep(2)
135135
raw expr : sleep(2_u8)
136136
checked expr : sleep<Float64>(to_float64<UInt8>(2_u8))
137-
optimized expr : 1_u8
137+
optimized expr : 0_u8
138138
output type : UInt8
139-
output domain : {1..=1}
140-
output : 1
139+
output domain : {0..=0}
140+
output : 0
141141

142142

143143
error:

src/query/sql/src/planner/optimizer/rule/rewrite/rule_push_down_filter_scan.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,16 @@ 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+
let add_filters = self.find_push_down_predicates(&filter.predicates)?;
10098

101-
get.push_down_predicates = Some(self.find_push_down_predicates(&filter.predicates)?);
99+
match get.push_down_predicates.as_mut() {
100+
Some(vs) => vs.extend(add_filters),
101+
None => get.push_down_predicates = Some(add_filters),
102+
}
102103

103-
let result = SExpr::create_unary(filter.into(), SExpr::create_leaf(get.into()));
104+
let mut result = SExpr::create_unary(filter.into(), SExpr::create_leaf(get.into()));
105+
result.set_applied_rule(&self.id);
104106
state.add_result(result);
105-
106107
Ok(())
107108
}
108109

tests/sqllogictests/suites/mode/standalone/explain/select.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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

tests/sqllogictests/suites/mode/standalone/explain/sort.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ Sort
5858
├── output columns: [a]
5959
└── estimated rows: 0.00
6060

61+
6162
statement ok
6263
drop table if exists t1;

0 commit comments

Comments
 (0)