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

Support [NOT] MATERIALIZED keyword for WITH queries/CTEs #345

Open
joelmccracken opened this issue Nov 15, 2022 · 4 comments
Open

Support [NOT] MATERIALIZED keyword for WITH queries/CTEs #345

joelmccracken opened this issue Nov 15, 2022 · 4 comments

Comments

@joelmccracken
Copy link

joelmccracken commented Nov 15, 2022

As mentioned in the esquelto docs (https://hackage.haskell.org/package/esqueleto-3.5.8.1/docs/Database-Esqueleto-Experimental-From-CommonTableExpression.html), postgres (>12) supports keywords which specifies that CTEs should be fully calculated/materialized. For us, this is a must for performance reasons.

It would be great if there was some way to do this in esquelto, so that we could use it everywhere instead of having to use sqlQQ in cases where we need to specify CTEs should be materialized.

@belevy
Copy link
Collaborator

belevy commented Nov 29, 2022

Is there a reason to use a cte if you don't need the materialization? Can you not just use a Haskell variable for the subquery?

@belevy
Copy link
Collaborator

belevy commented Nov 29, 2022

Sorry I misunderstood the question. Yes postgres module could have a with that specifies materialized

@joelmccracken
Copy link
Author

Thinking about working on this soon, any advice?

@joelmccracken
Copy link
Author

So, my initial thoughts was to add another element to CommonTableExpressionKind, like so:

data CommonTableExpressionKind
    = RecursiveCommonTableExpression
    | NormalCommonTableExpression
    | MaterializedCommonTableExpression
    deriving Eq

However, thinking this through, I realized that this has a problem: it omits the case where there are recursive AND materialized CTEs.

I guess for now I'm going to add another paraemter somewhere and make a withMaterialized and withRecursiveMaterialized functions, something like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants