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
opt: Support AS MATERIALIZED option in CTEs #45863
Comments
First time here, I'm happy to attempt this. Do you have more info to help me start out? |
Thanks @Anthuang. Here's a list of things that need to be done:
|
Thanks for the detailed steps! Do you have any docs for how these tests work (syntax, etc.)? And also what should I be achieving with changing |
Each testcase is a directive (usually
Just printing the new field that you add so we can make sure it's set as expected. |
I'm really close. I just can't figure out why the parser tests I wrote aren't passing. It seems as if the pretty printing function is omitting "[NOT] MATERIALIZE", and thus I've also included logic to parse the added "[NOT] MATERIALIZE" syntax in |
I assume you modified the Format method for a tree struct. There is a pretty printing code that needs to be updated as well - there is a file pretty.go or similar, grep for the type in there. IMO these should live next to Format but that's for another day :) |
Ah I missed that, thanks! |
As far as I can tell, postgres still forces materialization if the cte contains volatile functions:
Not sure if we want the same semantics. In our case it may be useful to allow overriding our side-effect logic when it is too conservative. @andy-kimball what do you think? |
Sorry, I didn't see this question until now. I agree that it seems better to allow a forced override rather than ignoring explicit instructions from the user, as Postgres does. |
PG 12 supports
AS MATERIALIZED
andAS NOT MATERIALIZED
syntax for user controller of CTE materialization. For example:With this syntax, the user can override the optimizer's default decision to not materialize that table (since it's only referenced once).
Similarly, this syntax allows the user to override the optimizer's default decision to materialize the table (since it's referenced multiple times).
Adding this option requires adding a flag to the generated
WithPrivate
struct, and then updating the parser to parse the new syntax, and set the flag. The optimizer'sInlineWith
rule (seewith.opt
) then changes to take into account the new flag.The text was updated successfully, but these errors were encountered: