Simplify eval to run directly inside the Query monad#56
Merged
shane-circuithub merged 1 commit intomasterfrom Jun 22, 2021
Merged
Simplify eval to run directly inside the Query monad#56shane-circuithub merged 1 commit intomasterfrom
eval to run directly inside the Query monad#56shane-circuithub merged 1 commit intomasterfrom
Conversation
c0e3bf5 to
1598e38
Compare
Contributor
Author
|
@ocharles I'm quite confident that I have something now that will always give the expected results. |
b6b7fb3 to
919b614
Compare
ocharles
approved these changes
Jun 22, 2021
Comment on lines
+54
to
+58
| rebind :: Table Expr a => a -> Query a | ||
| rebind a = Query $ \_ -> Opaleye.QueryArr $ \(_, query, tag) -> |
Contributor
There was a problem hiding this comment.
Could you document what this is doing? As it occurs after laterally, it seems to kind of "undo" the need for lateral joins (as they've already served their purpose), so we go back to letting PostgreSQL do its thing.
Contributor
Author
There was a problem hiding this comment.
I don't know what you mean. This is what makes it so that if you do (\x -> (x, x)) <$> evaluate (nextval "user_id_seq"), both your xs will have the same value. This is orthogonal to laterally which adds the superfluous lateral references.
Contributor
Author
There was a problem hiding this comment.
Added a comment anyway
Closed
@tomjaguarpaw at ZuriHac questioned whether the `Evaluation` monad was really unnecessary. And yes, it turns out that the `Evaluation` monad wasn't actually really adding any value. The real issue was Postgres's unspecified evaluation order (which in practice behaved like the broken `ListT` from transformers). We now maintain a stack of bindings from previous subselects in the `Query` monad, which future queries can reference. So for `evalulation`, to ensure that Postgres doesn't try to run a function once where we expect it to be run multiple times, we modify the expression to contain a bunch of superfluous lateral references to the previous queries. This ensures that it gets run every time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@tomjaguarpaw pointed out at ZuriHac that the
Evaluationmonad is entirely unnecessary. I've tested this change and it seems to still do what I want it to do. Not sure why I ever thought it was necessary!