aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gierth <rhodiumtoad@postgresql.org>2018-08-28 14:43:51 +0100
committerAndrew Gierth <rhodiumtoad@postgresql.org>2018-08-28 14:43:51 +0100
commitbf2d0462cd735f76bcf6eb8b399723674b2221ef (patch)
tree9eb6b83c2acf81b9a2c6d8db7cabbd165476bfa2
parentbfea331a5e1b993d22071fc1696e6e8811d2d0d4 (diff)
downloadpostgresql-bf2d0462cd735f76bcf6eb8b399723674b2221ef.tar.gz
postgresql-bf2d0462cd735f76bcf6eb8b399723674b2221ef.zip
postgres_fdw: don't push ORDER BY with no vars (bug #15352)
Commit aa09cd242 changed a condition in find_em_expr_for_rel from being a bms_equal comparison of relids to bms_is_subset, in order to support order by clauses on foreign joins. But this also allows through the degenerate case of expressions with no Vars at all (and hence empty relids), including integer constants which will be parsed unexpectedly on the remote (viz. "ERROR: ORDER BY position 0 is not in select list" as in the bug report). Repair by adding an additional !bms_is_empty test. Backpatch through to 9.6 where the aforementioned change was made. Per bug #15352 from Maksym Boguk; analysis and patch by me. Discussion: https://postgr.es/m/153518420278.1478.14875560810251994661@wrigleys.postgresql.org
-rw-r--r--contrib/postgres_fdw/postgres_fdw.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index 0803c30a48e..e4e330397ee 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -5793,7 +5793,8 @@ find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel)
{
EquivalenceMember *em = lfirst(lc_em);
- if (bms_is_subset(em->em_relids, rel->relids))
+ if (bms_is_subset(em->em_relids, rel->relids) &&
+ !bms_is_empty(em->em_relids))
{
/*
* If there is more than one equivalence member whose Vars are