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 1 commit
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
11 changes: 7 additions & 4 deletions query/src/storages/fuse/operations/read_partitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ impl FuseTable {
blocks_metas: &[BlockMeta],
push_downs: Option<Extras>,
) -> (Statistics, Partitions) {
let limit = push_downs
.as_ref()
.and_then(|p| p.limit)
.unwrap_or(usize::MAX);
let mut limit = usize::MAX;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

let limit = push_downs
            .as_ref()
            .filter(|p| p.order_by.is_empty())
            .and_then(|p| p.limit)
            .unwrap_or(usize::MAX);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

let limit = push_downs
            .as_ref()
            .filter(|p| p.order_by.is_empty())
            .and_then(|p| p.limit)
            .unwrap_or(usize::MAX);

That's great, I did not come up with this idea.

if let Some(p) = push_downs.as_ref() {
if p.order_by.is_empty() && p.limit.is_some() {
limit = p.limit.unwrap();
}
}

let (mut statistics, partitions) = match &push_downs {
None => Self::all_columns_partitions(blocks_metas, limit),
Some(extras) => match &extras.projection {
Expand Down
11 changes: 6 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,12 @@ impl BlockPruner {
return Ok(vec![]);
};

let limit = if let Some(Extras { limit: Some(l), .. }) = push_down {
*l
} else {
usize::MAX
};
let mut limit = usize::MAX;
if let Some(p) = push_down.as_ref() {
if p.order_by.is_empty() && p.limit.is_some() {
limit = p.limit.unwrap();
}
}

// 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 @@ -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;