Header And Logo

PostgreSQL
| The world's most advanced open source database.

spgist.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * spgist.h
00004  *    Public header file for SP-GiST access method.
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/access/spgist.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef SPGIST_H
00015 #define SPGIST_H
00016 
00017 #include "access/skey.h"
00018 #include "access/xlog.h"
00019 #include "fmgr.h"
00020 
00021 
00022 /* reloption parameters */
00023 #define SPGIST_MIN_FILLFACTOR           10
00024 #define SPGIST_DEFAULT_FILLFACTOR       80
00025 
00026 /* SPGiST opclass support function numbers */
00027 #define SPGIST_CONFIG_PROC              1
00028 #define SPGIST_CHOOSE_PROC              2
00029 #define SPGIST_PICKSPLIT_PROC           3
00030 #define SPGIST_INNER_CONSISTENT_PROC    4
00031 #define SPGIST_LEAF_CONSISTENT_PROC     5
00032 #define SPGISTNProc                     5
00033 
00034 /*
00035  * Argument structs for spg_config method
00036  */
00037 typedef struct spgConfigIn
00038 {
00039     Oid         attType;        /* Data type to be indexed */
00040 } spgConfigIn;
00041 
00042 typedef struct spgConfigOut
00043 {
00044     Oid         prefixType;     /* Data type of inner-tuple prefixes */
00045     Oid         labelType;      /* Data type of inner-tuple node labels */
00046     bool        canReturnData;  /* Opclass can reconstruct original data */
00047     bool        longValuesOK;   /* Opclass can cope with values > 1 page */
00048 } spgConfigOut;
00049 
00050 /*
00051  * Argument structs for spg_choose method
00052  */
00053 typedef struct spgChooseIn
00054 {
00055     Datum       datum;          /* original datum to be indexed */
00056     Datum       leafDatum;      /* current datum to be stored at leaf */
00057     int         level;          /* current level (counting from zero) */
00058 
00059     /* Data from current inner tuple */
00060     bool        allTheSame;     /* tuple is marked all-the-same? */
00061     bool        hasPrefix;      /* tuple has a prefix? */
00062     Datum       prefixDatum;    /* if so, the prefix value */
00063     int         nNodes;         /* number of nodes in the inner tuple */
00064     Datum      *nodeLabels;     /* node label values (NULL if none) */
00065 } spgChooseIn;
00066 
00067 typedef enum spgChooseResultType
00068 {
00069     spgMatchNode = 1,           /* descend into existing node */
00070     spgAddNode,                 /* add a node to the inner tuple */
00071     spgSplitTuple               /* split inner tuple (change its prefix) */
00072 } spgChooseResultType;
00073 
00074 typedef struct spgChooseOut
00075 {
00076     spgChooseResultType resultType;     /* action code, see above */
00077     union
00078     {
00079         struct                  /* results for spgMatchNode */
00080         {
00081             int         nodeN;  /* descend to this node (index from 0) */
00082             int         levelAdd;       /* increment level by this much */
00083             Datum       restDatum;      /* new leaf datum */
00084         }           matchNode;
00085         struct                  /* results for spgAddNode */
00086         {
00087             Datum       nodeLabel;      /* new node's label */
00088             int         nodeN;  /* where to insert it (index from 0) */
00089         }           addNode;
00090         struct                  /* results for spgSplitTuple */
00091         {
00092             /* Info to form new inner tuple with one node */
00093             bool        prefixHasPrefix;        /* tuple should have a prefix? */
00094             Datum       prefixPrefixDatum;      /* if so, its value */
00095             Datum       nodeLabel;      /* node's label */
00096 
00097             /* Info to form new lower-level inner tuple with all old nodes */
00098             bool        postfixHasPrefix;       /* tuple should have a prefix? */
00099             Datum       postfixPrefixDatum;     /* if so, its value */
00100         }           splitTuple;
00101     }           result;
00102 } spgChooseOut;
00103 
00104 /*
00105  * Argument structs for spg_picksplit method
00106  */
00107 typedef struct spgPickSplitIn
00108 {
00109     int         nTuples;        /* number of leaf tuples */
00110     Datum      *datums;         /* their datums (array of length nTuples) */
00111     int         level;          /* current level (counting from zero) */
00112 } spgPickSplitIn;
00113 
00114 typedef struct spgPickSplitOut
00115 {
00116     bool        hasPrefix;      /* new inner tuple should have a prefix? */
00117     Datum       prefixDatum;    /* if so, its value */
00118 
00119     int         nNodes;         /* number of nodes for new inner tuple */
00120     Datum      *nodeLabels;     /* their labels (or NULL for no labels) */
00121 
00122     int        *mapTuplesToNodes;       /* node index for each leaf tuple */
00123     Datum      *leafTupleDatums;    /* datum to store in each new leaf tuple */
00124 } spgPickSplitOut;
00125 
00126 /*
00127  * Argument structs for spg_inner_consistent method
00128  */
00129 typedef struct spgInnerConsistentIn
00130 {
00131     ScanKey     scankeys;       /* array of operators and comparison values */
00132     int         nkeys;          /* length of array */
00133 
00134     Datum       reconstructedValue;     /* value reconstructed at parent */
00135     int         level;          /* current level (counting from zero) */
00136     bool        returnData;     /* original data must be returned? */
00137 
00138     /* Data from current inner tuple */
00139     bool        allTheSame;     /* tuple is marked all-the-same? */
00140     bool        hasPrefix;      /* tuple has a prefix? */
00141     Datum       prefixDatum;    /* if so, the prefix value */
00142     int         nNodes;         /* number of nodes in the inner tuple */
00143     Datum      *nodeLabels;     /* node label values (NULL if none) */
00144 } spgInnerConsistentIn;
00145 
00146 typedef struct spgInnerConsistentOut
00147 {
00148     int         nNodes;         /* number of child nodes to be visited */
00149     int        *nodeNumbers;    /* their indexes in the node array */
00150     int        *levelAdds;      /* increment level by this much for each */
00151     Datum      *reconstructedValues;    /* associated reconstructed values */
00152 } spgInnerConsistentOut;
00153 
00154 /*
00155  * Argument structs for spg_leaf_consistent method
00156  */
00157 typedef struct spgLeafConsistentIn
00158 {
00159     ScanKey     scankeys;       /* array of operators and comparison values */
00160     int         nkeys;          /* length of array */
00161 
00162     Datum       reconstructedValue;     /* value reconstructed at parent */
00163     int         level;          /* current level (counting from zero) */
00164     bool        returnData;     /* original data must be returned? */
00165 
00166     Datum       leafDatum;      /* datum in leaf tuple */
00167 } spgLeafConsistentIn;
00168 
00169 typedef struct spgLeafConsistentOut
00170 {
00171     Datum       leafValue;      /* reconstructed original data, if any */
00172     bool        recheck;        /* set true if operator must be rechecked */
00173 } spgLeafConsistentOut;
00174 
00175 
00176 /* spginsert.c */
00177 extern Datum spgbuild(PG_FUNCTION_ARGS);
00178 extern Datum spgbuildempty(PG_FUNCTION_ARGS);
00179 extern Datum spginsert(PG_FUNCTION_ARGS);
00180 
00181 /* spgscan.c */
00182 extern Datum spgbeginscan(PG_FUNCTION_ARGS);
00183 extern Datum spgendscan(PG_FUNCTION_ARGS);
00184 extern Datum spgrescan(PG_FUNCTION_ARGS);
00185 extern Datum spgmarkpos(PG_FUNCTION_ARGS);
00186 extern Datum spgrestrpos(PG_FUNCTION_ARGS);
00187 extern Datum spggetbitmap(PG_FUNCTION_ARGS);
00188 extern Datum spggettuple(PG_FUNCTION_ARGS);
00189 extern Datum spgcanreturn(PG_FUNCTION_ARGS);
00190 
00191 /* spgutils.c */
00192 extern Datum spgoptions(PG_FUNCTION_ARGS);
00193 
00194 /* spgvacuum.c */
00195 extern Datum spgbulkdelete(PG_FUNCTION_ARGS);
00196 extern Datum spgvacuumcleanup(PG_FUNCTION_ARGS);
00197 
00198 /* spgxlog.c */
00199 extern void spg_redo(XLogRecPtr lsn, XLogRecord *record);
00200 extern void spg_desc(StringInfo buf, uint8 xl_info, char *rec);
00201 extern void spg_xlog_startup(void);
00202 extern void spg_xlog_cleanup(void);
00203 
00204 #endif   /* SPGIST_H */