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

Update default SQL optimization level to use CTEs #1525

Merged
merged 4 commits into from
Nov 14, 2024
Merged

Update default SQL optimization level to use CTEs #1525

merged 4 commits into from
Nov 14, 2024

Conversation

plypaul
Copy link
Contributor

@plypaul plypaul commented Nov 13, 2024

Resolves #1040

This PR updates the default SQL optimization level to use CTEs. This creates a number of snapshot changes as queries in tests now use CTEs in cases where there are common sources or common metrics in multi-metric / derived metric cases.

@cla-bot cla-bot bot added the cla:yes label Nov 13, 2024
@plypaul plypaul marked this pull request as ready for review November 13, 2024 06:34
Copy link
Contributor

@courtneyholcomb courtneyholcomb left a comment

Choose a reason for hiding this comment

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

Hell yeah, looks awesome! 🚀 Left one main question about with the duplicated alias.

@@ -129,7 +129,7 @@ def create_with_random_request_id( # noqa: D102
where_constraints: Optional[Sequence[str]] = None,
order_by_names: Optional[Sequence[str]] = None,
order_by: Optional[Sequence[OrderByQueryParameter]] = None,
sql_optimization_level: SqlQueryOptimizationLevel = SqlQueryOptimizationLevel.O4,
sql_optimization_level: SqlQueryOptimizationLevel = SqlQueryOptimizationLevel.default_level(),
Copy link
Contributor

Choose a reason for hiding this comment

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

You might need to check if MFS is overriding this param. I know at some point we overrode the dataflow_plan_optimizations param at least (to disable predicate pushdown) but not sure now.

, 1 AS bookings
FROM ***************************.fct_bookings bookings_source_src_28000
) subq_12
FROM rss_28020_cte rss_28020_cte
Copy link
Contributor

Choose a reason for hiding this comment

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

Noticing this alias is unnecessary duplication. Same with line 44 below. Is that intended? Maybe it's required for certain engines?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We always specify an alias for the sources in a SELECT. This is something that can be updated, but we haven't gotten around to it. We also always specify an alias for each of the columns, which is something that can be cleaned up as well.

@@ -0,0 +1,6 @@
kind: Features
body: se CTEs instead of sub queries in generated SQL
Copy link
Contributor

Choose a reason for hiding this comment

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

Use*

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@plypaul plypaul merged commit 0be9c0a into main Nov 14, 2024
15 checks passed
@plypaul plypaul deleted the p--cte--18 branch November 14, 2024 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SL-1756] [SL-1755] [Feature] Use CTEs instead of sub queries in generated SQL
2 participants