Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cGUEn-0000Bh-Lq for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Dec 2016 17:18:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cGUEn-0006ZJ-8r for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Dec 2016 17:18:05 +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 1cGUDM-0003Cc-Sz; Mon, 12 Dec 2016 17:16:37 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cGUDJ-00046Q-8a; Mon, 12 Dec 2016 17:16:35 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 0D4F421C565E; Mon, 12 Dec 2016 20:16:31 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Received: from mail.postgrespro.ru ([127.0.0.1]) by localhost (mail.postgrespro.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gyMtwq8I-3CT; Mon, 12 Dec 2016 20:16:30 +0300 (MSK) Received: from localhost (unknown [192.168.27.1]) by mail.postgrespro.ru (Postfix) with ESMTPSA id C461821C5644; Mon, 12 Dec 2016 20:16:30 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1481562990; bh=5Bcsml5WOtP++0GEAlS3ww7nHO2p2RZrISlZaKHJsyM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ahntuwm+jyaOTzOWXLPJRBWW4Ndleyfsp0Qs/FV6Xm3dRCwE+8NY1Vnxh63RMooJP wp6PdTCEaoFbmWEhBPsG1aQ7fGA9w5cB013HNZR1Jry77f28l9rXp6vIsnx6hvLW2F 8ezK3k0QCFsZfEgOacXhFLDNp1HpOCQQueHGnoBk= From: Dmitry Ivanov To: Robert Haas Cc: Dmitry Ivanov , Michael Paquier , Andres Freund , Erik Rijkers , Amit Langote , Amit Langote , Rajkumar Raghuwanshi , Ashutosh Bapat , Pg Hackers , Subject: Re: Declarative partitioning - another take Date: Mon, 12 Dec 2016 20:14:14 +0300 MIME-Version: 1.0 Message-ID: In-Reply-To: References: <890ce68d-2cff-ccf3-67f7-6f5d3264dbfc@lab.ntt.co.jp> <78ae9888-7372-245d-cf6b-f655e6fe6c12@lab.ntt.co.jp> <20161208043942.ekjvyf7ddbxehh7c@alap3.anarazel.de> <426b2b01-61e0-43aa-bd84-c6fcf516f1c3@postgrespro.ru> Organization: Postgres Professional User-Agent: Trojita/0.7; Qt/5.7.0; xcb; Linux; Content-Type: multipart/mixed; boundary="trojita=_13b243bb-64ca-499f-ba65-988d81f20596" X-Pg-Spam-Score: -5.0 (-----) 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 multipart/mixed message in MIME format. --trojita=_13b243bb-64ca-499f-ba65-988d81f20596 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Hi guys, Looks like I've just encountered a bug. Please excuse me for the messy=20 email, I don't have much time at the moment. Here's the test case: create table test(val int) partition by range (val); create table test_1 partition of test for values from (1) to (1000)=20 partition by range(val); create table test_2 partition of test for values from (1000) to (2000)=20 partition by range(val); create table test_1_1 partition of test_1 for values from (1) to (500)=20 partition by range(val); create table test_1_2 partition of test_1 for values from (500) to (1000)=20 partition by range(val); create table test_1_1_1 partition of test_1_1 for values from (1) to (500); create table test_1_2_1 partition of test_1_2 for values from (500) to=20 (1000); /* insert a row into "test_1_2_1" */ insert into test values(600); /* what we EXPECT to see */ select *, tableoid::regclass from test; val | tableoid=20=20 -----+------------ 600 | test_1_2_1 (1 row) /* what we ACTUALLY see */ insert into test values(600); ERROR: no partition of relation "test_1_1" found for row DETAIL: Failing row contains (600). How does this happen? This is how "PartitionDispatch" array looks like: test | test_1 | test_2 | test_1_1 | test_1_2 which means that this code (partition.c : 1025): /* * We can assign indexes this way because of the way * parted_rels has been generated. */ pd[i]->indexes[j] =3D -(i + 1 + m); doesn't work, since partitions are not always placed right after the parent= =20 (implied by index "m"). We have to take into account the total amount of partitions we've=20 encountered so far (right before index "i"). I've attached a patch with a hotfix, but the code looks so-so and has a=20 smell. I think it must be rewritten. This bug hunt surely took a while: I=20 had to recheck all of the steps several times. --=20 Dmitry Ivanov Postgres Professional: http://www.postgrespro.com Russian Postgres Company= --trojita=_13b243bb-64ca-499f-ba65-988d81f20596 Content-Type: text/x-patch Content-Disposition: attachment; filename=hacky_partitioning_hotfix.diff Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL2NhdGFsb2cvcGFydGl0aW9uLmMg Yi9zcmMvYmFja2VuZC9jYXRhbG9nL3BhcnRpdGlvbi5jCmluZGV4IDIxOWQz ODAuLjExOWE0MWQgMTAwNjQ0Ci0tLSBhL3NyYy9iYWNrZW5kL2NhdGFsb2cv cGFydGl0aW9uLmMKKysrIGIvc3JjL2JhY2tlbmQvY2F0YWxvZy9wYXJ0aXRp b24uYwpAQCAtOTUwLDcgKzk1MCw4IEBAIFJlbGF0aW9uR2V0UGFydGl0aW9u RGlzcGF0Y2hJbmZvKFJlbGF0aW9uIHJlbCwgaW50IGxvY2ttb2RlLAogCQkJ ICAgKnBhcnRlZF9yZWxzOwogCUxpc3RDZWxsICAgKmxjOwogCWludAkJCWks Ci0JCQkJazsKKwkJCQlrLAorCQkJCWNoaWxkcmVuX3NvX2ZhciA9IDA7CiAK IAkvKgogCSAqIExvY2sgcGFydGl0aW9ucyBhbmQgbWFrZSBhIGxpc3Qgb2Yg dGhlIHBhcnRpdGlvbmVkIG9uZXMgdG8gcHJlcGFyZQpAQCAtMTAyNiwxMSAr MTAyNywxOCBAQCBSZWxhdGlvbkdldFBhcnRpdGlvbkRpc3BhdGNoSW5mbyhS ZWxhdGlvbiByZWwsIGludCBsb2NrbW9kZSwKIAkJCQkgKiBXZSBjYW4gYXNz aWduIGluZGV4ZXMgdGhpcyB3YXkgYmVjYXVzZSBvZiB0aGUgd2F5CiAJCQkJ ICogcGFydGVkX3JlbHMgaGFzIGJlZW4gZ2VuZXJhdGVkLgogCQkJCSAqLwot CQkJCXBkW2ldLT5pbmRleGVzW2pdID0gLShpICsgMSArIG0pOworCQkJCXBk W2ldLT5pbmRleGVzW2pdID0gLSgxICsgbSArIGNoaWxkcmVuX3NvX2Zhcik7 CiAJCQkJbSsrOwogCQkJfQogCQl9CiAJCWkrKzsKKworCQkvKgorCQkgKiBD aGlsZHJlbiBvZiB0aGlzIHBhcmVudCBhcmUgcGxhY2VkCisJCSAqIGFmdGVy IGFsbCBjaGlsZHJlbiBvZiBhbGwgcHJldmlvdXMgcGFyZW50cywKKwkJICog c28gd2UgaGF2ZSB0byB0YWtlIHRoaXMgaW50byBhY2NvdW50LgorCQkgKi8K KwkJY2hpbGRyZW5fc29fZmFyICs9IHBhcnRkZXNjLT5ucGFydHM7CiAJfQog CiAJcmV0dXJuIHBkOwo= --trojita=_13b243bb-64ca-499f-ba65-988d81f20596 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 --trojita=_13b243bb-64ca-499f-ba65-988d81f20596--