~aglenyoung/+junk/postgres-9.3-dtrace

« back to all changes in this revision

Viewing changes to src/backend/utils/adt/rangetypes_typanalyze.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt, Christoph Berg, Martin Pitt
  • Date: 2013-06-26 15:13:32 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130626151332-p34yjpn0txbdsdzd
Tags: 9.3~beta2-1
[ Christoph Berg ]
* hurd-i386: Ignore testsuite failures so we have a working libpq5 (they
  don't implement semaphores so the server won't even start).
* Mark postgresql-9.3 as beta in the description, suggested by Joshua D.
  Drake.

[ Martin Pitt ]
* New upstream release 9.3 beta2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include "utils/builtins.h"
30
30
#include "utils/rangetypes.h"
31
31
 
32
 
static int float8_qsort_cmp(const void *a1, const void *a2);
33
 
static int range_bound_qsort_cmp(const void *a1, const void *a2, void *arg);
 
32
static int      float8_qsort_cmp(const void *a1, const void *a2);
 
33
static int      range_bound_qsort_cmp(const void *a1, const void *a2, void *arg);
34
34
static void compute_range_stats(VacAttrStats *stats,
35
35
                   AnalyzeAttrFetchFunc fetchfunc, int samplerows, double totalrows);
36
36
 
48
48
        typcache = range_get_typcache(fcinfo, stats->attrtypid);
49
49
 
50
50
        if (attr->attstattarget < 0)
51
 
        attr->attstattarget = default_statistics_target;
 
51
                attr->attstattarget = default_statistics_target;
52
52
 
53
53
        stats->compute_stats = compute_range_stats;
54
54
        stats->extra_data = typcache;
81
81
static int
82
82
range_bound_qsort_cmp(const void *a1, const void *a2, void *arg)
83
83
{
84
 
        RangeBound *b1 = (RangeBound *)a1;
85
 
        RangeBound *b2 = (RangeBound *)a2;
86
 
        TypeCacheEntry *typcache = (TypeCacheEntry *)arg;
 
84
        RangeBound *b1 = (RangeBound *) a1;
 
85
        RangeBound *b2 = (RangeBound *) a2;
 
86
        TypeCacheEntry *typcache = (TypeCacheEntry *) arg;
87
87
 
88
88
        return range_cmp_bounds(typcache, b1, b2);
89
89
}
106
106
        int                     num_bins = stats->attr->attstattarget;
107
107
        int                     num_hist;
108
108
        float8     *lengths;
109
 
        RangeBound *lowers, *uppers;
 
109
        RangeBound *lowers,
 
110
                           *uppers;
110
111
        double          total_width = 0;
111
112
 
112
113
        /* Allocate memory to hold range bounds and lengths of the sample ranges. */
163
164
                                 * and lower bound values.
164
165
                                 */
165
166
                                length = DatumGetFloat8(FunctionCall2Coll(
166
 
                                                                                        &typcache->rng_subdiff_finfo,
167
 
                                                                                        typcache->rng_collation,
168
 
                                                                                        upper.val, lower.val));
 
167
                                                                                                &typcache->rng_subdiff_finfo,
 
168
                                                                                                         typcache->rng_collation,
 
169
                                                                                                          upper.val, lower.val));
169
170
                        }
170
171
                        else
171
172
                        {
227
228
                        /*
228
229
                         * The object of this loop is to construct ranges from first and
229
230
                         * last entries in lowers[] and uppers[] along with evenly-spaced
230
 
                         * values in between. So the i'th value is a range of
231
 
                         * lowers[(i * (nvals - 1)) / (num_hist - 1)] and
232
 
                         * uppers[(i * (nvals - 1)) / (num_hist - 1)]. But computing that
233
 
                         * subscript directly risks integer overflow when the stats target
234
 
                         * is more than a couple thousand.  Instead we add
235
 
                         * (nvals - 1) / (num_hist - 1) to pos at each step, tracking the
236
 
                         * integral and fractional parts of the sum separately.
 
231
                         * values in between. So the i'th value is a range of lowers[(i *
 
232
                         * (nvals - 1)) / (num_hist - 1)] and uppers[(i * (nvals - 1)) /
 
233
                         * (num_hist - 1)]. But computing that subscript directly risks
 
234
                         * integer overflow when the stats target is more than a couple
 
235
                         * thousand.  Instead we add (nvals - 1) / (num_hist - 1) to pos
 
236
                         * at each step, tracking the integral and fractional parts of the
 
237
                         * sum separately.
237
238
                         */
238
239
                        delta = (non_empty_cnt - 1) / (num_hist - 1);
239
240
                        deltafrac = (non_empty_cnt - 1) % (num_hist - 1);
242
243
                        for (i = 0; i < num_hist; i++)
243
244
                        {
244
245
                                bound_hist_values[i] = PointerGetDatum(range_serialize(
245
 
                                                                typcache, &lowers[pos], &uppers[pos], false));
 
246
                                                           typcache, &lowers[pos], &uppers[pos], false));
246
247
                                pos += delta;
247
248
                                posfrac += deltafrac;
248
249
                                if (posfrac >= (num_hist - 1))
281
282
                         * The object of this loop is to copy the first and last lengths[]
282
283
                         * entries along with evenly-spaced values in between. So the i'th
283
284
                         * value is lengths[(i * (nvals - 1)) / (num_hist - 1)]. But
284
 
                         * computing that subscript directly risks integer overflow when the
285
 
                         * stats target is more than a couple thousand.  Instead we add
286
 
                         * (nvals - 1) / (num_hist - 1) to pos at each step, tracking the
287
 
                         * integral and fractional parts of the sum separately.
 
285
                         * computing that subscript directly risks integer overflow when
 
286
                         * the stats target is more than a couple thousand.  Instead we
 
287
                         * add (nvals - 1) / (num_hist - 1) to pos at each step, tracking
 
288
                         * the integral and fractional parts of the sum separately.
288
289
                         */
289
290
                        delta = (non_empty_cnt - 1) / (num_hist - 1);
290
291
                        deltafrac = (non_empty_cnt - 1) % (num_hist - 1);
342
343
                /* We found only nulls; assume the column is entirely null */
343
344
                stats->stats_valid = true;
344
345
                stats->stanullfrac = 1.0;
345
 
                stats->stawidth = 0;            /* "unknown" */
346
 
                stats->stadistinct = 0.0;       /* "unknown" */
 
346
                stats->stawidth = 0;    /* "unknown" */
 
347
                stats->stadistinct = 0.0;               /* "unknown" */
347
348
        }
 
349
 
348
350
        /*
349
351
         * We don't need to bother cleaning up any of our temporary palloc's. The
350
352
         * hashtable should also go away, as it used a child memory context.