Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dURE6-0003WU-IQ for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Jul 2017 05:27:18 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dURE5-0006Dx-9i for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Jul 2017 05:27: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.84_2) (envelope-from ) id 1dURCY-0003X8-JB for pgsql-hackers@postgresql.org; Mon, 10 Jul 2017 05:25:42 +0000 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dURCV-0004O4-3i for pgsql-hackers@postgresql.org; Mon, 10 Jul 2017 05:25:40 +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 v6A5PbnI007787 for ; Mon, 10 Jul 2017 14:25:37 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 785085F63F; Mon, 10 Jul 2017 14:25:37 +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 6C40E5F594; Mon, 10 Jul 2017 14:25:37 +0900 (JST) Received: from [IPv6:::1] (unknown [129.60.241.75]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 54F94400A15; Mon, 10 Jul 2017 14:25:37 +0900 (JST) From: Etsuro Fujita Subject: Re: Oddity in error handling of constraint violation in ExecConstraints for partitioned tables References: <8189d29e-27be-5c5c-a708-5e1f64ae6566@lab.ntt.co.jp> Message-ID: <56e0baa8-e458-2bbb-7936-367f7d832e43@lab.ntt.co.jp> Date: Mon, 10 Jul 2017 14:15:41 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <8189d29e-27be-5c5c-a708-5e1f64ae6566@lab.ntt.co.jp> Content-Type: multipart/mixed; boundary="------------2A1EC38380D2551B06AB1456" Content-Language: en-US To: Amit Langote , pgsql-hackers@postgresql.org X-TM-AS-MML: disable List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This is a multi-part message in MIME format. --------------2A1EC38380D2551B06AB1456 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 2017/07/07 18:47, Amit Langote wrote: > On 2017/07/06 16:06, Etsuro Fujita wrote: >> I think this should be fixed. Attached is a patch for that. > > Looking up the ResultRelInfo using the proposed method in > ExecFindResultRelInfo() can be unreliable sometimes, that is, the method > of using the root table OID to pin down the RangeTableEntry to get the the > modified columns set. You are right. Thank you for pointing that out. > How about setting ri_RangeTableIndex of the partition ResultRelInfo > correctly in the first place? If you look at the way InitResultRelInfo() > is called in ExecSetupPartitionTupleRouting(), a dummy RT index of 1 is > passed. We could instead pass the correct one. I think > ModifyTable.nominalRelation is that (at least in the INSERT case. > > The attached patch implements that. It modifies > ExecSetupPartitionTupleRouting to accept one more argument resultRTindex > and passes along the same to InitResultRelInfo(). Later when > ExecConstraints() wants to build the modifiedCols set, it looks up the > correct RTE using the partition ResultRelInfo, which has the appropriate > ri_RangeTableIndex set and uses the same. Looks good to me. > The patch keeps tests that you added in your patch. Added this to the > open items list. Another thing I noticed is the error handling in ExecWithCheckOptions; it doesn't take any care for partition tables, so the column description in the error message for WCO_VIEW_CHECK is built using the partition table's rowtype, not the root table's. But I think it'd be better to build that using the root table's rowtype, like ExecConstraints, because that would make the column description easier to understand since the parent view(s) (from which WithCheckOptions evaluated there are created) would have been defined on the root table. This seems independent from the above issue, so I created a separate patch, which I'm attaching. What do you think about that? Best regards, Etsuro Fujita --------------2A1EC38380D2551B06AB1456 Content-Type: text/plain; charset=UTF-8; name="ExecWithCheckOptions.patch" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="ExecWithCheckOptions.patch" KioqIGEvc3JjL2JhY2tlbmQvZXhlY3V0b3IvZXhlY01haW4uYwotLS0gYi9z cmMvYmFja2VuZC9leGVjdXRvci9leGVjTWFpbi5jCioqKioqKioqKioqKioq KgoqKiogMjA5NywyMTAyICoqKiogRXhlY1dpdGhDaGVja09wdGlvbnMoV0NP S2luZCBraW5kLCBSZXN1bHRSZWxJbmZvICpyZXN1bHRSZWxJbmZvLAotLS0g MjA5NywyMTIxIC0tLS0KICAJCQkJCSAqIFVTSU5HIHBvbGljeS4KICAJCQkJ CSAqLwogIAkJCQljYXNlIFdDT19WSUVXX0NIRUNLOgorIAkJCQkJLyogU2Vl IHRoZSBjb21tZW50IGluIEV4ZWNDb25zdHJhaW50cygpLiAqLworIAkJCQkJ aWYgKHJlc3VsdFJlbEluZm8tPnJpX1BhcnRpdGlvblJvb3QpCisgCQkJCQl7 CisgCQkJCQkJSGVhcFR1cGxlCXR1cGxlID0gRXhlY0ZldGNoU2xvdFR1cGxl KHNsb3QpOworIAkJCQkJCVR1cGxlRGVzYwlvbGRfdHVwZGVzYyA9IFJlbGF0 aW9uR2V0RGVzY3IocmVsKTsKKyAJCQkJCQlUdXBsZUNvbnZlcnNpb25NYXAg Km1hcDsKKyAKKyAJCQkJCQlyZWwgPSByZXN1bHRSZWxJbmZvLT5yaV9QYXJ0 aXRpb25Sb290OworIAkJCQkJCXR1cGRlc2MgPSBSZWxhdGlvbkdldERlc2Ny KHJlbCk7CisgCQkJCQkJLyogYSByZXZlcnNlIG1hcCAqLworIAkJCQkJCW1h cCA9IGNvbnZ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REVUQUlMOiAgRmFpbGluZyByb3cgY29udGFpbnMgKDIsIDEpLgogIGRyb3Ag dmlldyBwdHYsIHB0dl93Y287CiAgZHJvcCB0YWJsZSBwdCwgcHQxLCBwdDEx OwotLS0gMjQyNCwyNDI5IC0tLS0KICBjcmVhdGUgdmlldyBwdHZfd2NvIGFz IHNlbGVjdCAqIGZyb20gcHQgd2hlcmUgYSA9IDAgd2l0aCBjaGVjayBvcHRp b247CiAgaW5zZXJ0IGludG8gcHR2X3djbyB2YWx1ZXMgKDEsIDIpOwogIEVS Uk9SOiAgbmV3IHJvdyB2aW9sYXRlcyBjaGVjayBvcHRpb24gZm9yIHZpZXcg InB0dl93Y28iCiEgREVUQUlMOiAgRmFpbGluZyByb3cgY29udGFpbnMgKDEs IDIpLgogIGRyb3AgdmlldyBwdHYsIHB0dl93Y287CiAgZHJvcCB0YWJsZSBw dCwgcHQxLCBwdDExOwo= --------------2A1EC38380D2551B06AB1456 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --------------2A1EC38380D2551B06AB1456--