mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-23 12:10:41 +02:00
Fix ALTER TABLE...SET STATS error message for included columns
The existing error message was complaining that the column is not an expression, which is not correct. Introduce a suitable wording variation and a test. Co-authored-by: Yugo Nagata <nagata@sraoss.co.jp> Discussion: https://postgr.es/m/20180628182803.e4632d5a.nagata@sraoss.co.jp Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org>
This commit is contained in:
parent
fb2b61a21e
commit
802b04cb3f
@ -6504,14 +6504,21 @@ ATExecSetStatistics(Relation rel, const char *colName, int16 colNum, Node *newVa
|
|||||||
errmsg("cannot alter system column \"%s\"",
|
errmsg("cannot alter system column \"%s\"",
|
||||||
colName)));
|
colName)));
|
||||||
|
|
||||||
if ((rel->rd_rel->relkind == RELKIND_INDEX ||
|
if (rel->rd_rel->relkind == RELKIND_INDEX ||
|
||||||
rel->rd_rel->relkind == RELKIND_PARTITIONED_INDEX) &&
|
rel->rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
|
||||||
rel->rd_index->indkey.values[attnum - 1] != 0)
|
{
|
||||||
ereport(ERROR,
|
if (attnum > rel->rd_index->indnkeyatts)
|
||||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
ereport(ERROR,
|
||||||
errmsg("cannot alter statistics on non-expression column \"%s\" of index \"%s\"",
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
NameStr(attrtuple->attname), RelationGetRelationName(rel)),
|
errmsg("cannot alter statistics on included column \"%s\" of index \"%s\"",
|
||||||
errhint("Alter statistics on table column instead.")));
|
NameStr(attrtuple->attname), RelationGetRelationName(rel))));
|
||||||
|
else if (rel->rd_index->indkey.values[attnum - 1] != 0)
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
|
errmsg("cannot alter statistics on non-expression column \"%s\" of index \"%s\"",
|
||||||
|
NameStr(attrtuple->attname), RelationGetRelationName(rel)),
|
||||||
|
errhint("Alter statistics on table column instead.")));
|
||||||
|
}
|
||||||
|
|
||||||
attrtuple->attstattarget = newtarget;
|
attrtuple->attstattarget = newtarget;
|
||||||
|
|
||||||
|
@ -243,6 +243,20 @@ SELECT indexdef FROM pg_indexes WHERE tablename = 'tbl' ORDER BY indexname;
|
|||||||
----------
|
----------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
|
DROP TABLE tbl;
|
||||||
|
/*
|
||||||
|
* 3.3 Test ALTER TABLE SET STATISTICS
|
||||||
|
*/
|
||||||
|
CREATE TABLE tbl (c1 int, c2 int);
|
||||||
|
CREATE INDEX tbl_idx ON tbl (c1, (c1+0)) INCLUDE (c2);
|
||||||
|
ALTER INDEX tbl_idx ALTER COLUMN 1 SET STATISTICS 1000;
|
||||||
|
ERROR: cannot alter statistics on non-expression column "c1" of index "tbl_idx"
|
||||||
|
HINT: Alter statistics on table column instead.
|
||||||
|
ALTER INDEX tbl_idx ALTER COLUMN 2 SET STATISTICS 1000;
|
||||||
|
ALTER INDEX tbl_idx ALTER COLUMN 3 SET STATISTICS 1000;
|
||||||
|
ERROR: cannot alter statistics on included column "c2" of index "tbl_idx"
|
||||||
|
ALTER INDEX tbl_idx ALTER COLUMN 4 SET STATISTICS 1000;
|
||||||
|
ERROR: column number 4 of relation "tbl_idx" does not exist
|
||||||
DROP TABLE tbl;
|
DROP TABLE tbl;
|
||||||
/*
|
/*
|
||||||
* 4. CREATE INDEX CONCURRENTLY
|
* 4. CREATE INDEX CONCURRENTLY
|
||||||
|
@ -137,6 +137,16 @@ ALTER TABLE tbl DROP COLUMN c1;
|
|||||||
SELECT indexdef FROM pg_indexes WHERE tablename = 'tbl' ORDER BY indexname;
|
SELECT indexdef FROM pg_indexes WHERE tablename = 'tbl' ORDER BY indexname;
|
||||||
DROP TABLE tbl;
|
DROP TABLE tbl;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 3.3 Test ALTER TABLE SET STATISTICS
|
||||||
|
*/
|
||||||
|
CREATE TABLE tbl (c1 int, c2 int);
|
||||||
|
CREATE INDEX tbl_idx ON tbl (c1, (c1+0)) INCLUDE (c2);
|
||||||
|
ALTER INDEX tbl_idx ALTER COLUMN 1 SET STATISTICS 1000;
|
||||||
|
ALTER INDEX tbl_idx ALTER COLUMN 2 SET STATISTICS 1000;
|
||||||
|
ALTER INDEX tbl_idx ALTER COLUMN 3 SET STATISTICS 1000;
|
||||||
|
ALTER INDEX tbl_idx ALTER COLUMN 4 SET STATISTICS 1000;
|
||||||
|
DROP TABLE tbl;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 4. CREATE INDEX CONCURRENTLY
|
* 4. CREATE INDEX CONCURRENTLY
|
||||||
|
Loading…
Reference in New Issue
Block a user