Fix get_useful_pathkeys_for_relation for volatile expressions
authorTomas Vondra
Tue, 3 Nov 2020 19:07:23 +0000 (20:07 +0100)
committerTomas Vondra
Tue, 3 Nov 2020 21:32:34 +0000 (22:32 +0100)
commit2d26c4ac703447a002a02124c1edd01e70a5d1ee
treeeadbb37000a13cca7882537af987c5b23ffc37e6
parent936043c9eacb9e9c7356a8190a410d2c4e4ea03a
Fix get_useful_pathkeys_for_relation for volatile expressions

When considering Incremental Sort below a Gather Merge, we need to be
a bit more careful when matching pathkeys to EC members. It's not enough
to find a member whose Vars are all in the current relation's target;
volatile expressions in particular need to be contained in the target,
otherwise it's too early to use the pathkey.

Reported-by: Jaime Casanova
Author: James Coleman
Reviewed-by: Tomas Vondra
Backpatch-through: 13, where the incremental sort code was added
Discussion: https://postgr.es/m/CAJGNTeNaxpXgBVcRhJX%2B2vSbq%2BF2kJqGBcvompmpvXb7pq%2BoFA%40mail.gmail.com
src/backend/optimizer/path/allpaths.c
src/backend/optimizer/path/equivclass.c
src/include/optimizer/paths.h
src/test/regress/expected/incremental_sort.out
src/test/regress/sql/incremental_sort.sql