Re: Declarative partitioning - another take
Robert Haas <robertmhaas@gmail.com>
On Mon, Apr 24, 2017 at 6:43 AM, Amit Langote <Langote_Amit_f8@lab.ntt.co.jp> wrote: > The reason it doesn't work is that we do not allocate ResultRelInfos for > partitioned tables (not even for the root partitioned table in the > update/delete cases), because the current implementation assumes they are > not required. That's fine only so long as we consider that no rows are > inserted into them, no indexes need to be updated, and that no row-level > triggers are to be fired. But it misses the fact that we do allow > statement-level triggers on partitioned tables. So, we should fix things > such that ResultRelInfos are allocated so that any statement-level > triggers are fired. But there are following questions to consider: > > 1. Should we consider only the root partitioned table or all partitioned > tables in a given hierarchy, including the child partitioned tables? > Note that this is related to a current limitation of updating/deleting > inheritance hierarchies that we do not currently fire per-statement > triggers of the child tables. See the TODO item in wiki: > https://wiki.postgresql.org/wiki/Todo#Triggers, which says: "When > statement-level triggers are defined on a parent table, have them fire > only on the parent table, and fire child table triggers only where > appropriate" > > 2. Do we apply the same to inserts on the partitioned tables? Since > insert on a partitioned table implicitly affects its partitions, one > might say that we would need to fire per-statement insert triggers of > all the partitions. It seems to me that it doesn't make a lot of sense to fire the triggers for some tables involved in the hierarchy and not others. I suppose the consistent thing to do here is to make sure that we fire the statement triggers for all tables in the partitioning hierarchy for all operations (insert, update, delete, etc.). TBH, I don't like that very much. I'd rather fire the triggers only for the table actually named in the query and skip all the others, mostly because it seems like it would be faster and less likely to block future optimizations; eventually, I'd like to consider not even locking the children we're not touching, but that's not going to work if we have to check them all for triggers. So what I'd prefer -- on the totally unprincipled basis that it would let us improve performance in the future -- if you operate on a partition directly, you fire the partition's triggers, but if you operate on the parent, only the parent's triggers fire. How heretical is that idea? -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
Commits
-
Fix typo.
- 03bf59676ea0 10.0 landed
-
Document trigger-firing behavior for inheritance/partitioning.
- e17628145ac3 10.0 landed
-
Fire per-statement triggers on partitioned tables.
- e180c8aa8caf 10.0 landed
-
Set ecxt_scantuple correctly for tuple routing.
- 132488bfee68 10.0 landed
-
Fix interaction of partitioned tables with BulkInsertState.
- b1ecb9b3fcfb 10.0 landed
-
Avoid core dump for empty prepared statement in an aborted transaction.
- ba61a04bc7fe 10.0 cited
-
Fix some problems in check_new_partition_bound().
- 8a8afe2f54c2 10.0 landed
-
Remove unnecessary arguments from partitioning functions.
- 18fc5192a631 10.0 cited
-
Fix reporting of constraint violations for table partitioning.
- f1b4c771ea74 10.0 cited
-
Fix tuple routing in cases where tuple descriptors don't match.
- 2ac3ef7a01df 10.0 cited
-
Invalid parent's relcache after CREATE TABLE .. PARTITION OF.
- 7cd0fd655d68 10.0 landed
-
Doc: improve documentation about inheritance.
- 162477a63d3c 10.0 cited