Re: Partitioning option for COPY

From: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
To: Emmanuel Cecchet <manu(at)asterdata(dot)com>
Cc: Itagaki Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, Simon Riggs <simon(at)2ndquadrant(dot)com>, Emmanuel Cecchet <Emmanuel(dot)Cecchet(at)asterdata(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Partitioning option for COPY
Date: 2009-11-25 10:03:17
Message-ID: 1259143397.30357.170.camel@hvost1700
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, 2009-11-24 at 10:08 -0500, Emmanuel Cecchet wrote:
> Itagaki Takahiro wrote:
> > I just edited a wiki page for this discussion.
> > I hope it can be a help.
> > http://wiki.postgresql.org/wiki/Table_partitioning
> >
> I guess the problem of handling user triggers is still open.
> If we allow triggers on partitions, badly written logic could lead to
> infinite loops in routing. In the case of COPY, an after statement
> trigger could change all the routing decisions taken for each row.

A simple update to the row can cause it to move between partitions, no ?

> I am not sure what the semantic should be if you have triggers defined on the
> parent and child tables. Which triggers do you fire if the insert is on
> the parent table but the tuple ends up in a child table?

I'd propose that triggers on both parent table and selected child are
executed.

1. first you execute before triggers on parent table, which may
change which partition the row belongs to

2. then you execute before triggers on selected child table

2.1 if this changes the child table selection repeat from 2.

3. save the tuple in child table

4. execute after triggers of the final selected child table

5. execute after triggers of parent table

order of 4. and 5. is selected arbitrarily, others are determined by
flow.

> If the new implementation hides the child tables,

If you hide child tables, you suddenly need a lot of new syntax to
"unhide" them, so that partitions can be manipulated. Currently it is
easy to do it with INHERIT / NO INHERIT.

> it might be safer to
> not allow triggers on child tables altogether and use the parent table
> as the single point of entry to access the partition (and define
> triggers). With the current proposed implementation, would it be
> possible to define a view using child tables?

the child tables are there, and they _are_ defined, either implicitly
(using constraints, which "constraint exclusion" resolves to a set of
child tables) or explicitly, using child table names directly.

--
Hannu Krosing http://www.2ndQuadrant.com
PostgreSQL Scalability and Availability
Services, Consulting and Training

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Hannu Krosing 2009-11-25 10:26:39 Re: [PATCH 4/4] Add tests to dblink covering use of COPY TO FUNCTION
Previous Message Magnus Hagander 2009-11-25 10:02:52 Re: enable-thread-safety defaults?