Eneboo - Documentación para desarrolladores
src/libpq/include/utils/selfuncs.h
Ir a la documentación de este archivo.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * selfuncs.h
00004  *        Selectivity functions and index cost estimation functions for
00005  *        standard operators and index access methods.
00006  *
00007  *
00008  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
00009  * Portions Copyright (c) 1994, Regents of the University of California
00010  *
00011  * $PostgreSQL: pgsql/src/include/utils/selfuncs.h,v 1.24 2005/10/15 02:49:46 momjian Exp $
00012  *
00013  *-------------------------------------------------------------------------
00014  */
00015 #ifndef SELFUNCS_H
00016 #define SELFUNCS_H
00017 
00018 #include "fmgr.h"
00019 #include "nodes/relation.h"
00020 
00021 
00022 /*
00023  * Note: the default selectivity estimates are not chosen entirely at random.
00024  * We want them to be small enough to ensure that indexscans will be used if
00025  * available, for typical table densities of ~100 tuples/page.  Thus, for
00026  * example, 0.01 is not quite small enough, since that makes it appear that
00027  * nearly all pages will be hit anyway.  Also, since we sometimes estimate
00028  * eqsel as 1/num_distinct, we probably want DEFAULT_NUM_DISTINCT to equal
00029  * 1/DEFAULT_EQ_SEL.
00030  */
00031 
00032 /* default selectivity estimate for equalities such as "A = b" */
00033 #define DEFAULT_EQ_SEL  0.005
00034 
00035 /* default selectivity estimate for inequalities such as "A < b" */
00036 #define DEFAULT_INEQ_SEL  0.3333333333333333
00037 
00038 /* default selectivity estimate for range inequalities "A > b AND A < c" */
00039 #define DEFAULT_RANGE_INEQ_SEL  0.005
00040 
00041 /* default selectivity estimate for pattern-match operators such as LIKE */
00042 #define DEFAULT_MATCH_SEL       0.005
00043 
00044 /* default number of distinct values in a table */
00045 #define DEFAULT_NUM_DISTINCT  200
00046 
00047 /* default selectivity estimate for boolean and null test nodes */
00048 #define DEFAULT_UNK_SEL                 0.005
00049 #define DEFAULT_NOT_UNK_SEL             (1.0 - DEFAULT_UNK_SEL)
00050 
00051 
00052 /*
00053  * Clamp a computed probability estimate (which may suffer from roundoff or
00054  * estimation errors) to valid range.  Argument must be a float variable.
00055  */
00056 #define CLAMP_PROBABILITY(p) \
00057         do { \
00058                 if (p < 0.0) \
00059                         p = 0.0; \
00060                 else if (p > 1.0) \
00061                         p = 1.0; \
00062         } while (0)
00063 
00064 
00065 typedef enum
00066 {
00067         Pattern_Type_Like, Pattern_Type_Like_IC,
00068         Pattern_Type_Regex, Pattern_Type_Regex_IC
00069 } Pattern_Type;
00070 
00071 typedef enum
00072 {
00073         Pattern_Prefix_None, Pattern_Prefix_Partial, Pattern_Prefix_Exact
00074 } Pattern_Prefix_Status;
00075 
00076 
00077 /* selfuncs.c */
00078 
00079 extern Pattern_Prefix_Status pattern_fixed_prefix(Const *patt,
00080                                          Pattern_Type ptype,
00081                                          Const **prefix,
00082                                          Const **rest);
00083 extern Const *make_greater_string(const Const *str_const);
00084 
00085 extern Datum eqsel(PG_FUNCTION_ARGS);
00086 extern Datum neqsel(PG_FUNCTION_ARGS);
00087 extern Datum scalarltsel(PG_FUNCTION_ARGS);
00088 extern Datum scalargtsel(PG_FUNCTION_ARGS);
00089 extern Datum regexeqsel(PG_FUNCTION_ARGS);
00090 extern Datum icregexeqsel(PG_FUNCTION_ARGS);
00091 extern Datum likesel(PG_FUNCTION_ARGS);
00092 extern Datum iclikesel(PG_FUNCTION_ARGS);
00093 extern Datum regexnesel(PG_FUNCTION_ARGS);
00094 extern Datum icregexnesel(PG_FUNCTION_ARGS);
00095 extern Datum nlikesel(PG_FUNCTION_ARGS);
00096 extern Datum icnlikesel(PG_FUNCTION_ARGS);
00097 
00098 extern Datum eqjoinsel(PG_FUNCTION_ARGS);
00099 extern Datum neqjoinsel(PG_FUNCTION_ARGS);
00100 extern Datum scalarltjoinsel(PG_FUNCTION_ARGS);
00101 extern Datum scalargtjoinsel(PG_FUNCTION_ARGS);
00102 extern Datum regexeqjoinsel(PG_FUNCTION_ARGS);
00103 extern Datum icregexeqjoinsel(PG_FUNCTION_ARGS);
00104 extern Datum likejoinsel(PG_FUNCTION_ARGS);
00105 extern Datum iclikejoinsel(PG_FUNCTION_ARGS);
00106 extern Datum regexnejoinsel(PG_FUNCTION_ARGS);
00107 extern Datum icregexnejoinsel(PG_FUNCTION_ARGS);
00108 extern Datum nlikejoinsel(PG_FUNCTION_ARGS);
00109 extern Datum icnlikejoinsel(PG_FUNCTION_ARGS);
00110 
00111 extern Selectivity booltestsel(PlannerInfo *root, BoolTestType booltesttype,
00112                         Node *arg, int varRelid, JoinType jointype);
00113 extern Selectivity nulltestsel(PlannerInfo *root, NullTestType nulltesttype,
00114                         Node *arg, int varRelid);
00115 
00116 extern void mergejoinscansel(PlannerInfo *root, Node *clause,
00117                                  Selectivity *leftscan,
00118                                  Selectivity *rightscan);
00119 
00120 extern double estimate_num_groups(PlannerInfo *root, List *groupExprs,
00121                                         double input_rows);
00122 
00123 extern Selectivity estimate_hash_bucketsize(PlannerInfo *root, Node *hashkey,
00124                                                  double nbuckets);
00125 
00126 extern Datum btcostestimate(PG_FUNCTION_ARGS);
00127 extern Datum rtcostestimate(PG_FUNCTION_ARGS);
00128 extern Datum hashcostestimate(PG_FUNCTION_ARGS);
00129 extern Datum gistcostestimate(PG_FUNCTION_ARGS);
00130 
00131 #endif   /* SELFUNCS_H */
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'