diff options
| author | Alvaro Herrera | 2017-04-17 20:55:17 +0000 |
|---|---|---|
| committer | Alvaro Herrera | 2017-04-17 20:55:55 +0000 |
| commit | 8c5cdb7f4f6e1d6a6104cb58ce4f23453891651b (patch) | |
| tree | 25a5dfbae4b5d274b17cdb592ad120e36469c06e /src/backend/commands/statscmds.c | |
| parent | 76799fc89d2ca6f357c188daa4e1b38f0a59e360 (diff) | |
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
Diffstat (limited to 'src/backend/commands/statscmds.c')
| -rw-r--r-- | src/backend/commands/statscmds.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/backend/commands/statscmds.c b/src/backend/commands/statscmds.c index 46abadcc811..2dd32d9318a 100644 --- a/src/backend/commands/statscmds.c +++ b/src/backend/commands/statscmds.c @@ -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. |
