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

Commitd26d4c7

Browse files
committed
Disallow CREATE STATISTICS on system catalogs
Add a check that CREATE STATISTICS does not add extended statistics onsystem catalogs, similarly to indexes etc. It can be overriden usingthe allow_system_table_mods GUC.This bug exists since7b504eb, adding the extended statistics, sobackpatch all the way back to PostgreSQL 10.Author: Tomas VondraReported-by: Dean RasheedBackpatch-through: 10Discussion:https://postgr.es/m/CAEZATCXAPrrOKwEsyZKQ4uzzJQWBCt6QAvOcgqRGdWwT1zb%2BrQ%40mail.gmail.com
1 parentf44ae4d commitd26d4c7

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

‎src/backend/commands/statscmds.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ CreateStatistics(CreateStatsStmt *stmt)
135135
if (!pg_class_ownercheck(RelationGetRelid(rel),stxowner))
136136
aclcheck_error(ACLCHECK_NOT_OWNER,get_relkind_objtype(rel->rd_rel->relkind),
137137
RelationGetRelationName(rel));
138+
139+
/* Creating statistics on system catalogs is not allowed */
140+
if (!allowSystemTableMods&&IsSystemRelation(rel))
141+
ereport(ERROR,
142+
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
143+
errmsg("permission denied: \"%s\" is a system catalog",
144+
RelationGetRelationName(rel))));
138145
}
139146

140147
Assert(rel);

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ begin
2525
end;
2626
$$;
2727
-- Verify failures
28+
CREATE TABLE ext_stats_test (x int, y int, z int);
2829
CREATE STATISTICS tst;
2930
ERROR: syntax error at or near ";"
3031
LINE 1: CREATE STATISTICS tst;
@@ -39,16 +40,17 @@ LINE 1: CREATE STATISTICS tst FROM sometab;
3940
^
4041
CREATE STATISTICS tst ON a, b FROM nonexistent;
4142
ERROR: relation "nonexistent" does not exist
42-
CREATE STATISTICS tst ON a, b FROMpg_class;
43+
CREATE STATISTICS tst ON a, b FROMext_stats_test;
4344
ERROR: column "a" does not exist
44-
CREATE STATISTICS tst ONrelname, relname, relnatts FROMpg_class;
45+
CREATE STATISTICS tst ONx, x, y FROMext_stats_test;
4546
ERROR: duplicate column name in statistics definition
46-
CREATE STATISTICS tst ONrelnatts +relpages FROMpg_class;
47+
CREATE STATISTICS tst ONx +y FROMext_stats_test;
4748
ERROR: only simple column references are allowed in CREATE STATISTICS
48-
CREATE STATISTICS tst ON (relpages, reltuples) FROMpg_class;
49+
CREATE STATISTICS tst ON (x, y) FROMext_stats_test;
4950
ERROR: only simple column references are allowed in CREATE STATISTICS
50-
CREATE STATISTICS tst (unrecognized) ONrelname, relnatts FROMpg_class;
51+
CREATE STATISTICS tst (unrecognized) ONx, y FROMext_stats_test;
5152
ERROR: unrecognized statistics kind "unrecognized"
53+
DROP TABLE ext_stats_test;
5254
-- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it
5355
CREATE TABLE ab1 (a INTEGER, b INTEGER, c INTEGER);
5456
CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;

‎src/test/regress/sql/stats_ext.sql

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ end;
2828
$$;
2929

3030
-- Verify failures
31+
CREATETABLEext_stats_test (xint, yint, zint);
3132
CREATE STATISTICS tst;
3233
CREATE STATISTICS tstON a, b;
3334
CREATE STATISTICS tstFROM sometab;
3435
CREATE STATISTICS tstON a, bFROM nonexistent;
35-
CREATE STATISTICS tstON a, bFROM pg_class;
36-
CREATE STATISTICS tstON relname, relname, relnattsFROM pg_class;
37-
CREATE STATISTICS tstON relnatts+ relpagesFROM pg_class;
38-
CREATE STATISTICS tstON (relpages, reltuples)FROM pg_class;
39-
CREATE STATISTICS tst (unrecognized)ON relname, relnattsFROM pg_class;
36+
CREATE STATISTICS tstON a, bFROM ext_stats_test;
37+
CREATE STATISTICS tstON x, x, yFROM ext_stats_test;
38+
CREATE STATISTICS tstON x+ yFROM ext_stats_test;
39+
CREATE STATISTICS tstON (x, y)FROM ext_stats_test;
40+
CREATE STATISTICS tst (unrecognized)ON x, yFROM ext_stats_test;
41+
DROPTABLE ext_stats_test;
4042

4143
-- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it
4244
CREATETABLEab1 (aINTEGER, bINTEGER, cINTEGER);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp