Re: BUG #16006: Update queries fail on a table having any policy with a function that takes a whole-row var as arg

From: Andres Freund <andres(at)anarazel(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: vinay(dot)s(dot)banakar(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16006: Update queries fail on a table having any policy with a function that takes a whole-row var as arg
Date: 2019-09-12 21:10:47
Message-ID: 20190912211047.kr7e4pn7iof76jfx@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi,

On 2019-09-12 16:33:55 -0400, Tom Lane wrote:
> PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> > Update queries fail on a table having any policy with a function that takes
> > a whole-row var as argument.
>
> Hm. You really should have shown the failure you were seeing, but
> for the archives' sake: I can reproduce this on 9.5 and 9.6 (if I
> run the queries as non-superuser!), and it looks like
>
> regression=> insert into usertable values('key','field0','field1','field2','field3','field4','field5','field6','field7','field8','field9');
> INFO: log: (key,field0,field1,field2,field3,field4,field5,field6,field7,field8,field9,"2019-09-12 16:29:37.511329")
> INSERT 0 1
> regression=> update usertable set field0 = 'f0';
> INFO: log: (key,field0,field1,field2,field3,field4,field5,field6,field7,field8,field9,"2019-09-12 16:29:37.511329")
> ERROR: table row type and query-specified row type do not match
> DETAIL: Table has type tid at ordinal position 1, but query expects character varying.
>
> Digging into this, it seems the short answer is "Andres should have
> back-patched 148e632c0". The plan shape in 9.6.x is

Heh :/. I was wondering (and asking for input) at the time... The whole
business with parent nodes is somewhat fragile (cf 2abd7ae9b2 /
5f32b29c1819), which makes me generally a bit hesitant to backpatch.
But obviously it's needed here.

> Update on usertable usertable_1 (cost=0.00..66.00 rows=70 width=366)
> -> Subquery Scan on usertable (cost=0.00..66.00 rows=70 width=366)
> -> LockRows (cost=0.00..65.30 rows=70 width=340)
> -> Seq Scan on usertable usertable_2 (cost=0.00..64.60 rows=70 width=340)
> Filter: log_record(usertable_2.*)
>
> and because ExecInitModifyTable incorrectly passes the SubqueryScan
> as parent of the WCO expressions, the horrible examine-the-parent
> kluge in ExecEvalWholeRowVar fires, causing it to apply a completely
> inappropriate junkfilter to the scan tuple. After which, of course,
> the tuple rowtype is wrong.

I don't quite understand how this "visibly" broke between 9.5.15 and
9.5.19 as the op reports? Haven't dug into it yet though.

Greetings,

Andres Freund

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2019-09-12 22:28:25 Re: BUG #16006: Update queries fail on a table having any policy with a function that takes a whole-row var as arg
Previous Message Tom Lane 2019-09-12 20:33:55 Re: BUG #16006: Update queries fail on a table having any policy with a function that takes a whole-row var as arg