1
/*-------------------------------------------------------------------------
4
* Selectivity functions and index cost estimation functions for
5
* standard operators and index access methods.
8
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
9
* Portions Copyright (c) 1994, Regents of the University of California
11
* $PostgreSQL: pgsql/src/include/utils/selfuncs.h,v 1.21 2004-12-31 22:03:46 pgsql Exp $
13
*-------------------------------------------------------------------------
19
#include "nodes/parsenodes.h"
23
* Note: the default selectivity estimates are not chosen entirely at random.
24
* We want them to be small enough to ensure that indexscans will be used if
25
* available, for typical table densities of ~100 tuples/page. Thus, for
26
* example, 0.01 is not quite small enough, since that makes it appear that
27
* nearly all pages will be hit anyway. Also, since we sometimes estimate
28
* eqsel as 1/num_distinct, we probably want DEFAULT_NUM_DISTINCT to equal
32
/* default selectivity estimate for equalities such as "A = b" */
33
#define DEFAULT_EQ_SEL 0.005
35
/* default selectivity estimate for inequalities such as "A < b" */
36
#define DEFAULT_INEQ_SEL 0.3333333333333333
38
/* default selectivity estimate for range inequalities "A > b AND A < c" */
39
#define DEFAULT_RANGE_INEQ_SEL 0.005
41
/* default selectivity estimate for pattern-match operators such as LIKE */
42
#define DEFAULT_MATCH_SEL 0.005
44
/* default number of distinct values in a table */
45
#define DEFAULT_NUM_DISTINCT 200
47
/* default selectivity estimate for boolean and null test nodes */
48
#define DEFAULT_UNK_SEL 0.005
49
#define DEFAULT_NOT_UNK_SEL (1.0 - DEFAULT_UNK_SEL)
53
* Clamp a computed probability estimate (which may suffer from roundoff or
54
* estimation errors) to valid range. Argument must be a float variable.
56
#define CLAMP_PROBABILITY(p) \
67
Pattern_Type_Like, Pattern_Type_Like_IC,
68
Pattern_Type_Regex, Pattern_Type_Regex_IC
73
Pattern_Prefix_None, Pattern_Prefix_Partial, Pattern_Prefix_Exact
74
} Pattern_Prefix_Status;
79
extern Pattern_Prefix_Status pattern_fixed_prefix(Const *patt,
83
extern Const *make_greater_string(const Const *str_const);
85
extern Datum eqsel(PG_FUNCTION_ARGS);
86
extern Datum neqsel(PG_FUNCTION_ARGS);
87
extern Datum scalarltsel(PG_FUNCTION_ARGS);
88
extern Datum scalargtsel(PG_FUNCTION_ARGS);
89
extern Datum regexeqsel(PG_FUNCTION_ARGS);
90
extern Datum icregexeqsel(PG_FUNCTION_ARGS);
91
extern Datum likesel(PG_FUNCTION_ARGS);
92
extern Datum iclikesel(PG_FUNCTION_ARGS);
93
extern Datum regexnesel(PG_FUNCTION_ARGS);
94
extern Datum icregexnesel(PG_FUNCTION_ARGS);
95
extern Datum nlikesel(PG_FUNCTION_ARGS);
96
extern Datum icnlikesel(PG_FUNCTION_ARGS);
98
extern Datum eqjoinsel(PG_FUNCTION_ARGS);
99
extern Datum neqjoinsel(PG_FUNCTION_ARGS);
100
extern Datum scalarltjoinsel(PG_FUNCTION_ARGS);
101
extern Datum scalargtjoinsel(PG_FUNCTION_ARGS);
102
extern Datum regexeqjoinsel(PG_FUNCTION_ARGS);
103
extern Datum icregexeqjoinsel(PG_FUNCTION_ARGS);
104
extern Datum likejoinsel(PG_FUNCTION_ARGS);
105
extern Datum iclikejoinsel(PG_FUNCTION_ARGS);
106
extern Datum regexnejoinsel(PG_FUNCTION_ARGS);
107
extern Datum icregexnejoinsel(PG_FUNCTION_ARGS);
108
extern Datum nlikejoinsel(PG_FUNCTION_ARGS);
109
extern Datum icnlikejoinsel(PG_FUNCTION_ARGS);
111
extern Selectivity booltestsel(Query *root, BoolTestType booltesttype,
112
Node *arg, int varRelid, JoinType jointype);
113
extern Selectivity nulltestsel(Query *root, NullTestType nulltesttype,
114
Node *arg, int varRelid);
116
extern void mergejoinscansel(Query *root, Node *clause,
117
Selectivity *leftscan,
118
Selectivity *rightscan);
120
extern double estimate_num_groups(Query *root, List *groupExprs,
123
extern Selectivity estimate_hash_bucketsize(Query *root, Node *hashkey,
126
extern Datum btcostestimate(PG_FUNCTION_ARGS);
127
extern Datum rtcostestimate(PG_FUNCTION_ARGS);
128
extern Datum hashcostestimate(PG_FUNCTION_ARGS);
129
extern Datum gistcostestimate(PG_FUNCTION_ARGS);
131
#endif /* SELFUNCS_H */