Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query(fuse): limit push down respect orders #4818

Merged
merged 5 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions query/src/storages/fuse/operations/read_partitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,23 @@ impl FuseTable {

pub fn to_partitions(
blocks_metas: &[BlockMeta],
push_downs: Option<Extras>,
push_down: Option<Extras>,
) -> (Statistics, Partitions) {
let limit = push_downs
let limit = push_down
.as_ref()
.filter(|p| p.order_by.is_empty())
.and_then(|p| p.limit)
.unwrap_or(usize::MAX);
let (mut statistics, partitions) = match &push_downs {

let (mut statistics, partitions) = match &push_down {
None => Self::all_columns_partitions(blocks_metas, limit),
Some(extras) => match &extras.projection {
None => Self::all_columns_partitions(blocks_metas, limit),
Some(projection) => Self::projection_partitions(blocks_metas, projection, limit),
},
};

statistics.is_exact = statistics.is_exact && Self::is_exact(&push_downs);
statistics.is_exact = statistics.is_exact && Self::is_exact(&push_down);
(statistics, partitions)
}

Expand Down
10 changes: 5 additions & 5 deletions query/src/storages/fuse/pruning/block_pruner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ impl BlockPruner {
return Ok(vec![]);
};

let limit = if let Some(Extras { limit: Some(l), .. }) = push_down {
*l
} else {
usize::MAX
};
let limit = push_down
.as_ref()
.filter(|p| p.order_by.is_empty())
.and_then(|p| p.limit)
.unwrap_or(usize::MAX);

// Segments and blocks are accumulated concurrently, thus an atomic counter is used
// to **try** collecting as less blocks as possible. But concurrency is preferred to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ DROP TABLE IF EXISTS t1;
CREATE TABLE t1(a UInt64 null, b UInt64 null) Engine = Memory;
INSERT INTO t1 (a,b) VALUES (1, NULL), (2, 3);
SELECT a FROM t1 WHERE b IN (NULL,3);
DROP TABLE t1;

Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ DROP TABLE IF EXISTS t1;
CREATE TABLE t1(s String NULL, pat String NULL, pos Int64 NULL, occu Int64 NULL, ro Int64 NULL, mt String NULL) Engine = Memory;
INSERT INTO t1 (s, pat, pos, occu, ro, mt) VALUES (NULL, 'dog', 1, 1, 1, ''), ('dog cat dog', 'dog', NULL, 1, 1, 'c'), ('dog cat dog', 'dog', 1, 1, 1, 'c'), ('dog cat dog', 'dog', 1, 1, 1, NULL);
select s from t1 where regexp_instr(s, pat, pos, occu, ro, mt) = 4;
drop table t1;

Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ Projection: (number % 3) as c1:UInt8, (number % 2) as c2:UInt8
2 0
2 1
2 0
3
4
5
6
5
4
6 changes: 6 additions & 0 deletions tests/suites/0_stateless/03_dml/03_0004_select_order_by.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ SELECT number, number + 3 FROM numbers_mt (1000) where number > 5 order by numbe
SELECT number%3 as c1, number%2 as c2 FROM numbers_mt (10) order by c1 desc, c2 asc;
EXPLAIN SELECT number%3 as c1, number%2 as c2 FROM numbers_mt (10) order by c1, number desc;
SELECT number%3 as c1, number%2 as c2 FROM numbers_mt (10) order by c1, number desc;

create table t1(id int);
insert into t1 select number as id from numbers(10);
select * from t1 order by id asc limit 3,3;
select * from t1 order by id desc limit 3,3;
drop table t1;
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ Projection: (number % 3) as c1:UInt8, (number % 2) as c2:UInt8
2 0
2 1
2 0
3
4
5
6
5
4