Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: ```haskell SELECT x * y + x * y FROM ( SELECT a + b + c AS x d + e + f AS y FROM foo ) _ ``` into: ```haskell SELECT (a + b + c) * (d + e + f) + (a + b + c) * (d + e + f) FROM foo ``` 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 use `pure` if they wanted the fully expanded expression), we want a way to force PostgreSQL to evaluate the `a + b + c` and the `d + e + f` first before worrying about trying to simplify `x * y + x * y`. Adding `OFFSET 0` to the inner query seems to achieve that. ```haskell SELECT x * y + x * y FROM ( SELECT a + b + c AS x d + e + f AS y FROM foo OFFSET 0 ) _ ```
- Loading branch information