PostgreSQL Source Code git master
Data Structures | Typedefs | Functions
sortsupport.h File Reference
#include "access/attnum.h"
#include "utils/relcache.h"
Include dependency graph for sortsupport.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct   SortSupportData
 

Typedefs

typedef struct SortSupportDataSortSupport
 
typedef struct SortSupportData  SortSupportData
 

Functions

static int  ApplySortComparator (Datum datum1, bool isNull1, Datum datum2, bool isNull2, SortSupport ssup)
 
static int  ApplyUnsignedSortComparator (Datum datum1, bool isNull1, Datum datum2, bool isNull2, SortSupport ssup)
 
static int  ApplySignedSortComparator (Datum datum1, bool isNull1, Datum datum2, bool isNull2, SortSupport ssup)
 
static int  ApplyInt32SortComparator (Datum datum1, bool isNull1, Datum datum2, bool isNull2, SortSupport ssup)
 
static int  ApplySortAbbrevFullComparator (Datum datum1, bool isNull1, Datum datum2, bool isNull2, SortSupport ssup)
 
 
 
 
 
 
void  PrepareSortSupportFromIndexRel (Relation indexRel, bool reverse, SortSupport ssup)
 
 

Typedef Documentation

SortSupport

typedef struct SortSupportData* SortSupport

Definition at line 58 of file sortsupport.h.

SortSupportData

Function Documentation

ApplyInt32SortComparator()

static int ApplyInt32SortComparator ( Datum  datum1,
bool  isNull1,
Datum  datum2,
bool  isNull2,
SortSupport  ssup 
)
inlinestatic

Definition at line 300 of file sortsupport.h.

303{
304 int compare;
305
306 if (isNull1)
307 {
308 if (isNull2)
309 compare = 0; /* NULL "=" NULL */
310 else if (ssup->ssup_nulls_first)
311 compare = -1; /* NULL "<" NOT_NULL */
312 else
313 compare = 1; /* NULL ">" NOT_NULL */
314 }
315 else if (isNull2)
316 {
317 if (ssup->ssup_nulls_first)
318 compare = 1; /* NOT_NULL ">" NULL */
319 else
320 compare = -1; /* NOT_NULL "<" NULL */
321 }
322 else
323 {
324 compare = DatumGetInt32(datum1) < DatumGetInt32(datum2) ? -1 :
325 DatumGetInt32(datum1) > DatumGetInt32(datum2) ? 1 : 0;
326 if (ssup->ssup_reverse)
328 }
329
330 return compare;
331}
#define INVERT_COMPARE_RESULT(var)
Definition: c.h:1105
static int compare(const void *arg1, const void *arg2)
Definition: geqo_pool.c:145
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:212
bool ssup_reverse
Definition: sortsupport.h:74
bool ssup_nulls_first
Definition: sortsupport.h:75

References compare(), DatumGetInt32(), INVERT_COMPARE_RESULT, SortSupportData::ssup_nulls_first, and SortSupportData::ssup_reverse.

Referenced by qsort_tuple_int32_compare().

ApplySignedSortComparator()

static int ApplySignedSortComparator ( Datum  datum1,
bool  isNull1,
Datum  datum2,
bool  isNull2,
SortSupport  ssup 
)
inlinestatic

Definition at line 266 of file sortsupport.h.

269{
270 int compare;
271
272 if (isNull1)
273 {
274 if (isNull2)
275 compare = 0; /* NULL "=" NULL */
276 else if (ssup->ssup_nulls_first)
277 compare = -1; /* NULL "<" NOT_NULL */
278 else
279 compare = 1; /* NULL ">" NOT_NULL */
280 }
281 else if (isNull2)
282 {
283 if (ssup->ssup_nulls_first)
284 compare = 1; /* NOT_NULL ">" NULL */
285 else
286 compare = -1; /* NOT_NULL "<" NULL */
287 }
288 else
289 {
290 compare = DatumGetInt64(datum1) < DatumGetInt64(datum2) ? -1 :
291 DatumGetInt64(datum1) > DatumGetInt64(datum2) ? 1 : 0;
292 if (ssup->ssup_reverse)
294 }
295
296 return compare;
297}
static int64 DatumGetInt64(Datum X)
Definition: postgres.h:393

References compare(), DatumGetInt64(), INVERT_COMPARE_RESULT, SortSupportData::ssup_nulls_first, and SortSupportData::ssup_reverse.

Referenced by qsort_tuple_signed_compare().

ApplySortAbbrevFullComparator()

