diff options
Diffstat (limited to 'src/backend/commands/analyze.c')
-rw-r--r-- | src/backend/commands/analyze.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 314324618a8..c3d3958da76 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -47,8 +47,8 @@ #include "utils/lsyscache.h" #include "utils/memutils.h" #include "utils/pg_rusage.h" +#include "utils/sortsupport.h" #include "utils/syscache.h" -#include "utils/tuplesort.h" #include "utils/timestamp.h" #include "utils/tqual.h" @@ -1774,8 +1774,7 @@ typedef struct typedef struct { - FmgrInfo *cmpFn; - int cmpFlags; + SortSupport ssup; int *tupnoLink; } CompareScalarsContext; @@ -2222,9 +2221,7 @@ compute_scalar_stats(VacAttrStatsP stats, bool is_varwidth = (!stats->attrtype->typbyval && stats->attrtype->typlen < 0); double corr_xysum; - Oid cmpFn; - int cmpFlags; - FmgrInfo f_cmpfn; + SortSupportData ssup; ScalarItem *values; int values_cnt = 0; int *tupnoLink; @@ -2238,8 +2235,13 @@ compute_scalar_stats(VacAttrStatsP stats, tupnoLink = (int *) palloc(samplerows * sizeof(int)); track = (ScalarMCVItem *) palloc(num_mcv * sizeof(ScalarMCVItem)); - SelectSortFunction(mystats->ltopr, false, &cmpFn, &cmpFlags); - fmgr_info(cmpFn, &f_cmpfn); + memset(&ssup, 0, sizeof(ssup)); + ssup.ssup_cxt = CurrentMemoryContext; + /* We always use the default collation for statistics */ + ssup.ssup_collation = DEFAULT_COLLATION_OID; + ssup.ssup_nulls_first = false; + + PrepareSortSupportFromOrderingOp(mystats->ltopr, &ssup); /* Initial scan to find sortable values */ for (i = 0; i < samplerows; i++) @@ -2307,8 +2309,7 @@ compute_scalar_stats(VacAttrStatsP stats, CompareScalarsContext cxt; /* Sort the collected values */ - cxt.cmpFn = &f_cmpfn; - cxt.cmpFlags = cmpFlags; + cxt.ssup = &ssup; cxt.tupnoLink = tupnoLink; qsort_arg((void *) values, values_cnt, sizeof(ScalarItem), compare_scalars, (void *) &cxt); @@ -2712,12 +2713,9 @@ compare_scalars(const void *a, const void *b, void *arg) Datum db = ((const ScalarItem *) b)->value; int tb = ((const ScalarItem *) b)->tupno; CompareScalarsContext *cxt = (CompareScalarsContext *) arg; - int32 compare; + int compare; - /* We always use the default collation for statistics */ - compare = ApplySortFunction(cxt->cmpFn, cxt->cmpFlags, - DEFAULT_COLLATION_OID, - da, false, db, false); + compare = ApplySortComparator(da, false, db, false, cxt->ssup); if (compare != 0) return compare; |