pgsql: Fix infer_arbiter_indexes() to not assume resultRelation is 1.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix infer_arbiter_indexes() to not assume resultRelation is 1.
Date: 2024-06-11 21:58:15
Message-ID: E1sH9VO-0016ih-GP@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix infer_arbiter_indexes() to not assume resultRelation is 1.

infer_arbiter_indexes failed to renumber varnos in index expressions
or predicates that it got from the catalogs. This escaped detection
up to now because the stored varnos in such trees will be 1, and an
INSERT's result relation is usually the first rangetable entry,
so that that was fine. However, in cases such as inserting through
an updatable view, it's not fine, leading to failure to match the
expressions to the query with ensuing "there is no unique or exclusion
constraint matching the ON CONFLICT specification" errors.

Fix by copy-and-paste from get_relation_info().

Per bug #18502 from Michael Wang. Back-patch to all supported
versions.

Discussion: https://postgr.es/m/18502-545b53f5b81e54e0@postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/915de706d28c433283e9dc63701e8f978488a2b9

Modified Files
--------------
src/backend/optimizer/util/plancat.c | 9 ++++++++-
src/test/regress/expected/insert_conflict.out | 13 +++++++++++++
src/test/regress/sql/insert_conflict.sql | 6 ++++++
3 files changed, 27 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Masahiko Sawada 2024-06-12 00:57:05 pgsql: Fix segmentation fault in test_tidstore.
Previous Message Alvaro Herrera 2024-06-11 09:52:41 pgsql: Fix creation of partition descriptor during concurrent detach