databend icon indicating copy to clipboard operation
databend copied to clipboard

Feature: LIMIT push down for new planner

Open leiysky opened this issue 2 years ago • 9 comments

In some cases, it's possible to push the LIMIT operator down to reduce the data to be processed.

Besides, LIMIT hint of ReadDataSource will affect the behavior of Random table engine.

leiysky avatar Jul 28 '22 04:07 leiysky

@leiysky hi, is there any one working on this? I would like to pick this up.

AngleNet avatar Aug 05 '22 00:08 AngleNet

Besides, LIMIT push down could affect the Sort Plan which has partial sort optimization.

#[derive(Clone, Debug)]
pub struct Sort {
    pub items: Vec<SortItem>,
+   pub limit: option<usize>
}

sundy-li avatar Aug 05 '22 01:08 sundy-li

Besides, LIMIT push down could affect the Sort Plan which has partial sort optimization.

#[derive(Clone, Debug)]
pub struct Sort {
    pub items: Vec<SortItem>,
+   pub limit: option<usize>
}

@sundy-li Hi. What do you mean partial sort optimization?

AngleNet avatar Aug 05 '22 02:08 AngleNet

@sundy-li Hi. What do you mean partial sort optimization?

https://github.com/datafuselabs/databend/blob/4d458914ab5e6fcf26d3c5fc74b830ef3c3a2d82/query/src/pipelines/pipeline_builder.rs#L381-L402

sundy-li avatar Aug 05 '22 02:08 sundy-li

@sundy-li Is it actually a TopN operator?

leiysky avatar Aug 05 '22 03:08 leiysky

@sundy-li @leiysky Shall we implement a TopN operator and convert an order followed by limit to a TopN operator and the limit could be pushed down further?

AngleNet avatar Aug 06 '22 00:08 AngleNet

@AngleNet I've just opened a issue https://github.com/datafuselabs/databend/issues/7015 for that.

leiysky avatar Aug 06 '22 02:08 leiysky

Great! I think I could implement limit push down firstly and then introduce topn operator, refactor the limit push down to support topn finally. Is that ok?

AngleNet avatar Aug 06 '22 03:08 AngleNet

Great! I think I could implement limit push down firstly and then introduce topn operator, refactor the limit push down to support topn finally. Is that ok?

That's good.

leiysky avatar Aug 06 '22 07:08 leiysky