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 1fGNlW-0008Ls-0e for pgsql-hackers@arkaria.postgresql.org; Wed, 09 May 2018 12:00:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fGNcN-00026h-It for pgsql-hackers@arkaria.postgresql.org; Wed, 09 May 2018 11:50: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 1fGNcN-00026X-Bp for pgsql-hackers@lists.postgresql.org; Wed, 09 May 2018 11:50:47 +0000 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fGNcF-0000xh-JQ for pgsql-hackers@postgresql.org; Wed, 09 May 2018 11:50:46 +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 w49BoR3M031231; Wed, 9 May 2018 20:50:27 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id CA35BEA7B75; Wed, 9 May 2018 20:50:27 +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 B61FAEA7B1E; Wed, 9 May 2018 20:50:27 +0900 (JST) Received: from [IPv6:::1] (unknown [129.60.241.75]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id B262E4005E9; Wed, 9 May 2018 20:50:27 +0900 (JST) Message-ID: <5AF2E09F.9060208@lab.ntt.co.jp> Date: Wed, 09 May 2018 20:50:55 +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> <5AE1C0D3.5060009@lab.ntt.co.jp> <5AE84FBF.3040905@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/05/08 16:20), Ashutosh Bapat wrote: > On Tue, May 1, 2018 at 5:00 PM, Etsuro Fujita > wrote: >> Here are my review comments on patch >> 0003-postgres_fdw-child-join-with-ConvertRowtypeExprs-cau.patch: >> >> * This assertion in deparseConvertRowtypeExpr wouldn't always be true >> because of cases like ALTER FOREIGN TABLE DROP COLUMN plus ALTER FOREIGN >> TABLE ADD COLUMN: >> >> + Assert(parent_desc->natts == child_desc->natts); >> I think we should remove that assertion. > > Removed. >> * But I don't think that change is enough. Here is another oddity with that >> assertion removed. >> To fix this, I think we should skip the deparseColumnRef processing for >> dropped columns in the parent table. > > Done. Thanks for those changes! > I have changed the test file a bit to test these scenarios. +1 >> * I think it would be better to do EXPLAIN with the VERBOSE option to the >> queries this patch added to the regression tests, to see if >> ConvertRowtypeExprs are correctly deparsed in the remote queries. > > The reason VERBOSE option was omitted for partition-wise join was to > avoid repeated and excessive output for every child-join. I think that > still applies. I'd like to leave that for the committer's judge. > PFA patch-set with the fixes. Thanks for updating the patch! > I also noticed that the new function deparseConvertRowtypeExpr is not > quite following the naming convention of the other deparseFoo > functions. Foo is usually the type of the node the parser would > produced when the SQL string produced by that function is parsed. That > doesn't hold for the SQL string produced by ConvertRowtypeExpr but > then naming it as generic deparseRowExpr() wouldn't be correct either. > And then there are functions like deparseColumnRef which may produce a > variety of SQL strings which get parsed into different node types e.g. > a whole-row reference would produce ROW(...) which gets parsed as a > RowExpr. Please let me know if you have any suggestions for the name. To be honest, I don't have any strong opinion about that. But I like "deparseConvertRowtypeExpr" because that name seems to well represent the functionality, so I'd vote for that. BTW, one thing I'm a bit concerned about is this: (2018/04/25 18:51), Ashutosh Bapat wrote: > Actually I noticed that ConvertRowtypeExpr are used to cast a child's > whole row reference expression (not just a Var node) into that of its > parent and not. For example a cast like NULL::child::parent produces a > ConvertRowtypeExpr encapsulating a NULL constant node and not a Var > node. We are interested only in ConvertRowtypeExprs embedding Var > nodes with Var::varattno = 0. I have changed this code to use function > is_converted_whole_row_reference() instead of the above code with > Assert. In order to use that function, I had to take it out of > setrefs.c and put it in nodeFuncs.c which seemed to be a better fit. This change seems a bit confusing to me because the flag bits "PVC_INCLUDE_CONVERTROWTYPES" and "PVC_RECURSE_CONVERTROWTYPES" passed to pull_var_clause look as if it handles any ConvertRowtypeExpr nodes from a given clause, but really, it only handles ConvertRowtypeExprs you mentioned above. To make that function easy to understand and use, I think it'd be better to use the IsA(node, ConvertRowtypeExpr) test as in the first version of the patch, instead of is_converted_whole_row_reference, which would be more consistent with other cases such as PlaceHolderVar. Best regards, Etsuro Fujita