Re: Proposal: Local indexes for partitioned table
Robert Haas <robertmhaas@gmail.com>
From: Robert Haas <robertmhaas@gmail.com>
To: Maksim Milyutin <m.milyutin@postgrespro.ru>
Cc: Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2017-03-02T08:41:47Z
Lists: pgsql-hackers
On Wed, Mar 1, 2017 at 4:23 PM, Maksim Milyutin <m.milyutin@postgrespro.ru> wrote: > As I've understood from thread [1] the main issue of creating local indexes > for partitions is supporting REINDEX and DROP INDEX operations on parent > partitioned tables. Furthermore Robert Haas mentioned the problem of > creating index on key that is represented in partitions with single value > (or primitive interval) [1] i.e. under the list-partitioning or > range-partitioning with unit interval. > > I would like to propose the following solution: > > 1. Create index for hierarchy of partitioned tables and partitions > recursively. Don't create relfilenode for indexes on parents, only entries > in catalog (much like the partitioned table's storage elimination in [2]). > Abstract index for partitioned tables is only for the reference on indexes > of child tables to perform REINDEX and DROP INDEX operations. > > 2. Specify created indexes in pg_depend table so that indexes of child > tables depend on corresponding indexes of parent tables with type of > dependency DEPENDENCY_NORMAL so that index could be removed separately for > partitions and recursively/separately for partitioned tables. > > 3. REINDEX on index of partitioned table would perform this operation on > existing indexes of corresponding partitions. In this case it is necessary > to consider such operations as REINDEX SCHEMA | DATABASE | SYSTEM so that > partitions' indexes wouldn't be re-indexed multiple times in a row. > > Any thoughts? Sounds generally good. One thing to keep in mind is that - in this system - a UNIQUE index on the parent doesn't actually guarantee uniqueness across the whole partitioning hierarchy unless it so happens that the index columns or expressions are the same as the partitioning columns or expressions. That's a little a counterintuitive, and people have already been complaining that a partitioned table + partitions doesn't look enough like a plain table. However, I'm not sure there's a better alternative, because somebody might want partition-wise unique indexes even though that doesn't guarantee global uniqueness. So I think if someday we have global indexes, then we can plan to use some other syntax for that, like CREATE GLOBAL [ UNIQUE ] INDEX. But, of course, that's just my opinion. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
Commits
-
Local partitioned indexes
- 8b08f7d4820f 11.0 landed
-
Fix StoreCatalogInheritance1 to use 32bit inhseqno
- 1ef61ddce908 11.0 landed
- 9a215fb4b5ec 9.3.21 landed
- 8a71ee628854 9.6.7 landed
- 61f08c016322 10.2 landed
- 1284d18b5de9 9.4.16 landed
- 0d993709a773 9.5.11 landed
-
Get rid of copy_partition_key
- 8a0596cb656e 11.0 landed
-
Simplify index_[constraint_]create API
- a61f5ab98638 11.0 landed