/* default selectivity estimate for equalities such as "A = b" */ #define DEFAULT_EQ_SEL 0.005
/* default selectivity estimate for inequalities such as "A < b" */ #define DEFAULT_INEQ_SEL 0.3333333333333333
/* default selectivity estimate for range inequalities "A > b AND A < c" */ #define DEFAULT_RANGE_INEQ_SEL 0.005
/* default selectivity estimate for multirange inequalities "A > b AND A < c" */ #define DEFAULT_MULTIRANGE_INEQ_SEL 0.005
/* default selectivity estimate for pattern-match operators such as LIKE */ #define DEFAULT_MATCH_SEL 0.005
/* default selectivity estimate for other matching operators */ #define DEFAULT_MATCHING_SEL 0.010
/* default number of distinct values in a table */ #define DEFAULT_NUM_DISTINCT 200
/* default selectivity estimate for boolean and null test nodes */ #define DEFAULT_UNK_SEL 0.005 #define DEFAULT_NOT_UNK_SEL (1.0 - DEFAULT_UNK_SEL)
/* *Clampacomputedprobabilityestimate(whichmaysufferfromroundoffor *estimationerrors)tovalidrange.Argumentmustbeafloatvariable.
*/ #define CLAMP_PROBABILITY(p) \ do { \ if (p < 0.0) \
p = 0.0; \ elseif (p > 1.0) \
p = 1.0; \
} while (0)
/* *Asetofflagswhichsomeselectivityestimationfunctionscanpassbackto *callerstoprovidefurtherdetailsaboutsomeassumptionswhichweremade *duringtheestimation.
*/ #define SELFLAG_USED_DEFAULT (1 << 0) /* Estimation fell back on one *oftheDEFAULTsasdefined
* above. */
typedefstruct EstimationInfo
{
uint32 flags; /* Flags, as defined above to mark special
* properties of the estimation. */
} EstimationInfo;
/* Return data from examine_variable and friends */ typedefstruct VariableStatData
{
Node *var; /* the Var or expression tree */
RelOptInfo *rel; /* Relation, or NULL if not identifiable */
HeapTuple statsTuple; /* pg_statistic tuple, or NULL if none */ /* NB: if statsTuple!=NULL, it must be freed when caller is done */ void (*freefunc) (HeapTuple tuple); /* how to free statsTuple */
Oid vartype; /* exposed type of expression */
Oid atttype; /* actual type (after stripping relabel) */
int32 atttypmod; /* actual typmod (after stripping relabel) */ bool isunique; /* matches unique index, DISTINCT or GROUP-BY
* clause */ bool acl_ok; /* true if user has SELECT privilege on all
* rows from the table or column */
} VariableStatData;
#define ReleaseVariableStats(vardata) \ do { \ if (HeapTupleIsValid((vardata).statsTuple)) \
(vardata).freefunc((vardata).statsTuple); \
} while(0)
/* *genericcostestimateisageneral-purposeestimatorthatcanbeusedfor *mostindextypes.Insomecasesweusegenericcostestimateasthebase *codeandthenincorporateadditionalindex-type-specificknowledgein *thetype-specificcallingfunction.Toavoidcodeduplication,wemake *genericcostestimatereturnanumberofintermediatevaluesaswellas *itspreliminaryestimatesoftheoutputcostvalues.TheGenericCosts *structincludesallthesevalues. * *CallersshouldinitializeallfieldsofGenericCoststozero.Inaddition, *theycansetnumIndexTuplestosomepositivevalueiftheyhaveabetter *thandefaultwayofestimatingthenumberofleafindextuplesvisited. *Similarly,theycansetnum_sa_scanstosomevalue>=1foranindexAM *thatdoesn'tnecessarilyperformexactlyoneprimitiveindexscanper *distinctcombinationofScalarArrayOparrayelements.
*/ typedefstruct
{ /* These are the values the cost estimator must return to the planner */
Cost indexStartupCost; /* index-related startup cost */
Cost indexTotalCost; /* total index-related scan cost */
Selectivity indexSelectivity; /* selectivity of index */ double indexCorrelation; /* order correlation of index */
/* Intermediate values we obtain along the way */ double numIndexPages; /* number of leaf pages visited */ double numIndexTuples; /* number of leaf tuples visited */ double spc_random_page_cost; /* relevant random_page_cost value */ double num_sa_scans; /* # indexscans from ScalarArrayOpExprs */
} GenericCosts;
/* Hooks for plugins to get control when we ask for stats */ typedefbool (*get_relation_stats_hook_type) (PlannerInfo *root,
RangeTblEntry *rte,
AttrNumber attnum,
VariableStatData *vardata); extern PGDLLIMPORT get_relation_stats_hook_type get_relation_stats_hook; typedefbool (*get_index_stats_hook_type) (PlannerInfo *root,
Oid indexOid,
AttrNumber indexattnum,
VariableStatData *vardata); extern PGDLLIMPORT get_index_stats_hook_type get_index_stats_hook;
/* Functions in selfuncs.c */
externvoid examine_variable(PlannerInfo *root, Node *node, int varRelid,
VariableStatData *vardata); externbool all_rows_selectable(PlannerInfo *root, Index varno, Bitmapset *varattnos); externbool statistic_proc_security_check(VariableStatData *vardata, Oid func_oid); externbool get_restriction_variable(PlannerInfo *root, List *args, int varRelid,
VariableStatData *vardata, Node **other, bool *varonleft); externvoid get_join_variables(PlannerInfo *root, List *args,
SpecialJoinInfo *sjinfo,
VariableStatData *vardata1,
VariableStatData *vardata2, bool *join_is_reversed); externdouble get_variable_numdistinct(VariableStatData *vardata, bool *isdefault); externdouble mcv_selectivity(VariableStatData *vardata,
FmgrInfo *opproc, Oid collation,
Datum constval, bool varonleft, double *sumcommonp); externdouble histogram_selectivity(VariableStatData *vardata,
FmgrInfo *opproc, Oid collation,
Datum constval, bool varonleft, int min_hist_size, int n_skip, int *hist_size); externdouble generic_restriction_selectivity(PlannerInfo *root,
Oid oproid, Oid collation,
List *args, int varRelid, double default_selectivity); externdouble ineq_histogram_selectivity(PlannerInfo *root,
VariableStatData *vardata,
Oid opoid, FmgrInfo *opproc, bool isgt, bool iseq,
Oid collation,
Datum constval, Oid consttype); externdouble var_eq_const(VariableStatData *vardata,
Oid oproid, Oid collation,
Datum constval, bool constisnull, bool varonleft, bool negate); externdouble var_eq_non_const(VariableStatData *vardata,
Oid oproid, Oid collation,
Node *other, bool varonleft, bool negate);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.