diff options
author | Simon Riggs | 2016-04-07 11:08:33 +0000 |
---|---|---|
committer | Simon Riggs | 2016-04-07 11:08:33 +0000 |
commit | 015e88942aa50f0d419ddac00e63bb06d6e62e86 (patch) | |
tree | 5f8bffa51675e88ebdfb9f35ae2a62ce8dbc63d9 /src/include | |
parent | f2b1b3079ce9d2965f6e450585f24d18cdf5647b (diff) |
Load FK defs into relcache for use by planner
Fastpath ignores this if no triggers defined.
Author: Tomas Vondra, with fastpath and comments added by me
Reviewers: David Rowley, Simon Riggs
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/nodes/nodes.h | 1 | ||||
-rw-r--r-- | src/include/nodes/relation.h | 22 | ||||
-rw-r--r-- | src/include/utils/rel.h | 3 | ||||
-rw-r--r-- | src/include/utils/relcache.h | 1 |
4 files changed, 27 insertions, 0 deletions
diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h index 3f22bdb5a8a..84efa8e886d 100644 --- a/src/include/nodes/nodes.h +++ b/src/include/nodes/nodes.h @@ -223,6 +223,7 @@ typedef enum NodeTag T_PlannerGlobal, T_RelOptInfo, T_IndexOptInfo, + T_ForeignKeyOptInfo, T_ParamPathInfo, T_Path, T_IndexPath, diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h index 5264d3cc76d..d430f6e9fd4 100644 --- a/src/include/nodes/relation.h +++ b/src/include/nodes/relation.h @@ -516,6 +516,7 @@ typedef struct RelOptInfo List *lateral_vars; /* LATERAL Vars and PHVs referenced by rel */ Relids lateral_referencers; /* rels that reference me laterally */ List *indexlist; /* list of IndexOptInfo */ + List *fkeylist; /* list of ForeignKeyOptInfo */ BlockNumber pages; /* size estimates derived from pg_class */ double tuples; double allvisfrac; @@ -621,6 +622,27 @@ typedef struct IndexOptInfo void (*amcostestimate) (); /* AM's cost estimator */ } IndexOptInfo; +/* + * ForeignKeyOptInfo + * Per-foreign-key information for planning/optimization + * + * Only includes columns from pg_constraint related to foreign keys. + * + * conkeys[], confkeys[] and conpfeqop[] each have nkeys entries. + */ +typedef struct ForeignKeyOptInfo +{ + NodeTag type; + + Oid conrelid; /* relation constrained by the foreign key */ + Oid confrelid; /* relation referenced by the foreign key */ + + int nkeys; /* number of columns in the foreign key */ + int *conkeys; /* attnums of columns in the constrained table */ + int *confkeys; /* attnums of columns in the referenced table */ + Oid *conpfeqop; /* OIDs of equality operators used by the FK */ + +} ForeignKeyOptInfo; /* * EquivalenceClasses diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f2bebf2c3dd..51eb27a381b 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -94,6 +94,9 @@ typedef struct RelationData Oid rd_oidindex; /* OID of unique index on OID, if any */ Oid rd_replidindex; /* OID of replica identity index, if any */ + /* data managed by RelationGetFKList: */ + List *rd_fkeylist; /* OIDs of foreign keys */ + /* data managed by RelationGetIndexAttrBitmap: */ Bitmapset *rd_indexattr; /* identifies columns used in indexes */ Bitmapset *rd_keyattr; /* cols that can be ref'd by foreign keys */ diff --git a/src/include/utils/relcache.h b/src/include/utils/relcache.h index 1b4830462d5..7f07c269145 100644 --- a/src/include/utils/relcache.h +++ b/src/include/utils/relcache.h @@ -38,6 +38,7 @@ extern void RelationClose(Relation relation); * Routines to compute/retrieve additional cached information */ extern List *RelationGetIndexList(Relation relation); +extern List *RelationGetFKeyList(Relation relation); extern Oid RelationGetOidIndex(Relation relation); extern Oid RelationGetReplicaIndex(Relation relation); extern List *RelationGetIndexExpressions(Relation relation); |