Re: [HACKERS] Proposal: Local indexes for partitioned table
Alvaro Herrera <alvherre@alvh.no-ip.org>
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Robert Haas <robertmhaas@gmail.com>
Cc: David Rowley <david.rowley@2ndquadrant.com>, Simon Riggs <simon@2ndquadrant.com>, Pg Hackers <pgsql-hackers@postgresql.org>, Maksim Milyutin <milyutinma@gmail.com>
Date: 2017-12-15T22:12:43Z
Lists: pgsql-hackers
Robert Haas wrote: > On Thu, Nov 30, 2017 at 7:02 AM, Alvaro Herrera <alvherre@alvh.no-ip.org> wrote: > > Great question. So you're thinking that the planner might have an > > interest in knowing what indexes are defined at the parent table level > > for planning purposes; but for that to actually have any effect we would > > need to change the planner and executor also. And one more point, also > > related to something you said before: we currently (I mean after my > > patch) don't mark partitioned-table-level indexes as valid or not valid > > depending on whether all its children exist, so trying to use that in > > the planner without having a flag could cause invalid plans to be > > generated (i.e. ones that would cause nonexistent indexes to be > > referenced). > > Did you do it this way due to locking concerns? No -- just because since the index-on-parent is a different kind of object (RELKIND_PARTITIONED_INDEX) it is not considered for anything in the planner anyway, so there's no need for indisvalid to be "correct". Changing the flag in the parent index only needs to examine state on the children, not modify them, so I don't think there would be any serious locking problem. By the way, my implementation of ALTER INDEX ATTACH PARTITION was prone to deadlocks because it needs locks on parent table, index-on-parent, partition, and index-on-partition; and there was no consideration to the ordering in which these were being acquired. I wrote a callback for RangeVarGetRelidExtended to be called in ATExecAttachPartitionIdx() that tries to acquire locks in the right order -- but I recently realized that even that is not sufficient, because (unless I misread it) ALTER INDEX itself does not worry about locking the containing table before the index. I think some tweaking needs to be done in RangeVarCallbackForAlterRelation to lock the table if an index is being altered (conditionally, depending on the precise ALTER TABLE operation). It surprises me that we don't need to do that yet, but I haven't looked into it any further. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
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