Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fBffn-00011w-Ec for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Apr 2018 12:06:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fBffj-0007TT-Cn for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Apr 2018 12:06:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fBffj-0007TJ-5l for pgsql-hackers@lists.postgresql.org; Thu, 26 Apr 2018 12:06:47 +0000 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fBffa-0002bl-FP for pgsql-hackers@postgresql.org; Thu, 26 Apr 2018 12:06:45 +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 w3QC6XIS024645; Thu, 26 Apr 2018 21:06:33 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 1D8D7639686; Thu, 26 Apr 2018 21:06:33 +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 121CB638D43; Thu, 26 Apr 2018 21:06:33 +0900 (JST) Received: from [IPv6:::1] (unknown [129.60.241.75]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 0DF5D4007E0; Thu, 26 Apr 2018 21:06:33 +0900 (JST) Message-ID: <5AE1C0D3.5060009@lab.ntt.co.jp> Date: Thu, 26 Apr 2018 21:06:43 +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: <5AD5B1E0.8020404@lab.ntt.co.jp> <5AD5C5A1.1070509@lab.ntt.co.jp> <5ADF12D1.1030406@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/04/25 18:51), Ashutosh Bapat wrote: > On Tue, Apr 24, 2018 at 4:49 PM, Etsuro Fujita > wrote: >> o 0001-Handle-ConvertRowtypeExprs-in-pull_vars_clause.patch: >> Another thing I noticed about this patch is this: >> >> postgres=# create table prt1 (a int, b int, c varchar) partition by range >> (a); >> postgres=# create table prt1_p1 partition of prt1 FOR VALUES FROM (0) TO >> (250); >> postgres=# create table prt1_p2 partition of prt1 FOR VALUES FROM (250) TO >> (500) >> ; >> postgres=# insert into prt1 select i, i % 25, to_char(i, 'FM0000') from >> generate >> _series(0, 499) i where i % 2 = 0; >> postgres=# analyze prt1; >> postgres=# create table prt2 (a int, b int, c varchar) partition by range >> (b); >> postgres=# create table prt2_p1 partition of prt2 FOR VALUES FROM (0) TO >> (250); >> postgres=# create table prt2_p2 partition of prt2 FOR VALUES FROM (250) TO >> (500) >> ; >> postgres=# insert into prt2 select i % 25, i, to_char(i, 'FM0000') from >> generate >> _series(0, 499) i where i % 3 = 0; >> postgres=# analyze prt2; >> >> postgres=# update prt1 t1 set c = 'foo' from prt2 t2 where t1::text = >> t2::text a >> nd t1.a = t2.b; >> ERROR: ConvertRowtypeExpr found where not expected >> >> To fix this, I think we need to pass PVC_RECURSE_CONVERTROWTYPES to >> pull_vars_clause() in distribute_qual_to_rels() and >> generate_base_implied_equalities_no_const() as well. > > Thanks for the catch. I have updated patch with your suggested fix. Thanks, but I don't think that's enough. Consider: postgres=# create table base_tbl (a int, b int); postgres=# insert into base_tbl select i % 25, i from generate_series(0, 499) i where i % 6 = 0; postgres=# update prt1 t1 set c = 'foo' from prt2 t2 left join (select a, b, 1 from base_tbl) ss(c1, c2, c3) on (t2.b = ss.c2) where t1::text = t2::text and t1.a = t2.b; ERROR: ConvertRowtypeExpr found where not expected To fix this, I think we need to pass PVC_RECURSE_CONVERTROWTYPES to pull_var_clause() in find_placeholders_in_expr() as well. The patch doesn't pass that to pull_var_clause() in other places such as fix_placeholder_input_needed_levels() or planner.c, but I don't understand the reason why that's OK. Sorry, I've not finished the review yet, so I'll continue that. Thanks for updating the patch! Best regards, Etsuro Fujita