Skip to content

Commit 4d8be00

Browse files
committed
pathman: sorting bug fixed for ranges
1 parent c758c4b commit 4d8be00

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

contrib/pg_pathman/init.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ HTAB *relations = NULL;
1616
HTAB *range_restrictions = NULL;
1717
bool initialization_needed = true;
1818

19+
static FmgrInfo *qsort_type_cmp_func;
1920

2021
static bool validate_range_constraint(Expr *, PartRelationInfo *, Datum *, Datum *);
2122
static bool validate_hash_constraint(Expr *expr, PartRelationInfo *prel, int *hash);
@@ -279,7 +280,12 @@ load_check_constraints(Oid parent_oid)
279280

280281
if (prel->parttype == PT_RANGE)
281282
{
283+
TypeCacheEntry *tce;
284+
282285
/* Sort ascending */
286+
tce = lookup_type_cache(prel->atttype,
287+
TYPECACHE_CMP_PROC | TYPECACHE_CMP_PROC_FINFO);
288+
qsort_type_cmp_func = &tce->cmp_proc_finfo;
283289
qsort(ranges, proc, sizeof(RangeEntry), cmp_range_entries);
284290

285291
/* Copy oids to prel */
@@ -308,11 +314,7 @@ cmp_range_entries(const void *p1, const void *p2)
308314
const RangeEntry *v1 = (const RangeEntry *) p1;
309315
const RangeEntry *v2 = (const RangeEntry *) p2;
310316

311-
if (v1->min < v2->min)
312-
return -1;
313-
if (v1->min > v2->min)
314-
return 1;
315-
return 0;
317+
return FunctionCall2(qsort_type_cmp_func, v1->min, v2->min);
316318
}
317319

318320
/*

0 commit comments

Comments
 (0)