Fix ANALYZE crash with custom types

Extensions like PostGIS introduce custom datatypes for columns. They
also have custom statistics for such custom types. We already state in
our comments that stats for custom types are not supported but it was
never tested. Fix that now.

Fixes #3733
This commit is contained in:
Nikhil Sontakke 2021-10-27 11:38:01 +05:30 committed by Nikhils
parent 0fecefdafa
commit 6db012dcc9
2 changed files with 16 additions and 2 deletions

View File

@ -16,12 +16,14 @@ accidentally triggering the load of a previous DB version.**
* #3708 Fix crash in get_aggsplit * #3708 Fix crash in get_aggsplit
* #3709 Fix ordered append pathkey check * #3709 Fix ordered append pathkey check
* #3728 Fix SkipScan with varchar column * #3728 Fix SkipScan with varchar column
* #3733 Fix ANALYZE crash with custom statistics for custom types
**Thanks** **Thanks**
* @binakot and @sebvett for reporting an issue with DISTINCT queries * @binakot and @sebvett for reporting an issue with DISTINCT queries
* @hardikm10, @DavidPavlicek and @pafiti for reporting bugs on TRUNCATE * @hardikm10, @DavidPavlicek and @pafiti for reporting bugs on TRUNCATE
* @mjf for reporting an issue with ordered append and JOINs * @mjf for reporting an issue with ordered append and JOINs
* @phemmer for reporting the issues on multinode with aggregate queries and evaluation of now() * @phemmer for reporting the issues on multinode with aggregate queries and evaluation of now()
* @tanglebones for reporting the ANALYZE crash with custom types on multinode
## 2.4.2 (2021-09-21) ## 2.4.2 (2021-09-21)

View File

@ -757,7 +757,14 @@ collect_colstat_slots(const HeapTuple tuple, const Form_pg_statistic formdata, D
slot_collation[i] = ObjectIdGetDatum(((Oid *) &formdata->stacoll1)[i]); slot_collation[i] = ObjectIdGetDatum(((Oid *) &formdata->stacoll1)[i]);
slotkind[i] = ObjectIdGetDatum(kind); slotkind[i] = ObjectIdGetDatum(kind);
if (kind == InvalidOid)
/*
* As per comments in pg_statistic_d.h, "kind" codes from 0 - 99 are reserved
* for assignment by the core PostgreSQL project. Beyond that are for PostGIS
* and other projects
*/
#define PG_STATS_KINDS_MAX 99
if (kind == InvalidOid || kind > PG_STATS_KINDS_MAX)
{ {
nulls[numbers_idx] = true; nulls[numbers_idx] = true;
nulls[values_idx] = true; nulls[values_idx] = true;
@ -1175,7 +1182,12 @@ chunk_process_remote_colstats_row(StatsProcessContext *ctx, TupleFactory *tf, Tu
value_arrays[i] = NULL; value_arrays[i] = NULL;
valtype_oids[i] = InvalidOid; valtype_oids[i] = InvalidOid;
if (slot_kinds[i] == InvalidOid) /*
* As per comments in pg_statistic_d.h, "kind" codes from 0 - 99 are reserved
* for assignment by the core PostgreSQL project. Beyond that are for PostGIS
* and other projects
*/
if (slot_kinds[i] == InvalidOid || slot_kinds[i] > PG_STATS_KINDS_MAX)
continue; continue;
for (k = 0; k < STRINGS_PER_OP_OID; ++k) for (k = 0; k < STRINGS_PER_OP_OID; ++k)