mirror of
https://github.com/postgres/postgres.git
synced 2025-09-03 15:22:11 +03:00
Support ORDER BY ... NULLS FIRST/LAST, and add ASC/DESC/NULLS FIRST/NULLS LAST
per-column options for btree indexes. The planner's support for this is still pretty rudimentary; it does not yet know how to plan mergejoins with nondefault ordering options. The documentation is pretty rudimentary, too. I'll work on improving that stuff later. Note incompatible change from prior behavior: ORDER BY ... USING will now be rejected if the operator is not a less-than or greater-than member of some btree opclass. This prevents less-than-sane behavior if an operator that doesn't actually define a proper sort ordering is selected.
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/utils/tuplesort.h,v 1.24 2007/01/05 22:20:00 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/include/utils/tuplesort.h,v 1.25 2007/01/09 02:14:16 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -45,14 +45,14 @@ typedef struct Tuplesortstate Tuplesortstate;
|
||||
*/
|
||||
|
||||
extern Tuplesortstate *tuplesort_begin_heap(TupleDesc tupDesc,
|
||||
int nkeys,
|
||||
Oid *sortOperators, AttrNumber *attNums,
|
||||
int nkeys, AttrNumber *attNums,
|
||||
Oid *sortOperators, bool *nullsFirstFlags,
|
||||
int workMem, bool randomAccess);
|
||||
extern Tuplesortstate *tuplesort_begin_index(Relation indexRel,
|
||||
bool enforceUnique,
|
||||
int workMem, bool randomAccess);
|
||||
extern Tuplesortstate *tuplesort_begin_datum(Oid datumType,
|
||||
Oid sortOperator,
|
||||
Oid sortOperator, bool nullsFirstFlag,
|
||||
int workMem, bool randomAccess);
|
||||
|
||||
extern void tuplesort_puttupleslot(Tuplesortstate *state,
|
||||
@@ -84,28 +84,17 @@ extern void tuplesort_rescan(Tuplesortstate *state);
|
||||
extern void tuplesort_markpos(Tuplesortstate *state);
|
||||
extern void tuplesort_restorepos(Tuplesortstate *state);
|
||||
|
||||
/*
|
||||
* This routine selects an appropriate sorting function to implement
|
||||
* a sort operator as efficiently as possible.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
SORTFUNC_LT, /* raw "<" operator */
|
||||
SORTFUNC_REVLT, /* raw "<" operator, but reverse NULLs */
|
||||
SORTFUNC_CMP, /* -1 / 0 / 1 three-way comparator */
|
||||
SORTFUNC_REVCMP /* 1 / 0 / -1 (reversed) 3-way comparator */
|
||||
} SortFunctionKind;
|
||||
|
||||
extern void SelectSortFunction(Oid sortOperator,
|
||||
RegProcedure *sortFunction,
|
||||
SortFunctionKind *kind);
|
||||
/* Setup for ApplySortFunction */
|
||||
extern void SelectSortFunction(Oid sortOperator, bool nulls_first,
|
||||
Oid *sortFunction,
|
||||
int *sortFlags);
|
||||
|
||||
/*
|
||||
* Apply a sort function (by now converted to fmgr lookup form)
|
||||
* and return a 3-way comparison result. This takes care of handling
|
||||
* NULLs and sort ordering direction properly.
|
||||
* reverse-sort and NULLs-ordering properly.
|
||||
*/
|
||||
extern int32 ApplySortFunction(FmgrInfo *sortFunction, SortFunctionKind kind,
|
||||
extern int32 ApplySortFunction(FmgrInfo *sortFunction, int sortFlags,
|
||||
Datum datum1, bool isNull1,
|
||||
Datum datum2, bool isNull2);
|
||||
|
||||
|
Reference in New Issue
Block a user