Re: ON CONFLICT issues around whole row vars, - Mailing list pgsql-hackers

From Andres Freund
Subject Re: ON CONFLICT issues around whole row vars,
Date
Msg-id 20150920001109.GA3844@alap3.anarazel.de
Whole thread Raw
In response to Re: Free indexed_tlist memory explicitly within set_plan_refs()  (Peter Geoghegan <pg@heroku.com>)
Responses Re: ON CONFLICT issues around whole row vars,  (Peter Geoghegan <pg@heroku.com>)
List pgsql-hackers
Hi,

To recap for other readers: There's a problem with ON CONFLICT when the
SET or ON CONFLICT ... WHERE clause references excluded.* (i.e. as a
whole row var).  The problem is that setrefs.c in
fix_join_expr_mutator() currently won't find a matching entry in the
indexed tlist and thus error out with             elog(ERROR, "variable not found in subplan target lists");

The reason is that the targetlist we build the index list on just
contains the attributes in excluded.*.

Peter's patch upthread fixes this by pulling expressions from
onConflictSet/Where into the targetlist. I disliked this - much less
than initially - a bit because that seems a bit crufty given that we're
not actually getting data from a child node.  This is different to
RETURNING where the targetlist massaging is actually important to get
the data up the tree.

An actually trivial, although not all that pretty, fix is to simply
accept wholerow references in fix_join_expr_mutator(), even if not in
the targetlist. As far as I can see the problem right now really can
only be hit for whole row references.

A variant of the second approach is to have a fix_onconflict_expr()
mutator that has such special handler.

Any opinions on either approach?

Greetings,

Andres Freund



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: TABLESAMPLE patch is really in pretty sad shape
Next
From: Andres Freund
Date:
Subject: Update count mismatch - internal error