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

Commitd68e08d

Browse files
committed
Allow the index name to be omitted in CREATE INDEX, causing the system to
choose an index name the same as it would do for an unnamed index constraint.(My recent changes to the index naming logic have helped to ensure that thiswill be a reasonable choice.) Per a suggestion from Peter.A necessary side-effect is to promote CONCURRENTLY to type_func_name_keywordstatus, ie, it can't be a table/column/index name anymore unless quoted.This is not all bad, since we have heard more than once of people typingCREATE INDEX CONCURRENTLY ON foo (...) and getting a normal index build ofan index named "concurrently", which was not what they wanted. Now thissyntax will result in a concurrent build of an index with system-chosenname; which they can rename afterwards if they want something else.
1 parentc176e12 commitd68e08d

File tree

6 files changed

+38
-40
lines changed

6 files changed

+38
-40
lines changed

‎doc/src/sgml/keywords.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/keywords.sgml,v 2.27 2009/11/05 23:24:22 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/keywords.sgml,v 2.28 2009/12/23 17:41:43 tgl Exp $ -->
22

33
<appendix id="sql-keywords-appendix">
44
<title><acronym>SQL</acronym> Key Words</title>
@@ -921,7 +921,7 @@
921921
</row>
922922
<row>
923923
<entry><token>CONCURRENTLY</token></entry>
924-
<entry>non-reserved</entry>
924+
<entry>reserved (can be function or type)</entry>
925925
<entry></entry>
926926
<entry></entry>
927927
<entry></entry>

‎doc/src/sgml/ref/create_index.sgml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_index.sgml,v 1.71 2009/03/24 20:17:08 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_index.sgml,v 1.72 2009/12/2317:41:43 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -21,7 +21,7 @@ PostgreSQL documentation
2121

2222
<refsynopsisdiv>
2323
<synopsis>
24-
CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] <replaceable class="parameter">name</replaceable> ON <replaceable class="parameter">table</replaceable> [ USING <replaceable class="parameter">method</replaceable> ]
24+
CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ][<replaceable class="parameter">name</replaceable> ] ON <replaceable class="parameter">table</replaceable> [ USING <replaceable class="parameter">method</replaceable> ]
2525
( { <replaceable class="parameter">column</replaceable> | ( <replaceable class="parameter">expression</replaceable> ) } [ <replaceable class="parameter">opclass</replaceable> ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [, ...] )
2626
[ WITH ( <replaceable class="PARAMETER">storage_parameter</replaceable> = <replaceable class="PARAMETER">value</replaceable> [, ... ] ) ]
2727
[ TABLESPACE <replaceable class="parameter">tablespace</replaceable> ]
@@ -33,8 +33,8 @@ CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] <replaceable class="parameter">name</re
3333
<title>Description</title>
3434

3535
<para>
36-
<command>CREATE INDEX</command> constructs an index named <replaceable
37-
class="parameter">name</replaceable> on the specified table.
36+
<command>CREATE INDEX</command> constructs an index
37+
on the specified column(s) of the specified table.
3838
Indexes are primarily used to enhance database performance (though
3939
inappropriate use can result in slower performance).
4040
</para>
@@ -132,7 +132,9 @@ CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] <replaceable class="parameter">name</re
132132
<para>
133133
The name of the index to be created. No schema name can be included
134134
here; the index is always created in the same schema as its parent
135-
table.
135+
table. If the name is omitted, <productname>PostgreSQL</> chooses a
136+
suitable name based on the parent table's name and the indexed column
137+
name(s).
136138
</para>
137139
</listitem>
138140
</varlistentry>
@@ -514,8 +516,10 @@ CREATE UNIQUE INDEX title_idx ON films (title);
514516
To create an index on the expression <literal>lower(title)</>,
515517
allowing efficient case-insensitive searches:
516518
<programlisting>
517-
CREATE INDEXlower_title_idxON films ((lower(title)));
519+
CREATE INDEX ON films ((lower(title)));
518520
</programlisting>
521+
(In this example we have chosen to omit the index name, so the system
522+
will choose a name, typically <literal>films_lower_idx</>.)
519523
</para>
520524

