File tree Expand file tree Collapse file tree 3 files changed +25
-11
lines changed Expand file tree Collapse file tree 3 files changed +25
-11
lines changed Original file line number Diff line number Diff line change @@ -3834,7 +3834,7 @@ ExistingIndex: USING INDEX index_name { $$ = $3; }
38343834/* ****************************************************************************
38353835 *
38363836 * QUERY :
3837- * CREATE STATISTICS stats_name [(stat types)]
3837+ * CREATE STATISTICS [IF NOT EXISTS] stats_name [(stat types)]
38383838 * ON expression-list FROM from_list
38393839 *
38403840 * Note: the expectation here is that the clauses after ON are a subset of
@@ -3846,15 +3846,26 @@ ExistingIndex: USING INDEX index_name { $$ = $3; }
38463846 *****************************************************************************/
38473847
38483848CreateStatsStmt :
3849- CREATE opt_if_not_exists STATISTICS any_name
3849+ CREATE STATISTICS any_name
38503850 opt_name_list ON expr_list FROM from_list
38513851 {
38523852 CreateStatsStmt *n = makeNode(CreateStatsStmt);
3853- n->defnames = $4 ;
3854- n->stat_types = $5 ;
3855- n->exprs = $7 ;
3856- n->relations = $9 ;
3857- n->if_not_exists = $2 ;
3853+ n->defnames = $3 ;
3854+ n->stat_types = $4 ;
3855+ n->exprs = $6 ;
3856+ n->relations = $8 ;
3857+ n->if_not_exists = false ;
3858+ $$ = (Node *)n;
3859+ }
3860+ | CREATE STATISTICS IF_P NOT EXISTS any_name
3861+ opt_name_list ON expr_list FROM from_list
3862+ {
3863+ CreateStatsStmt *n = makeNode(CreateStatsStmt);
3864+ n->defnames = $6 ;
3865+ n->stat_types = $7 ;
3866+ n->exprs = $9 ;
3867+ n->relations = $11 ;
3868+ n->if_not_exists = true ;
38583869 $$ = (Node *)n;
38593870 }
38603871 ;
Original file line number Diff line number Diff line change @@ -30,9 +30,11 @@ CREATE STATISTICS tst ON (relpages, reltuples) FROM pg_class;
3030ERROR: only simple column references are allowed in CREATE STATISTICS
3131CREATE STATISTICS tst (unrecognized) ON relname, relnatts FROM pg_class;
3232ERROR: unrecognized statistic type "unrecognized"
33- -- Ensure stats are dropped sanely
33+ -- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it
3434CREATE TABLE ab1 (a INTEGER, b INTEGER, c INTEGER);
35- CREATE STATISTICS ab1_a_b_stats ON a, b FROM ab1;
35+ CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
36+ CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
37+ NOTICE: statistics object "ab1_a_b_stats" already exists, skipping
3638DROP STATISTICS ab1_a_b_stats;
3739CREATE SCHEMA regress_schema_2;
3840CREATE STATISTICS regress_schema_2.ab1_a_b_stats ON a, b FROM ab1;
Original file line number Diff line number Diff line change @@ -18,9 +18,10 @@ CREATE STATISTICS tst ON relnatts + relpages FROM pg_class;
1818CREATE STATISTICS tst ON (relpages, reltuples) FROM pg_class;
1919CREATE STATISTICS tst (unrecognized) ON relname, relnatts FROM pg_class;
2020
21- -- Ensure stats are dropped sanely
21+ -- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it
2222CREATE TABLE ab1 (a INTEGER , b INTEGER , c INTEGER );
23- CREATE STATISTICS ab1_a_b_stats ON a, b FROM ab1;
23+ CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
24+ CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
2425DROP STATISTICS ab1_a_b_stats;
2526
2627CREATE SCHEMA regress_schema_2 ;
You can’t perform that action at this time.
0 commit comments