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.
Somewhere between PostgreSQL 11 and PostgreSQL 15, PostgreSQL's optimiser gained the ability to see "through" subqueries, and it seems to choose to do this even when we don't really want it to.
E.g., it started transforming the following:
into:
before evaluating.
You can see how more complicated expressions nested several levels deep could get expanded into crazy big expressions. This seems to be what PostgreSQL actually does on Rel8 code that uses
rebind
. Compared to older versions of PostgreSQL, this increases the planning time and execution time dramatically.Given that Rel8's
rebind
is intended to function as a "let binding", and the user needs to go out of their way to choose to use it (they could just usepure
if they wanted the fully expanded expression), we want a way to force PostgreSQL to evaluate thea + b + c
and thed + e + f
first before worrying about trying to simplifyx * y + x * y
. AddingOFFSET 0
to the inner query seems to achieve that.