521525
<para>
@@ -544,7 +548,7 @@ CREATE INDEX gin_idx ON documents_table (locations) WITH (fastupdate = off);
544548
<literal>films</> and have the index reside in the tablespace
545549
<literal>indexspace</>:
546550
<programlisting>
547-
CREATE INDEX code_idx ON films(code) TABLESPACE indexspace;
551+
CREATE INDEX code_idx ON films(code) TABLESPACE indexspace;
548552
</programlisting>
549553
</para>
550554

‎src/backend/parser/gram.y

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.698 2009/12/2302:35:22 tgl Exp $
14+
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.699 2009/12/2317:41:43 tgl Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -253,7 +253,8 @@ static TypeName *TableFuncTypeName(List *columns);
253253

254254
%type<str>copy_file_name
255255
database_nameaccess_method_clauseaccess_methodattr_name
256-
index_namenamecursor_namefile_namecluster_index_specification
256+
namecursor_namefile_name
257+
index_nameopt_index_namecluster_index_specification
257258

258259
%type<list>func_namehandler_namequal_Opqual_all_Opsubquery_Op
259260
opt_classopt_inline_handleropt_validatorvalidator_clause
@@ -325,7 +326,7 @@ static TypeName *TableFuncTypeName(List *columns);
325326
%type<node>overlay_placingsubstr_fromsubstr_for
326327

327328
%type<boolean>opt_instead
328-
%type<boolean>index_opt_uniqueopt_verboseopt_full
329+
%type<boolean>opt_uniqueopt_concurrentlyopt_verboseopt_full
329330
%type<boolean>opt_freezeopt_defaultopt_recheck
330331
%type<defelt>opt_binaryopt_oidscopy_delimiter
331332

@@ -4822,36 +4823,17 @@ defacl_privilege_target:
48224823
*
48234824
*QUERY: CREATE INDEX
48244825
*
4825-
* Note: we can't factor CONCURRENTLY into a separate production without
4826-
* making it a reserved word.
4827-
*
48284826
* Note: we cannot put TABLESPACE clause after WHERE clause unless we are
48294827
* willing to make TABLESPACE a fully reserved word.
48304828
*****************************************************************************/
48314829

4832-
IndexStmt:CREATE index_opt_unique INDEX index_name
4833-
ON qualified_name access_method_clause'(' index_params')'
4834-
opt_reloptions OptTableSpace where_clause
4835-
{
4836-
IndexStmt *n = makeNode(IndexStmt);
4837-
n->unique =$2;
4838-
n->concurrent =false;
4839-
n->idxname =$4;
4840-
n->relation =$6;
4841-
n->accessMethod =$7;
4842-
n->indexParams =$9;
4843-
n->options =$11;
4844-
n->tableSpace =$12;
4845-
n->whereClause =$13;
4846-
$$ = (Node *)n;
4847-
}
4848-
| CREATE index_opt_unique INDEX CONCURRENTLY index_name
4830+
IndexStmt:CREATE opt_unique INDEX opt_concurrently opt_index_name
48494831
ON qualified_name access_method_clause'(' index_params')'
48504832
opt_reloptions OptTableSpace where_clause
48514833
{
48524834
IndexStmt *n = makeNode(IndexStmt);
48534835
n->unique =$2;
4854-
n->concurrent =true;
4836+
n->concurrent =$4;
48554837
n->idxname =$5;
48564838
n->relation =$7;
48574839
n->accessMethod =$8;
@@ -4863,11 +4845,21 @@ IndexStmt:CREATE index_opt_unique INDEX index_name
48634845
}
48644846
;
48654847

4866-
index_opt_unique:
4848+
opt_unique:
48674849
UNIQUE{$$ =TRUE; }
48684850
|/*EMPTY*/{$$ =FALSE; }
48694851
;
48704852

4853+
opt_concurrently:
4854+
CONCURRENTLY{$$ =TRUE; }
4855+
|/*EMPTY*/{$$ =FALSE; }
4856+
;
4857+
4858+
opt_index_name:
4859+
index_name{$$ =$1; }
4860+
|/*EMPTY*/{$$ =NULL; }
4861+
;
4862+
48714863
access_method_clause:
48724864
USING access_method{$$ =$2; }
48734865
|/*EMPTY*/{$$ = DEFAULT_INDEX_TYPE; }
@@ -10696,7 +10688,6 @@ unreserved_keyword:
1069610688
| COMMENTS
1069710689
| COMMIT
1069810690
| COMMITTED
10699-
| CONCURRENTLY
1070010691
| CONFIGURATION
1070110692
| CONNECTION
1070210693
| CONSTRAINTS
@@ -10988,6 +10979,7 @@ type_func_name_keyword:
1098810979
AUTHORIZATION
1098910980
| BETWEEN
1099010981
| BINARY
10982+
| CONCURRENTLY
1099110983
| CROSS
1099210984
| CURRENT_SCHEMA
1099310985
| FREEZE

‎src/include/parser/kwlist.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/include/parser/kwlist.h,v 1.7 2009/12/07 05:22:23 tgl Exp $
14+
* $PostgreSQL: pgsql/src/include/parser/kwlist.h,v 1.8 2009/12/23 17:41:44 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -83,7 +83,7 @@ PG_KEYWORD("comment", COMMENT, UNRESERVED_KEYWORD)
8383
PG_KEYWORD("comments",COMMENTS,UNRESERVED_KEYWORD)
8484
PG_KEYWORD("commit",COMMIT,UNRESERVED_KEYWORD)
8585
PG_KEYWORD("committed",COMMITTED,UNRESERVED_KEYWORD)
86-
PG_KEYWORD("concurrently",CONCURRENTLY,UNRESERVED_KEYWORD)
86+
PG_KEYWORD("concurrently",CONCURRENTLY,TYPE_FUNC_NAME_KEYWORD)
8787
PG_KEYWORD("configuration",CONFIGURATION,UNRESERVED_KEYWORD)
8888
PG_KEYWORD("connection",CONNECTION,UNRESERVED_KEYWORD)
8989
PG_KEYWORD("constraint",CONSTRAINT,RESERVED_KEYWORD)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,8 @@ DETAIL: Key (f2)=(b) is duplicated.
689689
-- test that expression indexes and partial indexes work concurrently
690690
CREATE INDEX CONCURRENTLY concur_index4 on concur_heap(f2) WHERE f1='a';
691691
CREATE INDEX CONCURRENTLY concur_index5 on concur_heap(f2) WHERE f1='x';
692-
CREATE INDEX CONCURRENTLY concur_index6 on concur_heap((f2||f1));
692+
-- here we also check that you can default the index name
693+
CREATE INDEX CONCURRENTLY on concur_heap((f2||f1));
693694
-- You can't do a concurrent index build in a transaction
694695
BEGIN;
695696
CREATE INDEX CONCURRENTLY concur_index7 ON concur_heap(f1);
@@ -711,10 +712,10 @@ Table "public.concur_heap"
711712
Indexes:
712713
"concur_index2" UNIQUE, btree (f1)
713714
"concur_index3" UNIQUE, btree (f2) INVALID
715+
"concur_heap_expr_idx" btree ((f2 || f1))
714716
"concur_index1" btree (f2, f1)
715717
"concur_index4" btree (f2) WHERE f1 = 'a'::text
716718
"concur_index5" btree (f2) WHERE f1 = 'x'::text
717-
"concur_index6" btree ((f2 || f1))
718719
"std_index" btree (f2)
719720

720721
DROP TABLE concur_heap;

‎src/test/regress/sql/create_index.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ CREATE UNIQUE INDEX CONCURRENTLY concur_index3 ON concur_heap(f2);
300300
-- test that expression indexes and partial indexes work concurrently
301301
CREATEINDEXCONCURRENTLY concur_index4on concur_heap(f2)WHERE f1='a';
302302
CREATEINDEXCONCURRENTLY concur_index5on concur_heap(f2)WHERE f1='x';
303-
CREATEINDEXCONCURRENTLY concur_index6on concur_heap((f2||f1));
303+
-- here we also check that you can default the index name
304+
CREATEINDEXCONCURRENTLYon concur_heap((f2||f1));
304305

305306
-- You can't do a concurrent index build in a transaction
306307
BEGIN;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp