/* Info needed to use an old-style comparison function as a sort comparator */ typedefstruct
{
FmgrInfo flinfo; /* lookup data for comparison function */
FunctionCallInfoBaseData fcinfo; /* reusable callinfo structure */
} SortShimExtra;
/* 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);
extra = (SortShimExtra *) MemoryContextAlloc(ssup->ssup_cxt,
SizeForSortShimExtra(2));
/* 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.args[0].isnull = false;
extra->fcinfo.args[1].isnull = false;
/* *LookupandcallsortsupportfunctiontosetupSortSupportcomparator; *orifnosuchfunctionexistsoritdeclinestosetuptheappropriate *state,prepareasuitableshim.
*/ staticvoid
FinishSortSupportFunction(Oid opfamily, Oid opcintype, SortSupport ssup)
{
Oid sortSupportFunction;
/* Look for a sort support function */
sortSupportFunction = get_opfamily_proc(opfamily, opcintype, opcintype,
BTSORTSUPPORT_PROC); if (OidIsValid(sortSupportFunction))
{ /* *Thesortsupportfunctioncanprovideacomparator,butitcanalso *choosenottoso(e.g.basedontheselectedcollation).
*/
OidFunctionCall1(sortSupportFunction, PointerGetDatum(ssup));
}
if (!OidIsValid(sortFunction))
elog(ERROR, "missing support function %d(%u,%u) in opfamily %u",
BTORDER_PROC, opcintype, opcintype, opfamily);
/* We'll use a shim to call the old-style btree comparator */
PrepareSortSupportComparisonShim(sortFunction, ssup);
}
}
/* *FillinSortSupportgivenanorderingoperator(btree"<"or">"operator). * *CallermustpreviouslyhavezeroedtheSortSupportDatastructureandthen *filledinssup_cxt,ssup_collation,andssup_nulls_first.Thiswillfill *inssup_reverseaswellasthecomparatorfunctionpointer.
*/ void
PrepareSortSupportFromOrderingOp(Oid orderingOp, SortSupport ssup)
{
Oid opfamily;
Oid opcintype;
CompareType cmptype;
Assert(ssup->comparator == NULL);
/* Find the operator in pg_amop */ if (!get_ordering_op_properties(orderingOp, &opfamily, &opcintype,
&cmptype))
elog(ERROR, "operator %u is not a valid ordering operator",
orderingOp);
ssup->ssup_reverse = (cmptype == COMPARE_GT);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.