Eneboo - Documentación para desarrolladores
src/libpq/include/utils/tuplesort.h
Ir a la documentación de este archivo.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * tuplesort.h
00004  *        Generalized tuple sorting routines.
00005  *
00006  * This module handles sorting of heap tuples, index tuples, or single
00007  * Datums (and could easily support other kinds of sortable objects,
00008  * if necessary).  It works efficiently for both small and large amounts
00009  * of data.  Small amounts are sorted in-memory using qsort().  Large
00010  * amounts are sorted using temporary files and a standard external sort
00011  * algorithm.
00012  *
00013  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
00014  * Portions Copyright (c) 1994, Regents of the University of California
00015  *
00016  * $PostgreSQL: pgsql/src/include/utils/tuplesort.h,v 1.17 2004/12/31 22:03:46 pgsql Exp $
00017  *
00018  *-------------------------------------------------------------------------
00019  */
00020 #ifndef TUPLESORT_H
00021 #define TUPLESORT_H
00022 
00023 #include "access/htup.h"
00024 #include "access/itup.h"
00025 #include "fmgr.h"
00026 
00027 /* Tuplesortstate is an opaque type whose details are not known outside tuplesort.c. */
00028 
00029 typedef struct Tuplesortstate Tuplesortstate;
00030 
00031 /*
00032  * We provide two different interfaces to what is essentially the same
00033  * code: one for sorting HeapTuples and one for sorting IndexTuples.
00034  * They differ primarily in the way that the sort key information is
00035  * supplied.
00036  * Yet a third slightly different interface supports sorting bare Datums.
00037  */
00038 
00039 extern Tuplesortstate *tuplesort_begin_heap(TupleDesc tupDesc,
00040                                          int nkeys,
00041                                          Oid *sortOperators, AttrNumber *attNums,
00042                                          int workMem, bool randomAccess);
00043 extern Tuplesortstate *tuplesort_begin_index(Relation indexRel,
00044                                           bool enforceUnique,
00045                                           int workMem, bool randomAccess);
00046 extern Tuplesortstate *tuplesort_begin_datum(Oid datumType,
00047                                           Oid sortOperator,
00048                                           int workMem, bool randomAccess);
00049 
00050 extern void tuplesort_puttuple(Tuplesortstate *state, void *tuple);
00051 
00052 extern void tuplesort_putdatum(Tuplesortstate *state, Datum val,
00053                                    bool isNull);
00054 
00055 extern void tuplesort_performsort(Tuplesortstate *state);
00056 
00057 extern void *tuplesort_gettuple(Tuplesortstate *state, bool forward,
00058                                    bool *should_free);
00059 
00060 #define tuplesort_getheaptuple(state, forward, should_free) \
00061         ((HeapTuple) tuplesort_gettuple(state, forward, should_free))
00062 #define tuplesort_getindextuple(state, forward, should_free) \
00063         ((IndexTuple) tuplesort_gettuple(state, forward, should_free))
00064 
00065 extern bool tuplesort_getdatum(Tuplesortstate *state, bool forward,
00066                                    Datum *val, bool *isNull);
00067 
00068 extern void tuplesort_end(Tuplesortstate *state);
00069 
00070 /*
00071  * These routines may only be called if randomAccess was specified 'true'.
00072  * Likewise, backwards scan in gettuple/getdatum is only allowed if
00073  * randomAccess was specified.
00074  */
00075 
00076 extern void tuplesort_rescan(Tuplesortstate *state);
00077 extern void tuplesort_markpos(Tuplesortstate *state);
00078 extern void tuplesort_restorepos(Tuplesortstate *state);
00079 
00080 /*
00081  * This routine selects an appropriate sorting function to implement
00082  * a sort operator as efficiently as possible.
00083  */
00084 typedef enum
00085 {
00086         SORTFUNC_LT,                            /* raw "<" operator */
00087         SORTFUNC_REVLT,                         /* raw "<" operator, but reverse NULLs */
00088         SORTFUNC_CMP,                           /* -1 / 0 / 1 three-way comparator */
00089         SORTFUNC_REVCMP                         /* 1 / 0 / -1 (reversed) 3-way comparator */
00090 } SortFunctionKind;
00091 
00092 extern void SelectSortFunction(Oid sortOperator,
00093                                    RegProcedure *sortFunction,
00094                                    SortFunctionKind *kind);
00095 
00096 /*
00097  * Apply a sort function (by now converted to fmgr lookup form)
00098  * and return a 3-way comparison result.  This takes care of handling
00099  * NULLs and sort ordering direction properly.
00100  */
00101 extern int32 ApplySortFunction(FmgrInfo *sortFunction, SortFunctionKind kind,
00102                                   Datum datum1, bool isNull1,
00103                                   Datum datum2, bool isNull2);
00104 
00105 #endif   /* TUPLESORT_H */
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'