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 1fg0VE-0006uy-5E for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Jul 2018 04:25:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fg0VB-0004fU-4C for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Jul 2018 04:25:17 +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 1fg0VA-0004f0-Q4 for pgsql-hackers@lists.postgresql.org; Thu, 19 Jul 2018 04:25:16 +0000 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fg0V6-0000Of-Sq for pgsql-hackers@postgresql.org; Thu, 19 Jul 2018 04:25:15 +0000 Received: from vc1.ecl.ntt.co.jp (vc1.ecl.ntt.co.jp [129.60.86.153]) by tama500.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id w6J4P9b0013186; Thu, 19 Jul 2018 13:25:09 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id D925CEA7A24; Thu, 19 Jul 2018 13:25:09 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id C40C5EA7957; Thu, 19 Jul 2018 13:25:09 +0900 (JST) Received: from [IPv6:::1] (unknown [129.60.241.75]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id B817C400864; Thu, 19 Jul 2018 13:25:09 +0900 (JST) Message-ID: <5B50129F.5020903@lab.ntt.co.jp> Date: Thu, 19 Jul 2018 13:25: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: <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> <5B46CBB3.2090300@lab.ntt.co.jp> <5B47352D.3030100@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/13 23:05), Ashutosh Bapat wrote: > On Thu, Jul 12, 2018 at 4:32 PM, Etsuro Fujita > wrote: >> In this example, the value of the whole-row reference to the child table >> ptp1 for that record is ('foo',1), and that of the index expression for that >> record is (1,'foo'). Those have different column orders, but the latter >> could be mapped to the former by a technique like do_convert_tuple. > The expression in this case would look like ptp1::pt::ptp1 which won't > match targetlist expression ptp1. I am also doubtful that the planner > will be able to deduce that it need to apply an inverse function of > ::pt and what exactly such an inverse function is. So index only scan > won't be picked. >> we could support index-only scans >> with such an index in the case where we have the whole-row reference in the >> targetlist, not the index expression itself. > > Can you please show an index only scan path being created in this case? We currently don't consider index-only scan with index expressions, so I haven't thought in detail yet about how the planner would work. But once we have that index-only scan, I think we could extend that to the case mentioned above, by adding this to the planner: if the index expression is of the form var::parenttype, consider that (not only the expression itself but) var can be returned from the index. I think the expression like ptp1::pt::ptp1 would be useful to get the value of ptp1 from the index at execution time. >>> There's a patch in an adjacent thread started by David Rowley to rip >>> out Append/MergeAppend when there is only one subplan. So, your >>> solution won't work there. >> >> >> Thanks for sharing that information! I skimmed the thread. I haven't yet >> caught up with all the discussions there, so I think I'm missing something, >> but it looks like that we haven't yet reached any consensus on the way to >> go. In my opinion, I like the approach mentioned in [1]. And if we go that >> way, my patch seems to fit into that, because in that approach the >> Append/MergeAppend could be removed after adjusting the targetlists for its >> subplans in create_append_plan/create_merge_append_plan. Anyway, I'd like >> to join in that work for PG12. > > Whatever may be the outcome of that work, I think what we fix here > shouldn't require to reverted in a few months from now, just so that > that patch works. I think we could add that optimization without reverting this change because the essential part of this change is to make create_plan adjust the tlists of the subplans based on the instruction stored into the subplans' RelOptInfos (ie, need_adjust_tlist in the second version of the patch). I think this technique could be extended even to the case where we have that optimization. Best regards, Etsuro Fujita