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/[email protected]_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(-)

Reply via email to