static int ApplySortAbbrevFullComparator ( Datum  datum1,
bool  isNull1,
Datum  datum2,
bool  isNull2,
SortSupport  ssup 
)
inlinestatic

Definition at line 339 of file sortsupport.h.

342{
343 int compare;
344
345 if (isNull1)
346 {
347 if (isNull2)
348 compare = 0; /* NULL "=" NULL */
349 else if (ssup->ssup_nulls_first)
350 compare = -1; /* NULL "<" NOT_NULL */
351 else
352 compare = 1; /* NULL ">" NOT_NULL */
353 }
354 else if (isNull2)
355 {
356 if (ssup->ssup_nulls_first)
357 compare = 1; /* NOT_NULL ">" NULL */
358 else
359 compare = -1; /* NOT_NULL "<" NULL */
360 }
361 else
362 {
363 compare = ssup->abbrev_full_comparator(datum1, datum2, ssup);
364 if (ssup->ssup_reverse)
366 }
367
368 return compare;
369}
int(* abbrev_full_comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:191

References SortSupportData::abbrev_full_comparator, compare(), INVERT_COMPARE_RESULT, SortSupportData::ssup_nulls_first, and SortSupportData::ssup_reverse.

Referenced by comparetup_cluster_tiebreak(), comparetup_datum_tiebreak(), comparetup_heap_tiebreak(), and comparetup_index_btree_tiebreak().

ApplySortComparator()

static int ApplySortComparator ( Datum  datum1,
bool  isNull1,
Datum  datum2,
bool  isNull2,
SortSupport  ssup 
)
inlinestatic

Definition at line 200 of file sortsupport.h.

203{
204 int compare;
205
206 if (isNull1)
207 {
208 if (isNull2)
209 compare = 0; /* NULL "=" NULL */
210 else if (ssup->ssup_nulls_first)
211 compare = -1; /* NULL "<" NOT_NULL */
212 else
213 compare = 1; /* NULL ">" NOT_NULL */
214 }
215 else if (isNull2)
216 {
217 if (ssup->ssup_nulls_first)
218 compare = 1; /* NOT_NULL ">" NULL */
219 else
220 compare = -1; /* NOT_NULL "<" NULL */
221 }
222 else
223 {
224 compare = ssup->comparator(datum1, datum2, ssup);
225 if (ssup->ssup_reverse)
227 }
228
229 return compare;
230}
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:106

References SortSupportData::comparator, compare(), INVERT_COMPARE_RESULT, SortSupportData::ssup_nulls_first, and SortSupportData::ssup_reverse.

Referenced by _bt_load(), _gin_compare_tuples(), compare_datums_simple(), compare_scalars(), comparetup_cluster(), comparetup_cluster_tiebreak(), comparetup_datum(), comparetup_heap(), comparetup_heap_tiebreak(), comparetup_index_btree(), comparetup_index_btree_tiebreak(), GinBufferKeyEquals(), heap_compare_slots(), MJCompare(), multi_sort_compare(), multi_sort_compare_dim(), multi_sort_compare_dims(), setop_compare_slots(), and sort_item_compare().

ApplyUnsignedSortComparator()

static int ApplyUnsignedSortComparator ( Datum  datum1,
bool  isNull1,
Datum  datum2,
bool  isNull2,
SortSupport  ssup 
)
inlinestatic

Definition at line 233 of file sortsupport.h.

236{
237 int compare;
238
239 if (isNull1)
240 {
241 if (isNull2)
242 compare = 0; /* NULL "=" NULL */
243 else if (ssup->ssup_nulls_first)
244 compare = -1; /* NULL "<" NOT_NULL */
245 else
246 compare = 1; /* NULL ">" NOT_NULL */
247 }
248 else if (isNull2)
249 {
250 if (ssup->ssup_nulls_first)
251 compare = 1; /* NOT_NULL ">" NULL */
252 else
253 compare = -1; /* NOT_NULL "<" NULL */
254 }
255 else
256 {
257 compare = datum1 < datum2 ? -1 : datum1 > datum2 ? 1 : 0;
258 if (ssup->ssup_reverse)
260 }
261
262 return compare;
263}

References compare(), INVERT_COMPARE_RESULT, SortSupportData::ssup_nulls_first, and SortSupportData::ssup_reverse.

Referenced by qsort_tuple_unsigned_compare().

PrepareSortSupportComparisonShim()

void PrepareSortSupportComparisonShim ( Oid  cmpFunc,
SortSupport  ssup 
)

Definition at line 68 of file sortsupport.c.

69{
70 SortShimExtra *extra;
71
74
75 /* Lookup the comparison function */
76 fmgr_info_cxt(cmpFunc, &extra->flinfo, ssup->ssup_cxt);
77
78 /* We can initialize the callinfo just once and re-use it */
79 InitFunctionCallInfoData(extra->fcinfo, &extra->flinfo, 2,
80 ssup->ssup_collation, NULL, NULL);
81 extra->fcinfo.args[0].isnull = false;
82 extra->fcinfo.args[1].isnull = false;
83
84 ssup->ssup_extra = extra;
86}
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
Definition: fmgr.c:137
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1229
static int comparison_shim(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.c:43
#define SizeForSortShimExtra(nargs)
Definition: sortsupport.c:33
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
bool isnull
Definition: postgres.h:89
FmgrInfo flinfo
Definition: sortsupport.c:29
FunctionCallInfoBaseData fcinfo
Definition: sortsupport.c:30
Oid ssup_collation
Definition: sortsupport.h:67
void * ssup_extra
Definition: sortsupport.h:87
MemoryContext ssup_cxt
Definition: sortsupport.h:66

References FunctionCallInfoBaseData::args, SortSupportData::comparator, comparison_shim(), SortShimExtra::fcinfo, SortShimExtra::flinfo, fmgr_info_cxt(), InitFunctionCallInfoData, NullableDatum::isnull, MemoryContextAlloc(), SizeForSortShimExtra, SortSupportData::ssup_collation, SortSupportData::ssup_cxt, and SortSupportData::ssup_extra.

Referenced by FinishSortSupportFunction(), GinBufferInit(), and MJExamineQuals().

PrepareSortSupportFromGistIndexRel()

void PrepareSortSupportFromGistIndexRel ( Relation  indexRel,
SortSupport  ssup 
)

Definition at line 185 of file sortsupport.c.

186{
187 Oid opfamily = indexRel->rd_opfamily[ssup->ssup_attno - 1];
188 Oid opcintype = indexRel->rd_opcintype[ssup->ssup_attno - 1];
189 Oid sortSupportFunction;
190
191 Assert(ssup->comparator == NULL);
192
193 if (indexRel->rd_rel->relam != GIST_AM_OID)
194 elog(ERROR, "unexpected non-gist AM: %u", indexRel->rd_rel->relam);
195 ssup->ssup_reverse = false;
196
197 /*
198 * Look up the sort support function. This is simpler than for B-tree
199 * indexes because we don't support the old-style btree comparators.
200 */
201 sortSupportFunction = get_opfamily_proc(opfamily, opcintype, opcintype,
203 if (!OidIsValid(sortSupportFunction))
204 elog(ERROR, "missing support function %d(%u,%u) in opfamily %u",
205 GIST_SORTSUPPORT_PROC, opcintype, opcintype, opfamily);
206 OidFunctionCall1(sortSupportFunction, PointerGetDatum(ssup));
207}
#define OidIsValid(objectId)
Definition: c.h:774
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
#define OidFunctionCall1(functionId, arg1)
Definition: fmgr.h:720
#define GIST_SORTSUPPORT_PROC
Definition: gist.h:42
Assert(PointerIsAligned(start, uint64))
Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum)
Definition: lsyscache.c:889
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:332
unsigned int Oid
Definition: postgres_ext.h:32
Oid * rd_opcintype
Definition: rel.h:208
Oid * rd_opfamily
Definition: rel.h:207
Form_pg_class rd_rel
Definition: rel.h:111
AttrNumber ssup_attno
Definition: sortsupport.h:81

References Assert(), SortSupportData::comparator, elog, ERROR, get_opfamily_proc(), GIST_SORTSUPPORT_PROC, OidFunctionCall1, OidIsValid, PointerGetDatum(), RelationData::rd_opcintype, RelationData::rd_opfamily, RelationData::rd_rel, SortSupportData::ssup_attno, and SortSupportData::ssup_reverse.

Referenced by tuplesort_begin_index_gist().

PrepareSortSupportFromIndexRel()

void PrepareSortSupportFromIndexRel ( Relation  indexRel,
bool  reverse,
SortSupport  ssup 
)

Definition at line 161 of file sortsupport.c.

163{
164 Oid opfamily = indexRel->rd_opfamily[ssup->ssup_attno - 1];
165 Oid opcintype = indexRel->rd_opcintype[ssup->ssup_attno - 1];
166
167 Assert(ssup->comparator == NULL);
168
169 if (!indexRel->rd_indam->amcanorder)
170 elog(ERROR, "unexpected non-amcanorder AM: %u", indexRel->rd_rel->relam);
171 ssup->ssup_reverse = reverse;
172
173 FinishSortSupportFunction(opfamily, opcintype, ssup);
174}
static void FinishSortSupportFunction(Oid opfamily, Oid opcintype, SortSupport ssup)
Definition: sortsupport.c:94
bool amcanorder
Definition: amapi.h:246
struct IndexAmRoutine * rd_indam
Definition: rel.h:206

References IndexAmRoutine::amcanorder, Assert(), SortSupportData::comparator, elog, ERROR, FinishSortSupportFunction(), RelationData::rd_indam, RelationData::rd_opcintype, RelationData::rd_opfamily, RelationData::rd_rel, SortSupportData::ssup_attno, and SortSupportData::ssup_reverse.

Referenced by _bt_load(), tuplesort_begin_cluster(), and tuplesort_begin_index_btree().

PrepareSortSupportFromOrderingOp()

void PrepareSortSupportFromOrderingOp ( Oid  orderingOp,
SortSupport  ssup 
)

Definition at line 134 of file sortsupport.c.

135{
136 Oid opfamily;
137 Oid opcintype;
138 CompareType cmptype;
139
140 Assert(ssup->comparator == NULL);
141
142 /* Find the operator in pg_amop */
143 if (!get_ordering_op_properties(orderingOp, &opfamily, &opcintype,
144 &cmptype))
145 elog(ERROR, "operator %u is not a valid ordering operator",
146 orderingOp);
147 ssup->ssup_reverse = (cmptype == COMPARE_GT);
148
149 FinishSortSupportFunction(opfamily, opcintype, ssup);
150}
CompareType
Definition: cmptype.h:32
@ COMPARE_GT
Definition: cmptype.h:38
bool get_ordering_op_properties(Oid opno, Oid *opfamily, Oid *opcintype, CompareType *cmptype)
Definition: lsyscache.c:266

References Assert(), SortSupportData::comparator, COMPARE_GT, elog, ERROR, FinishSortSupportFunction(), get_ordering_op_properties(), and SortSupportData::ssup_reverse.

Referenced by compute_scalar_stats(), ExecInitGatherMerge(), ExecInitIndexScan(), ExecInitMergeAppend(), ExecInitSetOp(), multi_sort_add_dimension(), statext_mcv_serialize(), tuplesort_begin_datum(), tuplesort_begin_heap(), and tuplesort_begin_index_gin().

ssup_datum_int32_cmp()

int ssup_datum_int32_cmp ( Datum  x,
Datum  y,
SortSupport  ssup 
)

Definition at line 3158 of file tuplesort.c.

3159{
3160 int32 xx = DatumGetInt32(x);
3161 int32 yy = DatumGetInt32(y);
3162
3163 if (xx < yy)
3164 return -1;
3165 else if (xx > yy)
3166 return 1;
3167 else
3168 return 0;
3169}
int32_t int32
Definition: c.h:534
y
int y
Definition: isn.c:76
x
int x
Definition: isn.c:75

References DatumGetInt32(), x, and y.

Referenced by btint4sortsupport(), date_sortsupport(), and tuplesort_sort_memtuples().

ssup_datum_signed_cmp()

int ssup_datum_signed_cmp ( Datum  x,
Datum  y,
SortSupport  ssup 
)

Definition at line 3144 of file tuplesort.c.

3145{
3146 int64 xx = DatumGetInt64(x);
3147 int64 yy = DatumGetInt64(y);
3148
3149 if (xx < yy)
3150 return -1;
3151 else if (xx > yy)
3152 return 1;
3153 else
3154 return 0;
3155}
int64_t int64
Definition: c.h:535

References DatumGetInt64(), x, and y.

Referenced by btint8sortsupport(), timestamp_sortsupport(), and tuplesort_sort_memtuples().

ssup_datum_unsigned_cmp()

int ssup_datum_unsigned_cmp ( Datum  x,
Datum  y,
SortSupport  ssup 
)

Definition at line 3133 of file tuplesort.c.

3134{
3135 if (x < y)
3136 return -1;
3137 else if (x > y)
3138 return 1;
3139 else
3140 return 0;
3141}

References x, and y.

Referenced by gist_point_sortsupport(), macaddr_sortsupport(), network_sortsupport(), tuplesort_sort_memtuples(), uuid_sortsupport(), and varstr_sortsupport().

AltStyle によって変換されたページ (->オリジナル) /