pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: vinay.s.banakar@gmail.com
Cc: pgsql-bugs@lists.postgresql.org, Andres Freund <andres@anarazel.de>
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: Thu, 12 Sep 2019 16:33:55 -0400
Message-ID: <28076.1568320435@sss.pgh.pa.us> (raw)
In-Reply-To: <16006-99290d2e4642cbd5@postgresql.org>
References: <16006-99290d2e4642cbd5@postgresql.org>

PG Bug reporting form <noreply@postgresql.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

 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 do not see the bug in v10 and up, but I think that's accidental in
v10/v11, because they produce a plan without the not-really-necessary
SubqueryScan:

 Update on usertable  (cost=0.00..64.60 rows=70 width=366)
   ->  Seq Scan on usertable  (cost=0.00..64.60 rows=70 width=366)
         Filter: log_record(usertable.*)

The whole-row var is still being initialized with respect to the wrong
parent, but it doesn't do anything funny when it's pointed at a plain
SeqScan, so all is well.  I suspect it's possible to develop a test
case that will fail in v10/v11, and will go look for one.

Thanks for the report!

			regards, tom lane





view thread (8+ messages)  latest in thread

Message-ID: <28076.1568320435@sss.pgh.pa.us>
Permalink:  ../28076.1568320435@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/28076.1568320435@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, vinay.s.banakar@gmail.com, andres@anarazel.de
  Subject: Re: BUG #16006: Update queries fail on a table having any policy with a function that takes a whole-row var as arg
  In-Reply-To: <28076.1568320435@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox