Skip to content

Commit 105eb36

Browse files
committed
Remove ATPrepSetStatistics
It was once possible to do ALTER TABLE ... SET STATISTICS on system tables without allow_sytem_table_mods. This was changed apparently by accident between PostgreSQL 9.1 and 9.2, but a code comment still claimed this was possible. Without that functionality, having a separate ATPrepSetStatistics() is useless, so use the generic ATSimplePermissions() instead and move the remaining custom code into ATExecSetStatistics(). Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/cc8d2648-a0ec-7a86-13e5-db473484e19e%402ndquadrant.com
1 parent b802412 commit 105eb36

File tree

1 file changed

+12
-41
lines changed

1 file changed

+12
-41
lines changed

src/backend/commands/tablecmds.c

+12-41
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,6 @@ static ObjectAddress ATExecAddIdentity(Relation rel, const char *colName,
386386
static ObjectAddress ATExecSetIdentity(Relation rel, const char *colName,
387387
Node *def, LOCKMODE lockmode);
388388
static ObjectAddress ATExecDropIdentity(Relation rel, const char *colName, bool missing_ok, LOCKMODE lockmode);
389-
static void ATPrepSetStatistics(Relation rel, const char *colName, int16 colNum,
390-
Node *newValue, LOCKMODE lockmode);
391389
static ObjectAddress ATExecSetStatistics(Relation rel, const char *colName, int16 colNum,
392390
Node *newValue, LOCKMODE lockmode);
393391
static ObjectAddress ATExecSetOptions(Relation rel, const char *colName,
@@ -3948,9 +3946,9 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
39483946
pass = AT_PASS_COL_ATTRS;
39493947
break;
39503948
case AT_SetStatistics: /* ALTER COLUMN SET STATISTICS */
3949+
ATSimplePermissions(rel, ATT_TABLE | ATT_MATVIEW | ATT_INDEX | ATT_PARTITIONED_INDEX | ATT_FOREIGN_TABLE);
39513950
ATSimpleRecursion(wqueue, rel, cmd, recurse, lockmode);
3952-
/* Performs own permission checks */
3953-
ATPrepSetStatistics(rel, cmd->name, cmd->num, cmd->def, lockmode);
3951+
/* No command-specific prep needed */
39543952
pass = AT_PASS_MISC;
39553953
break;
39563954
case AT_SetOptions: /* ALTER COLUMN SET ( options ) */
@@ -6702,26 +6700,18 @@ ATExecDropIdentity(Relation rel, const char *colName, bool missing_ok, LOCKMODE
67026700

67036701
/*
67046702
* ALTER TABLE ALTER COLUMN SET STATISTICS
6703+
*
6704+
* Return value is the address of the modified column
67056705
*/
6706-
static void
6707-
ATPrepSetStatistics(Relation rel, const char *colName, int16 colNum, Node *newValue, LOCKMODE lockmode)
6706+
static ObjectAddress
6707+
ATExecSetStatistics(Relation rel, const char *colName, int16 colNum, Node *newValue, LOCKMODE lockmode)
67086708
{
6709-
/*
6710-
* We do our own permission checking because (a) we want to allow SET
6711-
* STATISTICS on indexes (for expressional index columns), and (b) we want
6712-
* to allow SET STATISTICS on system catalogs without requiring
6713-
* allowSystemTableMods to be turned on.
6714-
*/
6715-
if (rel->rd_rel->relkind != RELKIND_RELATION &&
6716-
rel->rd_rel->relkind != RELKIND_MATVIEW &&
6717-
rel->rd_rel->relkind != RELKIND_INDEX &&
6718-
rel->rd_rel->relkind != RELKIND_PARTITIONED_INDEX &&
6719-
rel->rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
6720-
rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
6721-
ereport(ERROR,
6722-
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
6723-
errmsg("\"%s\" is not a table, materialized view, index, or foreign table",
6724-
RelationGetRelationName(rel))));
6709+
int newtarget;
6710+
Relation attrelation;
6711+
HeapTuple tuple;
6712+
Form_pg_attribute attrtuple;
6713+
AttrNumber attnum;
6714+
ObjectAddress address;
67256715

67266716
/*
67276717
* We allow referencing columns by numbers only for indexes, since table
@@ -6734,25 +6724,6 @@ ATPrepSetStatistics(Relation rel, const char *colName, int16 colNum, Node *newVa
67346724
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
67356725
errmsg("cannot refer to non-index column by number")));
67366726

6737-
/* Permissions checks */
6738-
if (!pg_class_ownercheck(RelationGetRelid(rel), GetUserId()))
6739-
aclcheck_error(ACLCHECK_NOT_OWNER, get_relkind_objtype(rel->rd_rel->relkind),
6740-
RelationGetRelationName(rel));
6741-
}
6742-
6743-
/*
6744-
* Return value is the address of the modified column
6745-
*/
6746-
static ObjectAddress
6747-
ATExecSetStatistics(Relation rel, const char *colName, int16 colNum, Node *newValue, LOCKMODE lockmode)
6748-
{
6749-
int newtarget;
6750-
Relation attrelation;
6751-
HeapTuple tuple;
6752-
Form_pg_attribute attrtuple;
6753-
AttrNumber attnum;
6754-
ObjectAddress address;
6755-
67566727
Assert(IsA(newValue, Integer));
67576728
newtarget = intVal(newValue);
67586729

0 commit comments

Comments
 (0)