Re: BUG #17803: Rule "ALSO INSERT ... SELECT ..." fails to substitute default values

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: exclusion(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17803: Rule "ALSO INSERT ... SELECT ..." fails to substitute default values
Date: 2023-02-21 15:05:50
Message-ID: 3953951.1676991950@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> writes:
> It looks like we need something like the attached, to deal with
> product queries that are INSERT ... SELECT queries. In that case the
> VALUES RTE will be at the same index, but in the SELECT part of the
> product query, not the top-level product query itself.

It seems like this bit:

+ rtr = (RangeTblRef *) linitial(pt->jointree->fromlist);
+ selectrte = rt_fetch(rtr->rtindex, pt->rtable);
+ selectquery = selectrte->subquery;

is missing several essential checks. Is the node extracted from
jointree->fromlist actually a RangeTblRef? Seems like it could
be a JoinExpr or FromExpr instead; even if it can't be that today,
an IsA check is cheap future-proofing. Likewise, once you've
got your hands on the RTE, you should check rtekind == RTE_SUBQUERY
rather than assuming it's safe to touch the subquery field.

(I see that getInsertSelectQuery isn't much better about this,
but we should fix that while we're at it.)

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Stephen Frost 2023-02-21 16:35:54 Re: Query run in 27s with 15.2 vs 37ms with 14.6
Previous Message Heikki Linnakangas 2023-02-21 14:32:02 Re: Unlimited memory consumption with long-lived connection