Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fczjd-0007PT-7h for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Jul 2018 20:59:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fczjb-00014y-GO for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Jul 2018 20:59:43 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fczjb-00014r-76 for pgsql-bugs@lists.postgresql.org; Tue, 10 Jul 2018 20:59:43 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fczjY-0006Tr-He for pgsql-bugs@lists.postgresql.org; Tue, 10 Jul 2018 20:59:41 +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 w6AKxXVO030416; Tue, 10 Jul 2018 16:59:33 -0400 From: Tom Lane To: Amit Langote cc: Mario De Frutos Dieguez , pgsql-bugs@lists.postgresql.org Subject: Re: Fwd: Problem with a "complex" upsert In-reply-to: <8da3739d-da24-1125-cab6-b68d6ec1bc6a@lab.ntt.co.jp> References: <18795.1529600753@sss.pgh.pa.us> <8da3739d-da24-1125-cab6-b68d6ec1bc6a@lab.ntt.co.jp> Comments: In-reply-to Amit Langote message dated "Fri, 22 Jun 2018 17:11:23 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <30414.1531256373.1@sss.pgh.pa.us> Date: Tue, 10 Jul 2018 16:59:33 -0400 Message-ID: <30415.1531256373@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Amit Langote writes: > Having worked a little bit on the ON CONFLICT code recently, I was able to > guess at the triggering detail. At least, I was able to reproduce the > error and crash seen in the OP's report. Here's a minimal example: > create table foo (a text unique, b float); > insert into foo values ('xyxyxy', 1); > -- note the different order of columns in the view > create view foo_view as select b, a from foo; Ah-hah. > I tried debugging why that happens and concluded that rewriteTargetView > fails to *completely* account for the fact that the view's column's may > have different attribute numbers than the underlying table that the DO > UPDATE action will be applied to. Especially, even if the view's Vars are > replaced with those corresponding underlying base table's columns, the > TargetEntry's into which those Vars are contained are not refreshed, that > is, their resnos don't match varattnos. > I created a patch that seems to fix the issue, which also adds a > representative test in updatable_view.sql. Hm. I looked at this patch a bit. While the onConflictSet change looks reasonable, I find the exclRelTlist change fishy. Shouldn't those resnos correspond to the exclRelTlist's *own* vars, independently of what is or isn't in the view_targetlist? And why is it OK to ignore failure to find a match? The provided test case doesn't seem to me to prove that that code is OK. AFAICS, exclRelTlist only gets used by EXPLAIN, and there's no EXPLAIN output in the test case. regards, tom lane