From: Dmitry Ivanov <d.ivanov@postgrespro.ru>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Dmitry Ivanov <d.ivanov@postgrespro.ru>
Cc: Michael Paquier <michael.paquier@gmail.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Erik Rijkers <er@xs4all.nl>
Cc: Amit Langote <amitlangote09@gmail.com>
Cc: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
Cc: Rajkumar Raghuwanshi <rajkumar.raghuwanshi@enterprisedb.com>
Cc: Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
Cc: Pg Hackers <pgsql-hackers@postgresql.org>
Cc: pgsql-hackers-owner@postgresql.org
Subject: Re: Declarative partitioning - another take
Date: Mon, 12 Dec 2016 20:14:14 +0300
Message-ID: <e6c56fe9-4b87-4f64-ac6f-bc99675f3f9e@postgrespro.ru> (raw)
In-Reply-To: <CA+TgmoarP9qWMifAfc=98M3Gz=WFsKVpYEdkjXKx5dhf7tk+tw@mail.gmail.com>
References: <890ce68d-2cff-ccf3-67f7-6f5d3264dbfc@lab.ntt.co.jp>
<CA+HiwqE1-1w9GiPE3+oje00=y5mzTu8c8XCn=9jzKW4ik+3y9w@mail.gmail.com>
<CA+Tgmob9o3+xgYHtGbfzUWm9bknRryx53Q5pEVFkzVHSDO=QXQ@mail.gmail.com>
<78ae9888-7372-245d-cf6b-f655e6fe6c12@lab.ntt.co.jp>
<ce3c665ba06aed715386e79ef2abc616@xs4all.nl>
<CA+HiwqFJ2qyA7eWfu0XLE77zhN88jMeQTxBBD_J-Uw=7YWkG_A@mail.gmail.com>
<CA+Tgmob==oNYLN2M-pVVaLNMZxqvXk3_EoUnJqqRdd-8tm0CNw@mail.gmail.com>
<bf186a19e6b16d104b997e7c1698cb56@xs4all.nl>
<CA+Tgmob6DJEQBd=qH2wZG1onYZ9R1Sji3q+GqCRUqQi+ug28Rw@mail.gmail.com>
<20161208043942.ekjvyf7ddbxehh7c@alap3.anarazel.de>
<CAB7nPqS1jYR5huoTAmCRWsjeYC=ap1qmonjM+rjKuHjqOzGaDg@mail.gmail.com>
<CA+TgmobTxn2+0x96h5Le+GOK5kw3J37SRveNfzEdx9s5-Yd8vA@mail.gmail.com>
<426b2b01-61e0-43aa-bd84-c6fcf516f1c3@postgrespro.ru>
<CA+Tgmoa8ieXx5fK1iC41jWZxCKhvnjS688RG_JO+yo7zhnOxHA@mail.gmail.com>
<c22db3f5-93f6-4015-a727-8eac50d38de1@postgrespro.ru>
<CA+TgmoarP9qWMifAfc=98M3Gz=WFsKVpYEdkjXKx5dhf7tk+tw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
Hi guys,
Looks like I've just encountered a bug. Please excuse me for the messy
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)
partition by range(val);
create table test_2 partition of test for values from (1000) to (2000)
partition by range(val);
create table test_1_1 partition of test_1 for values from (1) to (500)
partition by range(val);
create table test_1_2 partition of test_1 for values from (500) to (1000)
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
(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
-----+------------
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] = -(i + 1 + m);
doesn't work, since partitions are not always placed right after the parent
(implied by index "m").
We have to take into account the total amount of partitions we've
encountered so far (right before index "i").
I've attached a patch with a hotfix, but the code looks so-so and has a
smell. I think it must be rewritten. This bug hunt surely took a while: I
had to recheck all of the steps several times.
--
Dmitry Ivanov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company=
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackersAttachments:
[text/x-patch] hacky_partitioning_hotfix.diff (959B, ../e6c56fe9-4b87-4f64-ac6f-bc99675f3f9e@postgrespro.ru/2-hacky_partitioning_hotfix.diff)
download | inline diff:diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.cindex 219d380..119a41d 100644--- a/src/backend/catalog/partition.c+++ b/src/backend/catalog/partition.c@@ -950,7 +950,8 @@ RelationGetPartitionDispatchInfo(Relation rel, int lockmode,
*parted_rels;
ListCell *lc;
int i,
- k;+ k,+ children_so_far = 0;
/*
* Lock partitions and make a list of the partitioned ones to prepare
@@ -1026,11 +1027,18 @@ RelationGetPartitionDispatchInfo(Relation rel, int lockmode,
* We can assign indexes this way because of the way
* parted_rels has been generated.
*/
- pd[i]->indexes[j] = -(i + 1 + m);+ pd[i]->indexes[j] = -(1 + m + children_so_far);
m++;
}
}
i++;
++ /*+ * Children of this parent are placed+ * after all children of all previous parents,+ * so we have to take this into account.+ */+ children_so_far += partdesc->nparts;
}
return pd;
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: d.ivanov@postgrespro.ru, robertmhaas@gmail.com, michael.paquier@gmail.com, andres@anarazel.de, er@xs4all.nl, amitlangote09@gmail.com, Langote_Amit_f8@lab.ntt.co.jp, rajkumar.raghuwanshi@enterprisedb.com, ashutosh.bapat@enterprisedb.com, pgsql-hackers-owner@postgresql.org
Subject: Re: Declarative partitioning - another take
In-Reply-To: <e6c56fe9-4b87-4f64-ac6f-bc99675f3f9e@postgrespro.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox