Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hBzeZ-0004DB-9t for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Apr 2019 10:31:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hBzeX-0003Cy-U9 for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Apr 2019 10:31:25 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hBzeX-0003Cr-Md for pgsql-bugs@lists.postgresql.org; Thu, 04 Apr 2019 10:31:25 +0000 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hBzeV-000645-8I for pgsql-bugs@lists.postgresql.org; Thu, 04 Apr 2019 10:31:25 +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 x34AVLc5016176; Thu, 4 Apr 2019 19:31:21 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id C7469EA8554; Thu, 4 Apr 2019 19:31:21 +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 BCBABEA813A; Thu, 4 Apr 2019 19:31:21 +0900 (JST) Received: from [127.0.0.1] (unknown [129.60.241.61]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id B72B3400551; Thu, 4 Apr 2019 19:31:21 +0900 (JST) Subject: Re: BUG #15733: An insert destined at partition created after a column has been dropped from the parent table fails References: <15733-7692379e310b80ec@postgresql.org> <20190404013510.GB7693@paquier.xyz> From: Amit Langote Message-ID: Date: Thu, 4 Apr 2019 19:31:09 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190404013510.GB7693@paquier.xyz> Content-Type: multipart/mixed; boundary="------------F81370769A36D047C888F5F7" Content-Language: en-US X-CC-Mail-RelayStamp: 1 To: Michael Paquier , petr.fedorov@phystech.edu, pgsql-bugs@lists.postgresql.org X-TM-AS-MML: disable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------F81370769A36D047C888F5F7 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Hi Petr, Michael, On 2019/04/04 10:35, Michael Paquier wrote: > On Wed, Apr 03, 2019 at 06:22:34PM +0000, PG Bug reporting form wrote: >> 6. FAIL: Insert the row which would land at partitioned_2_1_1: >> >> insert into partitioned values(2,2,1, 1,1); >> >> ERROR: cannot extract attribute from empty tuple slot SQL state: XX000 Thanks for the report. > Indeed. I can see that for v11 but not for HEAD. Let's keep track of > that. (Not looking at that now though) The problem seems to be present only in PG 11; not in PG 10 and HEAD, as Michael already said. It seems to have been introduced by 34295b87f in PG 11, wherein the decision of when to add a tuple to an intermediate parent's dedicated tuple routing slot is mistakenly getting mixed with the decision of whether tuple conversion is required between the parent of the previous level and the current parent. We didn't catch that error back then, because we only tried up to 2 levels of partitioning, whereas the test case presented here uses 3 levels of partitioning. In the reported test case, the 1st level needs tuple conversion (between partitioned and partitioned_2), but the next level does not (between partitioned_2 and partitioned_2_1), so the slot used when routing through partitioned_2_1 to the last level doesn't contain a tuple to extract the partition key from, hence the error. Attached patch fixes this. Thanks, Amit --------------F81370769A36D047C888F5F7 Content-Type: text/plain; charset=UTF-8; name="v1-0001-Fix-a-bug-in-multi-level-tuple-routing.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="v1-0001-Fix-a-bug-in-multi-level-tuple-routing.patch"