#include "postgres.h"
#include "fmgr.h"
#include "utils/lsyscache.h"
#include "utils/sortsupport.h"
Go to the source code of this file.
Data Structures | |
struct | SortShimExtra |
Defines | |
#define | SORTSUPPORT_INCLUDE_DEFINITIONS |
Functions | |
static int | comparison_shim (Datum x, Datum y, SortSupport ssup) |
void | PrepareSortSupportComparisonShim (Oid cmpFunc, SortSupport ssup) |
void | PrepareSortSupportFromOrderingOp (Oid orderingOp, SortSupport ssup) |
#define SORTSUPPORT_INCLUDE_DEFINITIONS |
Definition at line 19 of file sortsupport.c.
static int comparison_shim | ( | Datum | x, | |
Datum | y, | |||
SortSupport | ssup | |||
) | [static] |
Definition at line 42 of file sortsupport.c.
References FunctionCallInfoData::arg, elog, ERROR, SortShimExtra::fcinfo, SortShimExtra::flinfo, FmgrInfo::fn_oid, FunctionCallInvoke, FunctionCallInfoData::isnull, and SortSupportData::ssup_extra.
{ SortShimExtra *extra = (SortShimExtra *) ssup->ssup_extra; Datum result; extra->fcinfo.arg[0] = x; extra->fcinfo.arg[1] = y; /* just for paranoia's sake, we reset isnull each time */ extra->fcinfo.isnull = false; result = FunctionCallInvoke(&extra->fcinfo); /* Check for null result, since caller is clearly not expecting one */ if (extra->fcinfo.isnull) elog(ERROR, "function %u returned NULL", extra->flinfo.fn_oid); return result; }
void PrepareSortSupportComparisonShim | ( | Oid | cmpFunc, | |
SortSupport | ssup | |||
) |
Definition at line 67 of file sortsupport.c.
References FunctionCallInfoData::argnull, SortSupportData::comparator, SortShimExtra::fcinfo, SortShimExtra::flinfo, fmgr_info_cxt(), InitFunctionCallInfoData, MemoryContextAlloc(), NULL, SortSupportData::ssup_collation, SortSupportData::ssup_cxt, and SortSupportData::ssup_extra.
Referenced by MJExamineQuals(), and PrepareSortSupportFromOrderingOp().
{ SortShimExtra *extra; extra = (SortShimExtra *) MemoryContextAlloc(ssup->ssup_cxt, sizeof(SortShimExtra)); /* Lookup the comparison function */ fmgr_info_cxt(cmpFunc, &extra->flinfo, ssup->ssup_cxt); /* We can initialize the callinfo just once and re-use it */ InitFunctionCallInfoData(extra->fcinfo, &extra->flinfo, 2, ssup->ssup_collation, NULL, NULL); extra->fcinfo.argnull[0] = false; extra->fcinfo.argnull[1] = false; ssup->ssup_extra = extra; ssup->comparator = comparison_shim; }
void PrepareSortSupportFromOrderingOp | ( | Oid | orderingOp, | |
SortSupport | ssup | |||
) |
Definition at line 95 of file sortsupport.c.
References Assert, SortSupportData::comparator, elog, ERROR, get_sort_function_for_ordering_op(), NULL, OidFunctionCall1, PointerGetDatum, PrepareSortSupportComparisonShim(), and SortSupportData::ssup_reverse.
Referenced by compute_scalar_stats(), ExecInitMergeAppend(), tuplesort_begin_datum(), and tuplesort_begin_heap().
{ Oid sortFunction; bool issupport; if (!get_sort_function_for_ordering_op(orderingOp, &sortFunction, &issupport, &ssup->ssup_reverse)) elog(ERROR, "operator %u is not a valid ordering operator", orderingOp); if (issupport) { /* The sort support function should provide a comparator */ OidFunctionCall1(sortFunction, PointerGetDatum(ssup)); Assert(ssup->comparator != NULL); } else { /* We'll use a shim to call the old-style btree comparator */ PrepareSortSupportComparisonShim(sortFunction, ssup); } }