File tree Expand file tree Collapse file tree 2 files changed +42
-12
lines changed
cubestore/src/queryplanner Expand file tree Collapse file tree 2 files changed +42
-12
lines changed Original file line number Diff line number Diff line change @@ -8285,20 +8285,39 @@ async fn limit_pushdown_without_group(service: Box<dyn SqlClient>) {
82858285 ) ;
82868286
82878287 // ====================================
8288- let res = assert_limit_pushdown (
8288+ assert_limit_pushdown (
82898289 & service,
82908290 "SELECT a, b, c FROM (
8291- SELECT a, b, c FROM foo.pushdown_where_group1
8292- union all
8293- SELECT a_alias a, b_alias b, c_alias c FROM foo.pushdown_where_group2_with_alias
8291+ SELECT a, b, c FROM foo.pushdown_where_group1
8292+ UNION ALL
8293+ SELECT a_alias a, b_alias b, c_alias c FROM foo.pushdown_where_group2_with_alias
82948294 ) as `tb`
8295- ORDER BY 3 DESC LIMIT 3" ,
8295+ ORDER BY 3 DESC
8296+ LIMIT 10" ,
82968297 Some ( "ind2" ) ,
82978298 true ,
82988299 true ,
82998300 )
83008301 . await
83018302 . unwrap ( ) ;
8303+
8304+ // ====================================
8305+ assert_limit_pushdown (
8306+ & service,
8307+ "SELECT a, b, c FROM (
8308+ SELECT a, b, c FROM foo.pushdown_where_group1
8309+ UNION ALL
8310+ SELECT a_alias a, b_alias b, c_alias c FROM foo.pushdown_where_group2_with_alias
8311+ ) as `tb`
8312+ WHERE b = 20
8313+ ORDER BY 1 DESC, 3 DESC
8314+ LIMIT 3" ,
8315+ Some ( "ind1" ) ,
8316+ true ,
8317+ true ,
8318+ )
8319+ . await
8320+ . unwrap ( ) ;
83028321}
83038322async fn limit_pushdown_without_group_resort ( service : Box < dyn SqlClient > ) {
83048323 service. exec_query ( "CREATE SCHEMA foo" ) . await . unwrap ( ) ;
Original file line number Diff line number Diff line change @@ -769,24 +769,35 @@ impl PlanRewriter for ChooseIndex<'_> {
769769 LogicalPlan :: Projection { expr, .. } => {
770770 let alias_to_column = get_alias_to_column ( expr) ;
771771
772- if let Some ( sort) = & context. sort {
772+ let new_single_value_filtered_cols = context
773+ . single_value_filtered_cols
774+ . iter ( )
775+ . map ( |name| {
776+ alias_to_column
777+ . get ( name)
778+ . map_or_else ( || name. clone ( ) , |col| col. name . clone ( ) )
779+ } )
780+ . collect ( ) ;
781+
782+ let mut new_context =
783+ context. update_single_value_filtered_cols ( new_single_value_filtered_cols) ;
784+
785+ if let Some ( sort) = & new_context. sort {
773786 let names: Vec < String > = sort
774- . clone ( )
775787 . iter ( )
776788 . map ( |k| {
777789 alias_to_column
778790 . get ( k)
779- . map_or_else ( || k. clone ( ) , |v| v . name . clone ( ) )
791+ . map_or_else ( || k. clone ( ) , |col| col . name . clone ( ) )
780792 } )
781793 . collect ( ) ;
782794
783795 if !names. is_empty ( ) {
784- return Some ( context. update_sort ( names, context. sort_is_asc ) ) ;
785- } else {
786- return None ;
796+ new_context = new_context. update_sort ( names, context. sort_is_asc ) ;
787797 }
788798 }
789- None
799+
800+ Some ( new_context)
790801 }
791802 LogicalPlan :: Limit { n, .. } => Some ( context. update_limit ( Some ( * n) ) ) ,
792803 LogicalPlan :: Skip { n, .. } => {
You can’t perform that action at this time.
0 commit comments