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 1fdSLF-00047U-Dq for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Jul 2018 03:32:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fdSLC-0005S2-SJ for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Jul 2018 03:32:26 +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 1fdSLC-0005Rv-I1 for pgsql-hackers@lists.postgresql.org; Thu, 12 Jul 2018 03:32:26 +0000 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fdSL4-0005DP-VG for pgsql-hackers@postgresql.org; Thu, 12 Jul 2018 03:32:25 +0000 Received: from vc2.ecl.ntt.co.jp (vc2.ecl.ntt.co.jp [129.60.86.154]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id w6C3WGsa004670; Thu, 12 Jul 2018 12:32:16 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 3433B638A8E; Thu, 12 Jul 2018 12:32:16 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 1F2A46387E1; Thu, 12 Jul 2018 12:32:16 +0900 (JST) Received: from [IPv6:::1] (unknown [129.60.241.75]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 1A7BA40034E; Thu, 12 Jul 2018 12:32:16 +0900 (JST) Message-ID: <5B46CBB3.2090300@lab.ntt.co.jp> Date: Thu, 12 Jul 2018 12:32:03 +0900 From: Etsuro Fujita User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 Subject: Re: Expression errors with "FOR UPDATE" and postgres_fdw with partition wise join enabled. References: <5B1E5071.1000704@lab.ntt.co.jp> <5B23A964.9020800@lab.ntt.co.jp> <5B28FB19.3090809@lab.ntt.co.jp> <5B362B38.2000103@lab.ntt.co.jp> <5B3CB833.4040005@lab.ntt.co.jp> <5B3F4BAA.3050601@lab.ntt.co.jp> <5B4340E9.3030707@lab.ntt.co.jp> <5B434886.9010107@lab.ntt.co.jp> <5B442A40.2040903@lab.ntt.co.jp> <5B45B777.7010502@lab.ntt.co.jp> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CC-Mail-RelayStamp: 1 To: Ashutosh Bapat Cc: Rajkumar Raghuwanshi , pgsql-hackers X-TM-AS-MML: disable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk (2018/07/11 20:02), Ashutosh Bapat wrote: > On Wed, Jul 11, 2018 at 1:23 PM, Etsuro Fujita > wrote: >> Actually, even if we could create such an index on the child table and the >> targetlist had the ConvertRowtypeExpr, the planner would still not be able >> to use an index-only scan with that index; because check_index_only would >> not consider that an index-only scan is possible for that index because that >> index is an expression index and that function currently does not consider >> that index expressions are able to be returned back in an index-only scan. >> That behavior of the planner might be improved in future, though. > Right and when we do so, not having ConvertRowtypeExpr in the > targetlist will be a problem. Yeah, but I don't think that that's unsolvable; because in that case the CRE as an index expression could be converted back to the whole-row Var's rowtype by adding another CRE to the index expression for that conversion, I suspect that that special handling could allow us to support an index-only scan even when having the whole-row Var instead of the CRE in the targetlist. (Having said that, I'm not 100% sure we need to solve that problem when we improve the planner, because there doesn't seem to me to be enough use-case to justify making the code complicated for that.) Anyway, I think that that would be a matter of future versions of PG. >>> At places in planner we match equivalence members >>> to the targetlist entries. This matching will fail unexpectedly when >>> ConvertRowtypeExpr is removed from a child's targetlist. But again I >>> couldn't reproduce a problem when such a mismatch arises. >> >> >> IIUC, I don't think the planner assumes that for an equivalence member there >> is an matching entry for that member in the targetlist; what I think the >> planner assumes is: an equivalence member is able to be computed from >> expressions in the targetlist. > > This is true. However, > >> So, I think it is safe to have whole-row >> Vars instead of ConvertRowtypeExprs in the targetlist. > > when it's looking for an expression, it finds a whole-row expression > so it think it needs to add a ConvertRowtypeExpr on that. But when the > plan is created, there is ConvertRowtypeExpr already, but there is no > way to know that a new ConvertRowtypeExpr is not needed anymore. So, > we may have two ConvertRowtypeExprs giving wrong results. Maybe I'm missing something, but I don't think that we need to worry about that, because in the approach I proposed, we only add CREs above whole-row Vars in the targetlists for subplans of an Append/MergeAppend for a partitioned relation at plan creation time. Best regards, Etsuro Fujita