Skip to content
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
1 change: 1 addition & 0 deletions rust/cubesql/cubesql/src/compile/rewrite/cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ impl BestCubePlan {

let joins = match enode {
LogicalPlanLanguage::Join(_) => 1,
LogicalPlanLanguage::CrossJoin(_) => 1,
_ => 0,
};

Expand Down
56 changes: 56 additions & 0 deletions rust/cubesql/cubesql/src/compile/test/test_cube_join_grouped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,3 +843,59 @@ GROUP BY
.sql
.contains(r#"CAST(${MultiTypeCube.dim_str1} AS STRING)"#));
}

/// Simple query, but complex join condition representation with
/// CrossJoin(CubeScan, CubeScan) is penalized, and Wrapper is preferred
#[tokio::test]
async fn test_crossjoin_extraction() {
if !Rewriter::sql_push_down_enabled() {
return;
}
init_testing_logger();

let query_plan = convert_select_to_query_plan(
// language=PostgreSQL
r#"
SELECT "t0"."measure"
FROM
MultiTypeCube
INNER JOIN (
SELECT
dim_str0,
AVG(avgPrice) AS "measure"
FROM
MultiTypeCube
GROUP BY 1
) "t0"
ON (MultiTypeCube.dim_str0 IS NOT DISTINCT FROM "t0".dim_str0)
LIMIT 1
;
"#
.to_string(),
DatabaseProtocol::PostgreSQL,
)
.await;

let physical_plan = query_plan.as_physical_plan().await.unwrap();
println!(
"Physical plan: {}",
displayable(physical_plan.as_ref()).indent()
);

let request = query_plan
.as_logical_plan()
.find_cube_scan_wrapped_sql()
.request;

assert_eq!(request.ungrouped, Some(true));

assert_eq!(request.subquery_joins.as_ref().unwrap().len(), 1);

let subquery = &request.subquery_joins.unwrap()[0];

assert!(!subquery.sql.contains("ungrouped"));
assert_eq!(subquery.join_type, "INNER");
assert!(subquery
.on
.contains(r#"${MultiTypeCube.dim_str0} IS NOT DISTINCT FROM \"t0\".\"dim_str0\""#));
}
Loading