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

Commit943a113

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 parentf5d044e commit943a113

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
@@ -132,6 +132,13 @@ CreateStatistics(CreateStatsStmt *stmt)
132132
if (!pg_class_ownercheck(RelationGetRelid(rel),stxowner))
133133
aclcheck_error(ACLCHECK_NOT_OWNER,get_relkind_objtype(rel->rd_rel->relkind),
134134
RelationGetRelationName(rel));
135+
136+
/* Creating statistics on system catalogs is not allowed */
137+
if (!allowSystemTableMods&&IsSystemRelation(rel))
138+
ereport(ERROR,
139+
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
140+
errmsg("permission denied: \"%s\" is a system catalog",
141+
RelationGetRelationName(rel))));
135142
}
136143

137144
Assert(rel);

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ begin
2323
end;
2424
$$;
2525
-- Verify failures
26+
CREATE TABLE ext_stats_test (x int, y int, z int);
2627
CREATE STATISTICS tst;
2728
ERROR: syntax error at or near ";"
2829
LINE 1: CREATE STATISTICS tst;
@@ -37,16 +38,17 @@ LINE 1: CREATE STATISTICS tst FROM sometab;
3738
^
3839
CREATE STATISTICS tst ON a, b FROM nonexistent;
3940
ERROR: relation "nonexistent" does not exist
40-
CREATE STATISTICS tst ON a, b FROMpg_class;
41+
CREATE STATISTICS tst ON a, b FROMext_stats_test;
4142
ERROR: column "a" does not exist
42-
CREATE STATISTICS tst ONrelname, relname, relnatts FROMpg_class;
43+
CREATE STATISTICS tst ONx, x, y FROMext_stats_test;
4344
ERROR: duplicate column name in statistics definition
44-
CREATE STATISTICS tst ONrelnatts +relpages FROMpg_class;
45+
CREATE STATISTICS tst ONx +y FROMext_stats_test;
4546
ERROR: only simple column references are allowed in CREATE STATISTICS
46-
CREATE STATISTICS tst ON (relpages, reltuples) FROMpg_class;
47+
CREATE STATISTICS tst ON (x, y) FROMext_stats_test;
4748
ERROR: only simple column references are allowed in CREATE STATISTICS
48-
CREATE STATISTICS tst (unrecognized) ONrelname, relnatts FROMpg_class;
49+
CREATE STATISTICS tst (unrecognized) ONx, y FROMext_stats_test;
4950
ERROR: unrecognized statistics kind "unrecognized"
51+
DROP TABLE ext_stats_test;
5052
-- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it
5153
CREATE TABLE ab1 (a INTEGER, b INTEGER, c INTEGER);
5254
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
@@ -26,15 +26,17 @@ end;
2626
$$;
2727

2828
-- Verify failures
29+
CREATETABLEext_stats_test (xint, yint, zint);
2930
CREATE STATISTICS tst;
3031
CREATE STATISTICS tstON a, b;
3132
CREATE STATISTICS tstFROM sometab;
3233
CREATE STATISTICS tstON a, bFROM nonexistent;
33-
CREATE STATISTICS tstON a, bFROM pg_class;
34-
CREATE STATISTICS tstON relname, relname, relnattsFROM pg_class;
35-
CREATE STATISTICS tstON relnatts+ relpagesFROM pg_class;
36-
CREATE STATISTICS tstON (relpages, reltuples)FROM pg_class;
37-
CREATE STATISTICS tst (unrecognized)ON relname, relnattsFROM pg_class;
34+
CREATE STATISTICS tstON a, bFROM ext_stats_test;
35+
CREATE STATISTICS tstON x, x, yFROM ext_stats_test;
36+
CREATE STATISTICS tstON x+ yFROM ext_stats_test;
37+
CREATE STATISTICS tstON (x, y)FROM ext_stats_test;
38+
CREATE STATISTICS tst (unrecognized)ON x, yFROM ext_stats_test;
39+
DROPTABLE ext_stats_test;
3840

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp