Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oiGrW-0007uR-8w for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Oct 2022 15:08:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oiGrU-0007ks-VQ for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Oct 2022 15:08:04 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oiGrU-0007kj-Na for pgsql-bugs@lists.postgresql.org; Tue, 11 Oct 2022 15:08:04 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oiGrS-0002UR-Kp for pgsql-bugs@lists.postgresql.org; Tue, 11 Oct 2022 15:08:04 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 29BF7jr4312798; Tue, 11 Oct 2022 11:07:45 -0400 From: Tom Lane To: Japin Li cc: Richard Guo , jiye_sw@126.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17633: Define rule on views which do insert to another relation trigger cache lookup failed error. In-reply-to: References: <17633-98cc85e1fa91e905@postgresql.org> Comments: In-reply-to Japin Li message dated "Tue, 11 Oct 2022 22:35:50 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <312796.1665500865.1@sss.pgh.pa.us> Date: Tue, 11 Oct 2022 11:07:45 -0400 Message-ID: <312797.1665500865@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Japin Li writes: > On Tue, 11 Oct 2022 at 21:16, Richard Guo wrote: >> +1 for the idea. We need to identify the right target relation for each >> product query and rt_entry_relation is not the right one. > After some more thinking, I find the previous cannot work correctly. Yeah. The product query might not be an INSERT at all, yet rewriteValuesRTE is assuming it is --- that whole business of scanning the targetlist for referencing Vars and then saving their resnos doesn't make sense otherwise. I think the basic problem is that the two calls of rewriteValuesRTE are really dealing with fundamentally different cases, and we should probably not have tried to make the same function do both. I'm going to try splitting it into two functions, one for the force_nulls case and one for the !force_nulls case. The force_nulls case shouldn't really need a target_relation parameter in the first place (since it has no business assuming that the query is an INSERT). I think it should just replace each SetToDefault with a NULL of the same type as the SetToDefault, and call it good. regards, tom lane