pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Create foreign key triggers in partitioned tables too
3+ messages / 3 participants
[nested] [flat]

* pgsql: Create foreign key triggers in partitioned tables too
@ 2022-01-05 22:15  Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 1 reply; 3+ messages in thread

From: Alvaro Herrera @ 2022-01-05 22:15 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Create foreign key triggers in partitioned tables too

While user-defined triggers defined on a partitioned table have
a catalog definition for both it and its partitions, internal
triggers used by foreign keys defined on partitioned tables only
have a catalog definition for its partitions.  This commit fixes
that so that partitioned tables get the foreign key triggers too,
just like user-defined triggers.  Moreover, like user-defined
triggers, partitions' internal triggers will now also have their
tgparentid set appropriately.  This is to allow subsequent commit(s)
to make the foreign key related events to be fired in some cases
using the parent table triggers instead of those of partitions'.

This also changes what tgisinternal means in some cases.  Currently,
it means either that the trigger is an internal implementation object
of a foreign key constraint, or a "child" trigger on a partition
cloned from the trigger on the parent.  This commit changes it to
only mean the former to avoid confusion.  As for the latter, it can
be told by tgparentid being nonzero, which is now true both for user-
defined and foreign key's internal triggers.

Author: Amit Langote <amitlangote09@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Arne Roland <A.Roland@index.de>
Discussion: https://postgr.es/m/CA+HiwqG7LQSK+n8Bki8tWv7piHD=PnZro2y6ysU2-28JS6cfgQ@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f4566345cf40b068368cb5617e61318da60676ec

Modified Files
--------------
src/backend/commands/tablecmds.c       | 413 +++++++++++++++++++++++++++------
src/backend/commands/trigger.c         | 101 +++++++-
src/bin/pg_dump/pg_dump.c              |  46 +++-
src/bin/pg_dump/pg_dump.h              |   2 +-
src/bin/psql/describe.c                |  10 +-
src/include/commands/trigger.h         |   4 +
src/test/regress/expected/triggers.out |   4 +-
7 files changed, 490 insertions(+), 90 deletions(-)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: pgsql: Create foreign key triggers in partitioned tables too
@ 2022-01-05 22:46  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2022-01-05 22:46 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@alvh.no-ip.org>; +Cc: pgsql-committers@lists.postgresql.org

Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> This also changes what tgisinternal means in some cases.  Currently,
> it means either that the trigger is an internal implementation object
> of a foreign key constraint, or a "child" trigger on a partition
> cloned from the trigger on the parent.  This commit changes it to
> only mean the former to avoid confusion.

Hmm, perhaps the column's description in catalogs.sgml deserves
an update?

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: pgsql: Create foreign key triggers in partitioned tables too
@ 2022-01-11 02:47  Amit Langote <amitlangote09@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Amit Langote @ 2022-01-11 02:47 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>; pgsql-committers@lists.postgresql.org

On Thu, Jan 6, 2022 at 7:46 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> > This also changes what tgisinternal means in some cases.  Currently,
> > it means either that the trigger is an internal implementation object
> > of a foreign key constraint, or a "child" trigger on a partition
> > cloned from the trigger on the parent.  This commit changes it to
> > only mean the former to avoid confusion.
>
> Hmm, perhaps the column's description in catalogs.sgml deserves
> an update?

tginternal's description in catalogs.sgml is this:

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>tgisinternal</structfield> <type>bool</type>
      </para>
      <para>
       True if trigger is internally generated (usually, to enforce
       the constraint identified by <structfield>tgconstraint</structfield>)
      </para></entry>
     </row>

which matches what the commit restores tgisinternal's meaning to.  I
guess we forgot in 86f575948c77 to update this to mention
tgisinternal's relation to partitioning?

-- 
Amit Langote
EDB: http://www.enterprisedb.com





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2022-01-11 02:47 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-01-05 22:15 pgsql: Create foreign key triggers in partitioned tables too Alvaro Herrera <alvherre@alvh.no-ip.org>
2022-01-05 22:46 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-01-11 02:47   ` Amit Langote <amitlangote09@gmail.com>

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