pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dmitry Ivanov <d.ivanov@postgrespro.ru>
To: Dmitry Ivanov <d.ivanov@postgrespro.ru>
Cc: Robert Haas <robertmhaas@gmail.com>
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:45:38 +0300
Message-ID: <0d5b64c9-fa05-4dab-93e7-56576d1193ca@postgrespro.ru> (raw)
In-Reply-To: <e6c56fe9-4b87-4f64-ac6f-bc99675f3f9e@postgrespro.ru>
References: <890ce68d-2cff-ccf3-67f7-6f5d3264dbfc@lab.ntt.co.jp>
	<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>
	<e6c56fe9-4b87-4f64-ac6f-bc99675f3f9e@postgrespro.ru>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

Huh, this code is broken as well. We have to ignore partitions that don't 
have any subpartitions. Patch is attached below (v2).


-- 
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-hackers

Attachments:

  [text/x-patch] hacky_partitioning_hotfix_v2.diff (1.7K, ../0d5b64c9-fa05-4dab-93e7-56576d1193ca@postgrespro.ru/2-hacky_partitioning_hotfix_v2.diff)
  download | inline diff:
diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.c
index 219d380..6555c7c 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,
+				partitioned_children_so_far = 0;
 
 	/*
 	 * Lock partitions and make a list of the partitioned ones to prepare
@@ -1001,7 +1002,7 @@ RelationGetPartitionDispatchInfo(Relation rel, int lockmode,
 		PartitionKey partkey = RelationGetPartitionKey(partrel);
 		PartitionDesc partdesc = RelationGetPartitionDesc(partrel);
 		int			j,
-					m;
+					my_partitioned_children;
 
 		pd[i] = (PartitionDispatch) palloc(sizeof(PartitionDispatchData));
 		pd[i]->reldesc = partrel;
@@ -1010,7 +1011,7 @@ RelationGetPartitionDispatchInfo(Relation rel, int lockmode,
 		pd[i]->partdesc = partdesc;
 		pd[i]->indexes = (int *) palloc(partdesc->nparts * sizeof(int));
 
-		m = 0;
+		my_partitioned_children = 0;
 		for (j = 0; j < partdesc->nparts; j++)
 		{
 			Oid			partrelid = partdesc->oids[j];
@@ -1026,11 +1027,21 @@ 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);
-				m++;
+				pd[i]->indexes[j] = -(1 +
+									  my_partitioned_children +
+									  partitioned_children_so_far);
+
+				my_partitioned_children++;
 			}
 		}
 		i++;
+
+		/*
+		 * Children of this parent should be placed after all
+		 * partitioned children of all previous parents, so we
+		 * have to take this into account.
+		 */
+		partitioned_children_so_far += my_partitioned_children;
 	}
 
 	return pd;


view thread (329+ messages)  latest in thread

Message-ID: <0d5b64c9-fa05-4dab-93e7-56576d1193ca@postgrespro.ru>
Permalink:  ../0d5b64c9-fa05-4dab-93e7-56576d1193ca@postgrespro.ru/
Also on:    postgresql.org/message-id/0d5b64c9-fa05-4dab-93e7-56576d1193ca@postgrespro.ru

 ·  · 

reply

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: <0d5b64c9-fa05-4dab-93e7-56576d1193ca@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