*** src/backend/commands/analyze.c --- /tmp/.diff_sIxSwv 2008-06-02 17:55:58.000000000 +0200 *************** *** 683,688 **** --- 683,689 ---- Form_pg_attribute attr = onerel->rd_att->attrs[attnum - 1]; HeapTuple typtuple; VacAttrStats *stats; + int i; bool ok; /* Never analyze dropped columns */ *************** *** 711,716 **** --- 712,730 ---- stats->tupattnum = attnum; /* + * Initialize fields describing the stats->stavalues[n] element types, so + * the typanalyze function will have some defaults in case it neglects to + * set them itself. + */ + for (i = 0; i < STATISTIC_NUM_SLOTS; i++) + { + stats->statypid[i] = stats->attr->atttypid; + stats->statyplen[i] = stats->attrtype->typlen; + stats->statypbyval[i] = stats->attrtype->typbyval; + stats->statypalign[i] = stats->attrtype->typalign; + } + + /* * Call the type-specific typanalyze function. If none is specified, use * std_typanalyze(). */ *************** *** 1321,1330 **** arry = construct_array(stats->stavalues[k], stats->numvalues[k], ! stats->attr->atttypid, ! stats->attrtype->typlen, ! stats->attrtype->typbyval, ! stats->attrtype->typalign); values[i++] = PointerGetDatum(arry); /* stavaluesN */ } else --- 1335,1344 ---- arry = construct_array(stats->stavalues[k], stats->numvalues[k], ! stats->statypid[k], ! stats->statyplen[k], ! stats->statypbyval[k], ! stats->statypalign[k]); values[i++] = PointerGetDatum(arry); /* stavaluesN */ } else *************** *** 1854,1859 **** --- 1868,1877 ---- stats->numnumbers[0] = num_mcv; stats->stavalues[0] = mcv_values; stats->numvalues[0] = num_mcv; + /* + * Accept the defaults for stats->statypid and others. + * They have been set before we were called (see vacuum.h) + */ } } else if (null_cnt > 0) *************** *** 2197,2202 **** --- 2215,2224 ---- stats->numnumbers[slot_idx] = num_mcv; stats->stavalues[slot_idx] = mcv_values; stats->numvalues[slot_idx] = num_mcv; + /* + * Accept the defaults for stats->statypid and others. + * They have been set before we were called (see vacuum.h) + */ slot_idx++; } *************** *** 2281,2286 **** --- 2303,2312 ---- stats->staop[slot_idx] = mystats->ltopr; stats->stavalues[slot_idx] = hist_values; stats->numvalues[slot_idx] = num_hist; + /* + * Accept the defaults for stats->statypid and others. + * They have been set before we were called (see vacuum.h) + */ slot_idx++; } *** src/include/commands/vacuum.h --- /tmp/.diff_YRgK4O 2008-06-02 17:55:58.000000000 +0200 *************** *** 94,99 **** --- 94,111 ---- Datum *stavalues[STATISTIC_NUM_SLOTS]; /* + * These fields describe the stavalues[n] element types. They will + * be initialized to be the same as the column's that's underlying the slot, + * but a custom typanalyze function might want to store an array of + * something other that the analyzed column's elements. It should then + * overwrite these fields. + */ + Oid statypid[STATISTIC_NUM_SLOTS]; + int2 statyplen[STATISTIC_NUM_SLOTS]; + bool statypbyval[STATISTIC_NUM_SLOTS]; + char statypalign[STATISTIC_NUM_SLOTS]; + + /* * These fields are private to the main ANALYZE code and should not be * looked at by type-specific functions. */