pgsql: Avoid creating duplicate cached plans for inherited FK constrain

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Avoid creating duplicate cached plans for inherited FK constrain
Date: 2021-03-10 19:22:42
Message-ID: E1lK4Pq-0002oG-Sm@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Avoid creating duplicate cached plans for inherited FK constraints.

When a foreign key constraint is applied to a partitioned table, each
leaf partition inherits a similar FK constraint. We were processing all
of those constraints independently, meaning that in large partitioning
trees we'd build up large collections of cached FK-checking query plans.
However, in all cases but one, the generated queries are actually
identical for all members of the inheritance tree (because, in most
cases, the query only mentions the topmost table of the other side of
the FK relationship). So we can share a single cached plan among all
the partitions, saving memory, not to mention time to build and maintain
the cached plans.

Keisuke Kuroda and Amit Langote

Discussion: https://postgr.es/m/cab4b85d-9292-967d-adf2-be0d803c3e23@nttcom.co.jp_1

Branch
------
master

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

Modified Files
--------------
src/backend/utils/adt/ri_triggers.c | 67 +++++++++++++++++++++++++++++--
src/test/regress/expected/foreign_key.out | 18 +++++++++
src/test/regress/sql/foreign_key.sql | 16 ++++++++
3 files changed, 97 insertions(+), 4 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Thomas Munro 2021-03-10 21:46:28 pgsql: Replace buffer I/O locks with condition variables.
Previous Message Tom Lane 2021-03-10 17:38:48 pgsql: Doc: get rid of <foreignphrase> tags.