mirror of
https://github.com/postgres/postgres.git
synced 2025-09-03 15:22:11 +03:00
Restore foreign-key-aware estimation of join relation sizes.
This patch provides a new implementation of the logic added by commit137805f89
and later removed by77ba61080
. It differs from the original primarily in expending much less effort per joinrel in large queries, which it accomplishes by doing most of the matching work once per query not once per joinrel. Hopefully, it's also less buggy and better commented. The never-documented enable_fkey_estimates GUC remains gone. There remains work to be done to make the selectivity estimates account for nulls in FK referencing columns; but that was true of the original patch as well. We may be able to address this point later in beta. In the meantime, any error should be in the direction of overestimating rather than underestimating joinrel sizes, which seems like the direction we want to err in. Tomas Vondra and Tom Lane Discussion: <31041.1465069446@sss.pgh.pa.us>
This commit is contained in:
@@ -90,6 +90,10 @@ typedef struct RelationData
|
||||
/* use "struct" here to avoid needing to include rowsecurity.h: */
|
||||
struct RowSecurityDesc *rd_rsdesc; /* row security policies, or NULL */
|
||||
|
||||
/* data managed by RelationGetFKeyList: */
|
||||
List *rd_fkeylist; /* list of ForeignKeyCacheInfo (see below) */
|
||||
bool rd_fkeyvalid; /* true if list has been computed */
|
||||
|
||||
/* data managed by RelationGetIndexList: */
|
||||
List *rd_indexlist; /* list of OIDs of indexes on relation */
|
||||
Oid rd_oidindex; /* OID of unique index on OID, if any */
|
||||
@@ -170,6 +174,34 @@ typedef struct RelationData
|
||||
struct PgStat_TableStatus *pgstat_info; /* statistics collection area */
|
||||
} 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 only cache fields of interest to the planner, but the
|
||||
* set of fields could be expanded in future.
|
||||
*/
|
||||
typedef struct ForeignKeyCacheInfo
|
||||
{
|
||||
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 */
|
||||
/* these arrays each have nkeys valid entries: */
|
||||
AttrNumber conkey[INDEX_MAX_KEYS]; /* cols in referencing table */
|
||||
AttrNumber confkey[INDEX_MAX_KEYS]; /* cols in referenced table */
|
||||
Oid conpfeqop[INDEX_MAX_KEYS]; /* PK = FK operator OIDs */
|
||||
} ForeignKeyCacheInfo;
|
||||
|
||||
|
||||
/*
|
||||
* StdRdOptions
|
||||
* Standard contents of rd_options for heaps and generic indexes.
|
||||
|
Reference in New Issue
Block a user