File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed
rust/cubesql/cubesql/src/compile Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ impl BestCubePlan {
6464
6565 let joins = match enode {
6666 LogicalPlanLanguage :: Join ( _) => 1 ,
67+ LogicalPlanLanguage :: CrossJoin ( _) => 1 ,
6768 _ => 0 ,
6869 } ;
6970
Original file line number Diff line number Diff line change @@ -843,3 +843,59 @@ GROUP BY
843843 . sql
844844 . contains( r#"CAST(${MultiTypeCube.dim_str1} AS STRING)"# ) ) ;
845845}
846+
847+ /// Simple query, but complex join condition representation with
848+ /// CrossJoin(CubeScan, CubeScan) is penalized, and Wrapper is preferred
849+ #[ tokio:: test]
850+ async fn test_crossjoin_extraction ( ) {
851+ if !Rewriter :: sql_push_down_enabled ( ) {
852+ return ;
853+ }
854+ init_testing_logger ( ) ;
855+
856+ let query_plan = convert_select_to_query_plan (
857+ // language=PostgreSQL
858+ r#"
859+ SELECT "t0"."measure"
860+ FROM
861+ MultiTypeCube
862+ INNER JOIN (
863+ SELECT
864+ dim_str0,
865+ AVG(avgPrice) AS "measure"
866+ FROM
867+ MultiTypeCube
868+ GROUP BY 1
869+ ) "t0"
870+ ON (MultiTypeCube.dim_str0 IS NOT DISTINCT FROM "t0".dim_str0)
871+ LIMIT 1
872+ ;
873+ "#
874+ . to_string ( ) ,
875+ DatabaseProtocol :: PostgreSQL ,
876+ )
877+ . await ;
878+
879+ let physical_plan = query_plan. as_physical_plan ( ) . await . unwrap ( ) ;
880+ println ! (
881+ "Physical plan: {}" ,
882+ displayable( physical_plan. as_ref( ) ) . indent( )
883+ ) ;
884+
885+ let request = query_plan
886+ . as_logical_plan ( )
887+ . find_cube_scan_wrapped_sql ( )
888+ . request ;
889+
890+ assert_eq ! ( request. ungrouped, Some ( true ) ) ;
891+
892+ assert_eq ! ( request. subquery_joins. as_ref( ) . unwrap( ) . len( ) , 1 ) ;
893+
894+ let subquery = & request. subquery_joins . unwrap ( ) [ 0 ] ;
895+
896+ assert ! ( !subquery. sql. contains( "ungrouped" ) ) ;
897+ assert_eq ! ( subquery. join_type, "INNER" ) ;
898+ assert ! ( subquery
899+ . on
900+ . contains( r#"${MultiTypeCube.dim_str0} IS NOT DISTINCT FROM \"t0\".\"dim_str0\""# ) ) ;
901+ }
You can’t perform that action at this time.
0 commit comments