1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-22 21:53:06 +03:00

Tighten up relation kind checks for extended statistics

We were accepting creation of extended statistics only for regular
tables, but they can usefully be created for foreign tables, partitioned
tables, and materialized views, too.  Allow those cases.

While at it, make sure all the rejected cases throw a consistent error
message, and add regression tests for the whole thing.

Author: David Rowley, Álvaro Herrera
Discussion: https://postgr.es/m/CAKJS1f-BmGo410bh5RSPZUvOO0LhmHL2NYmdrC_Jm8pk_FfyCA@mail.gmail.com
This commit is contained in:
Alvaro Herrera
2017-04-17 17:55:17 -03:00
parent 76799fc89d
commit 8c5cdb7f4f
5 changed files with 92 additions and 7 deletions

View File

@@ -102,14 +102,16 @@ CreateStatistics(CreateStatsStmt *stmt)
* take only ShareUpdateExclusiveLock on relation, conflicting with
* ANALYZE and other DDL that sets statistical information.
*/
rel = heap_openrv(stmt->relation, ShareUpdateExclusiveLock);
rel = relation_openrv(stmt->relation, ShareUpdateExclusiveLock);
relid = RelationGetRelid(rel);
if (rel->rd_rel->relkind != RELKIND_RELATION &&
rel->rd_rel->relkind != RELKIND_MATVIEW)
rel->rd_rel->relkind != RELKIND_MATVIEW &&
rel->rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("relation \"%s\" is not a table or materialized view",
errmsg("relation \"%s\" is not a table, foreign table, or materialized view",
RelationGetRelationName(rel))));
/*
@@ -248,7 +250,7 @@ CreateStatistics(CreateStatsStmt *stmt)
CatalogTupleInsert(statrel, htup);
statoid = HeapTupleGetOid(htup);
heap_freetuple(htup);
heap_close(statrel, RowExclusiveLock);
relation_close(statrel, RowExclusiveLock);
/*
* Invalidate relcache so that others see the new statistics.