~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/include/utils/selfuncs.h

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * selfuncs.h
 
4
 *        Selectivity functions and index cost estimation functions for
 
5
 *        standard operators and index access methods.
 
6
 *
 
7
 *
 
8
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
 
9
 * Portions Copyright (c) 1994, Regents of the University of California
 
10
 *
 
11
 * $PostgreSQL: pgsql/src/include/utils/selfuncs.h,v 1.21 2004-12-31 22:03:46 pgsql Exp $
 
12
 *
 
13
 *-------------------------------------------------------------------------
 
14
 */
 
15
#ifndef SELFUNCS_H
 
16
#define SELFUNCS_H
 
17
 
 
18
#include "fmgr.h"
 
19
#include "nodes/parsenodes.h"
 
20
 
 
21
 
 
22
/*
 
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
 
29
 * 1/DEFAULT_EQ_SEL.
 
30
 */
 
31
 
 
32
/* default selectivity estimate for equalities such as "A = b" */
 
33
#define DEFAULT_EQ_SEL  0.005
 
34
 
 
35
/* default selectivity estimate for inequalities such as "A < b" */
 
36
#define DEFAULT_INEQ_SEL  0.3333333333333333
 
37
 
 
38
/* default selectivity estimate for range inequalities "A > b AND A < c" */
 
39
#define DEFAULT_RANGE_INEQ_SEL  0.005
 
40
 
 
41
/* default selectivity estimate for pattern-match operators such as LIKE */
 
42
#define DEFAULT_MATCH_SEL       0.005
 
43
 
 
44
/* default number of distinct values in a table */
 
45
#define DEFAULT_NUM_DISTINCT  200
 
46
 
 
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)
 
50
 
 
51
 
 
52
/*
 
53
 * Clamp a computed probability estimate (which may suffer from roundoff or
 
54
 * estimation errors) to valid range.  Argument must be a float variable.
 
55
 */
 
56
#define CLAMP_PROBABILITY(p) \
 
57
        do { \
 
58
                if (p < 0.0) \
 
59
                        p = 0.0; \
 
60
                else if (p > 1.0) \
 
61
                        p = 1.0; \
 
62
        } while (0)
 
63
 
 
64
 
 
65
typedef enum
 
66
{
 
67
        Pattern_Type_Like, Pattern_Type_Like_IC,
 
68
        Pattern_Type_Regex, Pattern_Type_Regex_IC
 
69
} Pattern_Type;
 
70
 
 
71
typedef enum
 
72
{
 
73
        Pattern_Prefix_None, Pattern_Prefix_Partial, Pattern_Prefix_Exact
 
74
} Pattern_Prefix_Status;
 
75
 
 
76
 
 
77
/* selfuncs.c */
 
78
 
 
79
extern Pattern_Prefix_Status pattern_fixed_prefix(Const *patt,
 
80
                                         Pattern_Type ptype,
 
81
                                         Const **prefix,
 
82
                                         Const **rest);
 
83
extern Const *make_greater_string(const Const *str_const);
 
84
 
 
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);
 
97
 
 
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);
 
110
 
 
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);
 
115
 
 
116
extern void mergejoinscansel(Query *root, Node *clause,
 
117
                                 Selectivity *leftscan,
 
118
                                 Selectivity *rightscan);
 
119
 
 
120
extern double estimate_num_groups(Query *root, List *groupExprs,
 
121
                                        double input_rows);
 
122
 
 
123
extern Selectivity estimate_hash_bucketsize(Query *root, Node *hashkey,
 
124
                                                 int nbuckets);
 
125
 
 
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);
 
130
 
 
131
#endif   /* SELFUNCS_H */