1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-08 22:02:03 +03:00

Add Cardinality typedef

Similar to Cost and Selectivity, this is just a double, which can be
used in path and plan nodes to give some hint about the meaning of a
field.

Discussion: https://www.postgresql.org/message-id/c091e5cd-45f8-69ee-6a9b-de86912cc7e7@enterprisedb.com
This commit is contained in:
Peter Eisentraut 2021-09-15 18:56:13 +02:00
parent 1316be2866
commit 6fe0eb963d
4 changed files with 27 additions and 26 deletions

View File

@ -668,6 +668,7 @@ extern bool equal(const void *a, const void *b);
*/ */
typedef double Selectivity; /* fraction of tuples a qualifier will pass */ typedef double Selectivity; /* fraction of tuples a qualifier will pass */
typedef double Cost; /* execution cost (in page-access units) */ typedef double Cost; /* execution cost (in page-access units) */
typedef double Cardinality; /* (estimated) number of rows or other integer count */
/* /*

View File

@ -1144,7 +1144,7 @@ typedef struct RangeTblEntry
* Fields valid for ENR RTEs (else NULL/zero): * Fields valid for ENR RTEs (else NULL/zero):
*/ */
char *enrname; /* name of ephemeral named relation */ char *enrname; /* name of ephemeral named relation */
double enrtuples; /* estimated or actual from caller */ Cardinality enrtuples; /* estimated or actual from caller */
/* /*
* Fields valid in all RTEs: * Fields valid in all RTEs:

View File

@ -334,11 +334,11 @@ struct PlannerInfo
MemoryContext planner_cxt; /* context holding PlannerInfo */ MemoryContext planner_cxt; /* context holding PlannerInfo */
double total_table_pages; /* # of pages in all non-dummy tables of Cardinality total_table_pages; /* # of pages in all non-dummy tables of
* query */ * query */
double tuple_fraction; /* tuple_fraction passed to query_planner */ Selectivity tuple_fraction; /* tuple_fraction passed to query_planner */
double limit_tuples; /* limit_tuples passed to query_planner */ Cardinality limit_tuples; /* limit_tuples passed to query_planner */
Index qual_security_level; /* minimum security_level for quals */ Index qual_security_level; /* minimum security_level for quals */
/* Note: qual_security_level is zero if there are no securityQuals */ /* Note: qual_security_level is zero if there are no securityQuals */
@ -681,7 +681,7 @@ typedef struct RelOptInfo
Relids relids; /* set of base relids (rangetable indexes) */ Relids relids; /* set of base relids (rangetable indexes) */
/* size estimates generated by planner */ /* size estimates generated by planner */
double rows; /* estimated number of result tuples */ Cardinality rows; /* estimated number of result tuples */
/* per-relation planner control flags */ /* per-relation planner control flags */
bool consider_startup; /* keep cheap-startup-cost paths? */ bool consider_startup; /* keep cheap-startup-cost paths? */
@ -718,7 +718,7 @@ typedef struct RelOptInfo
List *indexlist; /* list of IndexOptInfo */ List *indexlist; /* list of IndexOptInfo */
List *statlist; /* list of StatisticExtInfo */ List *statlist; /* list of StatisticExtInfo */
BlockNumber pages; /* size estimates derived from pg_class */ BlockNumber pages; /* size estimates derived from pg_class */
double tuples; Cardinality tuples;
double allvisfrac; double allvisfrac;
Bitmapset *eclass_indexes; /* Indexes in PlannerInfo's eq_classes list of Bitmapset *eclass_indexes; /* Indexes in PlannerInfo's eq_classes list of
* ECs that mention this rel */ * ECs that mention this rel */
@ -841,7 +841,7 @@ struct IndexOptInfo
/* index-size statistics (from pg_class and elsewhere) */ /* index-size statistics (from pg_class and elsewhere) */
BlockNumber pages; /* number of disk pages in index */ BlockNumber pages; /* number of disk pages in index */
double tuples; /* number of index tuples in index */ Cardinality tuples; /* number of index tuples in index */
int tree_height; /* index tree height, or -1 if unknown */ int tree_height; /* index tree height, or -1 if unknown */
/* index descriptor information */ /* index descriptor information */
@ -1139,7 +1139,7 @@ typedef struct ParamPathInfo
NodeTag type; NodeTag type;
Relids ppi_req_outer; /* rels supplying parameters used by path */ Relids ppi_req_outer; /* rels supplying parameters used by path */
double ppi_rows; /* estimated number of result tuples */ Cardinality ppi_rows; /* estimated number of result tuples */
List *ppi_clauses; /* join clauses available from outer rels */ List *ppi_clauses; /* join clauses available from outer rels */
} ParamPathInfo; } ParamPathInfo;
@ -1189,7 +1189,7 @@ typedef struct Path
int parallel_workers; /* desired # of workers; 0 = not parallel */ int parallel_workers; /* desired # of workers; 0 = not parallel */
/* estimated size/costs for path (see costsize.c for more info) */ /* estimated size/costs for path (see costsize.c for more info) */
double rows; /* estimated number of result tuples */ Cardinality rows; /* estimated number of result tuples */
Cost startup_cost; /* cost expended before fetching any tuples */ Cost startup_cost; /* cost expended before fetching any tuples */
Cost total_cost; /* total cost (assuming all tuples fetched) */ Cost total_cost; /* total cost (assuming all tuples fetched) */
@ -1452,7 +1452,7 @@ typedef struct AppendPath
List *subpaths; /* list of component Paths */ List *subpaths; /* list of component Paths */
/* Index of first partial path in subpaths; list_length(subpaths) if none */ /* Index of first partial path in subpaths; list_length(subpaths) if none */
int first_partial_path; int first_partial_path;
double limit_tuples; /* hard limit on output tuples, or -1 */ Cardinality limit_tuples; /* hard limit on output tuples, or -1 */
} AppendPath; } AppendPath;
#define IS_DUMMY_APPEND(p) \ #define IS_DUMMY_APPEND(p) \
@ -1474,7 +1474,7 @@ typedef struct MergeAppendPath
{ {
Path path; Path path;
List *subpaths; /* list of component Paths */ List *subpaths; /* list of component Paths */
double limit_tuples; /* hard limit on output tuples, or -1 */ Cardinality limit_tuples; /* hard limit on output tuples, or -1 */
} MergeAppendPath; } MergeAppendPath;
/* /*
@ -1515,7 +1515,7 @@ typedef struct MemoizePath
List *param_exprs; /* cache keys */ List *param_exprs; /* cache keys */
bool singlerow; /* true if the cache entry is to be marked as bool singlerow; /* true if the cache entry is to be marked as
* complete after caching the first record. */ * complete after caching the first record. */
double calls; /* expected number of rescans */ Cardinality calls; /* expected number of rescans */
uint32 est_entries; /* The maximum number of entries that the uint32 est_entries; /* The maximum number of entries that the
* planner expects will fit in the cache, or 0 * planner expects will fit in the cache, or 0
* if unknown */ * if unknown */
@ -1667,7 +1667,7 @@ typedef struct HashPath
JoinPath jpath; JoinPath jpath;
List *path_hashclauses; /* join clauses used for hashing */ List *path_hashclauses; /* join clauses used for hashing */
int num_batches; /* number of batches expected */ int num_batches; /* number of batches expected */
double inner_rows_total; /* total inner rows expected */ Cardinality inner_rows_total; /* total inner rows expected */
} HashPath; } HashPath;
/* /*
@ -1770,7 +1770,7 @@ typedef struct AggPath
Path *subpath; /* path representing input source */ Path *subpath; /* path representing input source */
AggStrategy aggstrategy; /* basic strategy, see nodes.h */ AggStrategy aggstrategy; /* basic strategy, see nodes.h */
AggSplit aggsplit; /* agg-splitting mode, see nodes.h */ AggSplit aggsplit; /* agg-splitting mode, see nodes.h */
double numGroups; /* estimated number of groups in input */ Cardinality numGroups; /* estimated number of groups in input */
uint64 transitionSpace; /* for pass-by-ref transition data */ uint64 transitionSpace; /* for pass-by-ref transition data */
List *groupClause; /* a list of SortGroupClause's */ List *groupClause; /* a list of SortGroupClause's */
List *qual; /* quals (HAVING quals), if any */ List *qual; /* quals (HAVING quals), if any */
@ -1784,7 +1784,7 @@ typedef struct GroupingSetData
{ {
NodeTag type; NodeTag type;
List *set; /* grouping set as list of sortgrouprefs */ List *set; /* grouping set as list of sortgrouprefs */
double numGroups; /* est. number of result groups */ Cardinality numGroups; /* est. number of result groups */
} GroupingSetData; } GroupingSetData;
typedef struct RollupData typedef struct RollupData
@ -1793,7 +1793,7 @@ typedef struct RollupData
List *groupClause; /* applicable subset of parse->groupClause */ List *groupClause; /* applicable subset of parse->groupClause */
List *gsets; /* lists of integer indexes into groupClause */ List *gsets; /* lists of integer indexes into groupClause */
List *gsets_data; /* list of GroupingSetData */ List *gsets_data; /* list of GroupingSetData */
double numGroups; /* est. number of result groups */ Cardinality numGroups; /* est. number of result groups */
bool hashable; /* can be hashed */ bool hashable; /* can be hashed */
bool is_hashed; /* to be implemented as a hashagg */ bool is_hashed; /* to be implemented as a hashagg */
} RollupData; } RollupData;
@ -1844,7 +1844,7 @@ typedef struct SetOpPath
List *distinctList; /* SortGroupClauses identifying target cols */ List *distinctList; /* SortGroupClauses identifying target cols */
AttrNumber flagColIdx; /* where is the flag column, if any */ AttrNumber flagColIdx; /* where is the flag column, if any */
int firstFlag; /* flag value for first input relation */ int firstFlag; /* flag value for first input relation */
double numGroups; /* estimated number of groups in input */ Cardinality numGroups; /* estimated number of groups in input */
} SetOpPath; } SetOpPath;
/* /*
@ -1857,7 +1857,7 @@ typedef struct RecursiveUnionPath
Path *rightpath; Path *rightpath;
List *distinctList; /* SortGroupClauses identifying target cols */ List *distinctList; /* SortGroupClauses identifying target cols */
int wtParam; /* ID of Param representing work table */ int wtParam; /* ID of Param representing work table */
double numGroups; /* estimated number of groups in input */ Cardinality numGroups; /* estimated number of groups in input */
} RecursiveUnionPath; } RecursiveUnionPath;
/* /*
@ -2612,7 +2612,7 @@ typedef struct
typedef struct typedef struct
{ {
bool limit_needed; bool limit_needed;
double limit_tuples; Cardinality limit_tuples;
int64 count_est; int64 count_est;
int64 offset_est; int64 offset_est;
} FinalPathExtraData; } FinalPathExtraData;
@ -2643,15 +2643,15 @@ typedef struct JoinCostWorkspace
Cost inner_rescan_run_cost; Cost inner_rescan_run_cost;
/* private for cost_mergejoin code */ /* private for cost_mergejoin code */
double outer_rows; Cardinality outer_rows;
double inner_rows; Cardinality inner_rows;
double outer_skip_rows; Cardinality outer_skip_rows;
double inner_skip_rows; Cardinality inner_skip_rows;
/* private for cost_hashjoin code */ /* private for cost_hashjoin code */
int numbuckets; int numbuckets;
int numbatches; int numbatches;
double inner_rows_total; Cardinality inner_rows_total;
} JoinCostWorkspace; } JoinCostWorkspace;
/* /*

View File

@ -120,7 +120,7 @@ typedef struct Plan
/* /*
* planner's estimate of result size of this plan step * planner's estimate of result size of this plan step
*/ */
double plan_rows; /* number of rows plan is expected to emit */ Cardinality plan_rows; /* number of rows plan is expected to emit */
int plan_width; /* average row width in bytes */ int plan_width; /* average row width in bytes */
/* /*
@ -976,7 +976,7 @@ typedef struct Hash
AttrNumber skewColumn; /* outer join key's column #, or zero */ AttrNumber skewColumn; /* outer join key's column #, or zero */
bool skewInherit; /* is outer join rel an inheritance tree? */ bool skewInherit; /* is outer join rel an inheritance tree? */
/* all other info is in the parent HashJoin node */ /* all other info is in the parent HashJoin node */
double rows_total; /* estimate total rows if parallel_aware */ Cardinality rows_total; /* estimate total rows if parallel_aware */
} Hash; } Hash;
/* ---------------- /* ----------------