Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfdd8857

Browse files
committed
Block ALTER INDEX/TABLE index_name ALTER COLUMN colname SET (options)
The grammar of this command run on indexes with column names has alwaysbeen authorized by the parser, and it has never been documented.Since911e702, it is possible to define opclass parameters as of CREATEINDEX, which actually broke the old case of ALTER INDEX/TABLE whererelation-level parameters n_distinct and n_distinct_inherited could bedefined for an index (see76a47c0 and its thread where this point hasbeen touched, still remained unused). Attempting to do that in v13~would cause the index to become unusable, as there is a new dedicatedcode path to load opclass parameters instead of the relation-level onespreviously available. Note that it is possible to fix things with amanual catalog update to bring the relation back online.This commit disables this command for now as the use of column names forindexes does not make sense anyway, particularly when it comes to indexexpressions where names are automatically computed. One way to properlysupport this case properly in the future would be to use column numberswhen it comes to indexes, in the same way as ALTER INDEX .. ALTER COLUMN.. SET STATISTICS.Partitioned indexes were already blocked, but not indexes. Some testsare added for both cases.There was some code in ANALYZE to enforce n_distinct to be used for anindex expression if the parameter was defined, but just remove it fornow until/if there is support for this (note that index-level parametersnever had support in pg_dump either, previously), so this was just deadcode.Reported-by: Matthijs van der VleutenAuthor: Nathan Bossart, Michael PaquierReviewed-by: Vik Fearing, Dilip KumarDiscussion:https://postgr.es/m/17220-15d684c6c2171a83@postgresql.orgBackpatch-through: 13
1 parentd6f1e16 commitfdd8857

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

‎src/backend/commands/analyze.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -965,9 +965,6 @@ compute_index_stats(Relation onerel, double totalrows,
965965
for (i=0;i<attr_cnt;i++)
966966
{
967967
VacAttrStats*stats=thisdata->vacattrstats[i];
968-
AttributeOpts*aopt=
969-
get_attribute_options(stats->attr->attrelid,
970-
stats->attr->attnum);
971968

972969
stats->exprvals=exprvals+i;
973970
stats->exprnulls=exprnulls+i;
@@ -977,14 +974,6 @@ compute_index_stats(Relation onerel, double totalrows,
977974
numindexrows,
978975
totalindexrows);
979976

980-
/*
981-
* If the n_distinct option is specified, it overrides the
982-
* above computation. For indices, we always use just
983-
* n_distinct, not n_distinct_inherited.
984-
*/
985-
if (aopt!=NULL&&aopt->n_distinct!=0.0)
986-
stats->stadistinct=aopt->n_distinct;
987-
988977
MemoryContextResetAndDeleteChildren(col_context);
989978
}
990979
}

‎src/backend/commands/tablecmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4494,7 +4494,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
44944494
break;
44954495
case AT_SetOptions:/* ALTER COLUMN SET ( options ) */
44964496
case AT_ResetOptions:/* ALTER COLUMN RESET ( options ) */
4497-
ATSimplePermissions(cmd->subtype, rel, ATT_TABLE | ATT_MATVIEW |ATT_INDEX |ATT_FOREIGN_TABLE);
4497+
ATSimplePermissions(cmd->subtype, rel, ATT_TABLE | ATT_MATVIEW | ATT_FOREIGN_TABLE);
44984498
/* This command never recurses */
44994499
pass = AT_PASS_MISC;
45004500
break;

‎src/test/regress/expected/btree_index.out

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,17 @@ INSERT INTO delete_test_table SELECT i, 1, 2, 3 FROM generate_series(1,1000) i;
329329
-- Test unsupported btree opclass parameters
330330
create index on btree_tall_tbl (id int4_ops(foo=1));
331331
ERROR: operator class int4_ops has no options
332+
-- Test case of ALTER INDEX with abuse of column names for indexes.
333+
-- This grammar is not officially supported, but the parser allows it.
334+
CREATE INDEX btree_tall_idx2 ON btree_tall_tbl (id);
335+
ALTER INDEX btree_tall_idx2 ALTER COLUMN id SET (n_distinct=100);
336+
ERROR: ALTER action ALTER COLUMN ... SET cannot be performed on relation "btree_tall_idx2"
337+
DETAIL: This operation is not supported for indexes.
338+
DROP INDEX btree_tall_idx2;
339+
-- Partitioned index
340+
CREATE TABLE btree_part (id int4) PARTITION BY RANGE (id);
341+
CREATE INDEX btree_part_idx ON btree_part(id);
342+
ALTER INDEX btree_part_idx ALTER COLUMN id SET (n_distinct=100);
343+
ERROR: ALTER action ALTER COLUMN ... SET cannot be performed on relation "btree_part_idx"
344+
DETAIL: This operation is not supported for partitioned indexes.
345+
DROP TABLE btree_part;

‎src/test/regress/sql/btree_index.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,14 @@ INSERT INTO delete_test_table SELECT i, 1, 2, 3 FROM generate_series(1,1000) i;
172172

173173
-- Test unsupported btree opclass parameters
174174
createindexon btree_tall_tbl (id int4_ops(foo=1));
175+
176+
-- Test case of ALTER INDEX with abuse of column names for indexes.
177+
-- This grammar is not officially supported, but the parser allows it.
178+
CREATEINDEXbtree_tall_idx2ON btree_tall_tbl (id);
179+
ALTERINDEX btree_tall_idx2 ALTER COLUMN idSET (n_distinct=100);
180+
DROPINDEX btree_tall_idx2;
181+
-- Partitioned index
182+
CREATETABLEbtree_part (id int4) PARTITION BY RANGE (id);
183+
CREATEINDEXbtree_part_idxON btree_part(id);
184+
ALTERINDEX btree_part_idx ALTER COLUMN idSET (n_distinct=100);
185+
DROPTABLE btree_part;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp