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

Commit5dfd564

Browse files
committed
Fix IF NOT EXISTS in CREATE STATISTICS
I misplaced the IF NOT EXISTS clause in commit7b504eb, before theword STATISTICS. Put it where it belongs.Patch written independently by Amit Langote and myself. I adopted hissubmitted test case with a slight edit also.Reported-by: Bruno Wolff IIIDiscussion:https://postgr.es/m/20170621004237.GB8337@wolff.to
1 parent2c77903 commit5dfd564

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

‎src/backend/parser/gram.y

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff 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

38483848
CreateStatsStmt:
3849-
CREATEopt_if_not_existsSTATISTICSany_name
3849+
CREATESTATISTICSany_name
38503850
opt_name_listONexpr_listFROMfrom_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+
|CREATESTATISTICSIF_PNOTEXISTSany_name
3861+
opt_name_listONexpr_listFROMfrom_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
;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ CREATE STATISTICS tst ON (relpages, reltuples) FROM pg_class;
3030
ERROR: only simple column references are allowed in CREATE STATISTICS
3131
CREATE STATISTICS tst (unrecognized) ON relname, relnatts FROM pg_class;
3232
ERROR: unrecognized statistic type "unrecognized"
33-
-- Ensure stats are dropped sanely
33+
-- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it
3434
CREATE 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
3638
DROP STATISTICS ab1_a_b_stats;
3739
CREATE SCHEMA regress_schema_2;
3840
CREATE STATISTICS regress_schema_2.ab1_a_b_stats ON a, b FROM ab1;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ CREATE STATISTICS tst ON relnatts + relpages FROM pg_class;
1818
CREATE STATISTICS tstON (relpages, reltuples)FROM pg_class;
1919
CREATE STATISTICS tst (unrecognized)ON relname, relnattsFROM pg_class;
2020

21-
-- Ensure stats are dropped sanely
21+
-- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it
2222
CREATETABLEab1 (aINTEGER, bINTEGER, cINTEGER);
23-
CREATE STATISTICS ab1_a_b_statsON a, bFROM ab1;
23+
CREATE STATISTICS IF NOT EXISTS ab1_a_b_statsON a, bFROM ab1;
24+
CREATE STATISTICS IF NOT EXISTS ab1_a_b_statsON a, bFROM ab1;
2425
DROP STATISTICS ab1_a_b_stats;
2526

2627
CREATESCHEMAregress_schema_2;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp