From 9779abcb202ffe2d5b2ec609bde53c9563de4eb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Herrera?= Date: Fri, 16 Oct 2026 17:30:14 +0200 Subject: [PATCH] Move ForeignKeyCacheInfo to a new file For consumption by gen_node_support.pl --- src/backend/commands/tablecmds.c | 1 + src/backend/nodes/gen_node_support.pl | 2 +- src/backend/optimizer/util/plancat.c | 1 + src/backend/utils/cache/relcache.c | 1 + src/include/nodes/meson.build | 2 +- src/include/utils/rel.h | 42 ----------------------- src/include/utils/relfkcache.h | 48 +++++++++++++++++++++++++++ 7 files changed, 53 insertions(+), 44 deletions(-) create mode 100644 src/include/utils/relfkcache.h diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 93ad49e59fd..158f3e7177b 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -104,6 +104,7 @@ #include "utils/memutils.h" #include "utils/partcache.h" #include "utils/relcache.h" +#include "utils/relfkcache.h" #include "utils/ruleutils.h" #include "utils/snapmgr.h" #include "utils/syscache.h" diff --git a/src/backend/nodes/gen_node_support.pl b/src/backend/nodes/gen_node_support.pl index 0b766272018..e87a1eb9b99 100644 --- a/src/backend/nodes/gen_node_support.pl +++ b/src/backend/nodes/gen_node_support.pl @@ -73,7 +73,7 @@ my @all_input_files = qw( nodes/replnodes.h nodes/supportnodes.h nodes/value.h - utils/rel.h + utils/relfkcache.h ); # Nodes from these input files are automatically treated as nodetag_only. diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index 22e0e8b11f8..227c16f954f 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -52,6 +52,7 @@ #include "utils/lsyscache.h" #include "utils/partcache.h" #include "utils/rel.h" +#include "utils/relfkcache.h" #include "utils/snapmgr.h" #include "utils/syscache.h" diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index d8f04a05309..46592357328 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -88,6 +88,7 @@ #include "utils/inval.h" #include "utils/lsyscache.h" #include "utils/memutils.h" +#include "utils/relfkcache.h" #include "utils/relmapper.h" #include "utils/resowner.h" #include "utils/snapmgr.h" diff --git a/src/include/nodes/meson.build b/src/include/nodes/meson.build index 96800215df1..ff19fa53677 100644 --- a/src/include/nodes/meson.build +++ b/src/include/nodes/meson.build @@ -23,7 +23,7 @@ node_support_input_i = [ 'nodes/replnodes.h', 'nodes/supportnodes.h', 'nodes/value.h', - 'utils/rel.h', + 'utils/relfkcache.h', ] node_support_input = [] diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 7b8c2b1e362..2840f46a717 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -265,48 +265,6 @@ typedef struct RelationData } RelationData; -/* - * ForeignKeyCacheInfo - * Information the relcache can cache about foreign key constraints - * - * This is basically just an image of relevant columns from pg_constraint. - * We make it a subclass of Node so that copyObject() can be used on a list - * of these, but we also ensure it is a "flat" object without substructure, - * so that list_free_deep() is sufficient to free such a list. - * The per-FK-column arrays can be fixed-size because we allow at most - * INDEX_MAX_KEYS columns in a foreign key constraint. - * - * Currently, we mostly cache fields of interest to the planner, but the set - * of fields has already grown the constraint OID for other uses. - */ -typedef struct ForeignKeyCacheInfo -{ - pg_node_attr(no_equal, no_read, no_query_jumble) - - NodeTag type; - /* oid of the constraint itself */ - Oid conoid; - /* relation constrained by the foreign key */ - Oid conrelid; - /* relation referenced by the foreign key */ - Oid confrelid; - /* number of columns in the foreign key */ - int nkeys; - - /* Is enforced ? */ - bool conenforced; - - /* - * these arrays each have nkeys valid entries: - */ - /* cols in referencing table */ - AttrNumber conkey[INDEX_MAX_KEYS] pg_node_attr(array_size(nkeys)); - /* cols in referenced table */ - AttrNumber confkey[INDEX_MAX_KEYS] pg_node_attr(array_size(nkeys)); - /* PK = FK operator OIDs */ - Oid conpfeqop[INDEX_MAX_KEYS] pg_node_attr(array_size(nkeys)); -} ForeignKeyCacheInfo; - /* * StdRdOptions diff --git a/src/include/utils/relfkcache.h b/src/include/utils/relfkcache.h new file mode 100644 index 00000000000..32993eecee4 --- /dev/null +++ b/src/include/utils/relfkcache.h @@ -0,0 +1,48 @@ +#ifndef RELFKCACHE_H +#define RELFKCACHE_H + +/* + * ForeignKeyCacheInfo + * Information the relcache can cache about foreign key constraints + * + * This is basically just an image of relevant columns from pg_constraint. + * We make it a subclass of Node so that copyObject() can be used on a list + * of these, but we also ensure it is a "flat" object without substructure, + * so that list_free_deep() is sufficient to free such a list. + * The per-FK-column arrays can be fixed-size because we allow at most + * INDEX_MAX_KEYS columns in a foreign key constraint. + * + * Currently, we mostly cache fields of interest to the planner, but the set + * of fields has already grown the constraint OID for other uses. + */ +typedef struct ForeignKeyCacheInfo +{ + pg_node_attr(no_equal, no_read, no_query_jumble) + + NodeTag type; + /* oid of the constraint itself */ + Oid conoid; + /* relation constrained by the foreign key */ + Oid conrelid; + /* relation referenced by the foreign key */ + Oid confrelid; + /* number of columns in the foreign key */ + int nkeys; + + /* Is enforced ? */ + bool conenforced; + + /* + * these arrays each have nkeys valid entries: + */ + /* cols in referencing table */ + AttrNumber conkey[INDEX_MAX_KEYS] pg_node_attr(array_size(nkeys)); + /* cols in referenced table */ + AttrNumber confkey[INDEX_MAX_KEYS] pg_node_attr(array_size(nkeys)); + /* PK = FK operator OIDs */ + Oid conpfeqop[INDEX_MAX_KEYS] pg_node_attr(array_size(nkeys)); +} ForeignKeyCacheInfo; + + + +#endif /* RELFKCACHE_H */ -- 2.47.3