Skip to content

Commit

Permalink
Fix ANALYZE crash with custom types
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nikkhils committed Oct 27, 2021
1 parent 0fecefd commit af7f6ea
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tsl/src/chunk_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,14 @@ collect_colstat_slots(const HeapTuple tuple, const Form_pg_statistic formdata, D
slot_collation[i] = ObjectIdGetDatum(((Oid *) &formdata->stacoll1)[i]);

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[values_idx] = true;
Expand Down Expand Up @@ -1175,7 +1182,12 @@ chunk_process_remote_colstats_row(StatsProcessContext *ctx, TupleFactory *tf, Tu
value_arrays[i] = NULL;
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;

for (k = 0; k < STRINGS_PER_OP_OID; ++k)
Expand Down

0 comments on commit af7f6ea

Please sign in to comment.