Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i8Vn2-0000mH-NG for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Sep 2019 20:34:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i8Vn1-000861-42 for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Sep 2019 20:34:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i8Vn0-00085f-Pt for pgsql-bugs@lists.postgresql.org; Thu, 12 Sep 2019 20:34:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1i8Vmy-0000Yi-HW for pgsql-bugs@lists.postgresql.org; Thu, 12 Sep 2019 20:34:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x8CKXtj7028077; Thu, 12 Sep 2019 16:33:55 -0400 From: Tom Lane To: vinay.s.banakar@gmail.com cc: pgsql-bugs@lists.postgresql.org, Andres Freund 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: <16006-99290d2e4642cbd5@postgresql.org> References: <16006-99290d2e4642cbd5@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Thu, 12 Sep 2019 16:51:01 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <28075.1568320435.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 12 Sep 2019 16:33:55 -0400 Message-ID: <28076.1568320435@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > Update queries fail on a table having any policy with a function that ta= kes > 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=3D> insert into usertable values('key','field0','field1','field= 2','field3','field4','field5','field6','field7','field8','field9'); INFO: log: (key,field0,field1,field2,field3,field4,field5,field6,field7,f= ield8,field9,"2019-09-12 16:29:37.511329") INSERT 0 1 regression=3D> update usertable set field0 =3D 'f0'; INFO: log: (key,field0,field1,field2,field3,field4,field5,field6,field7,f= ield8,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 chara= cter 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=3D0.00..66.00 rows=3D70 width=3D36= 6) -> Subquery Scan on usertable (cost=3D0.00..66.00 rows=3D70 width=3D3= 66) -> LockRows (cost=3D0.00..65.30 rows=3D70 width=3D340) -> Seq Scan on usertable usertable_2 (cost=3D0.00..64.60 = rows=3D70 width=3D340) 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=3D0.00..64.60 rows=3D70 width=3D366) -> Seq Scan on usertable (cost=3D0.00..64.60 rows=3D70 width=3D366) 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