Re: enable_incremental_sort changes query behavior
James Coleman <jtc331@gmail.com>
From: James Coleman <jtc331@gmail.com>
To: Tomas Vondra <tomas.vondra@2ndquadrant.com>
Cc: Jaime Casanova <jaime.casanova@2ndquadrant.com>, Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2020-10-02T21:49:04Z
Lists: pgsql-hackers
On Fri, Oct 2, 2020 at 4:56 PM Tomas Vondra <tomas.vondra@2ndquadrant.com> wrote: > >And I don't see any reason why the CASE statement couldn't in theory > >(I don't know the internals enough to know when it actually happens) > >be done as part of the base relation scan (in this case, the seq > >scan). It's not dependent on any information from the join. > > > > Imagine a query like this: > > select t1.id, volatile_func() from t1 join t2 using (id); > > and now assume t2 contains duplicate values. If the volatile_func gets > evaluated as part of the t1 scan, then we'll get multiple occurrences > in the results, due to the t2 duplicates. I belive volatile functions > are not expected to behave like that - the docs say: > > A query using a volatile function will re-evaluate the function at > every row where its value is needed.. > > And I assume this references to rows at the level where the function is > used, i.e. after the join. Ah, this makes sense. I was thinking exactly the opposite: that you'd want not to execute volatile functions multiple times for the same base rel row, but now that you describe it it makes sense why they shouldn't be. James
Commits
-
Disallow SRFs when considering sorts below Gather Merge
- fac1b470a9f7 14.0 landed
- d0167631e8b7 13.2 landed
-
Error out when Gather Merge input is not sorted
- 6bc27698324a 14.0 landed
-
Fix get_useful_pathkeys_for_relation for volatile expressions
- 2d26c4ac7034 13.1 landed
- ebb7ae839d03 14.0 landed
-
Guard against core dump from uninitialized subplan.
- 936043c9eacb 13.1 cited