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

Commite55c8e3

Browse files
committed
Support syntax "CLUSTER table USING index", which is more logical.
Holger Schurig
1 parentd7e2de6 commite55c8e3

File tree

5 files changed

+52
-42
lines changed

5 files changed

+52
-42
lines changed

‎doc/src/sgml/ref/cluster.sgml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/cluster.sgml,v 1.40 2007/02/01 00:28:18 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/cluster.sgml,v 1.41 2007/04/08 00:26:33 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -20,8 +20,7 @@ PostgreSQL documentation
2020

2121
<refsynopsisdiv>
2222
<synopsis>
23-
CLUSTER <replaceable class="PARAMETER">indexname</replaceable> ON <replaceable class="PARAMETER">tablename</replaceable>
24-
CLUSTER <replaceable class="PARAMETER">tablename</replaceable>
23+
CLUSTER <replaceable class="PARAMETER">tablename</replaceable> [ USING <replaceable class="PARAMETER">indexname</replaceable> ]
2524
CLUSTER
2625
</synopsis>
2726
</refsynopsisdiv>
@@ -77,19 +76,19 @@ CLUSTER
7776

7877
<variablelist>
7978
<varlistentry>
80-
<term><replaceable class="PARAMETER">indexname</replaceable></term>
79+
<term><replaceable class="PARAMETER">tablename</replaceable></term>
8180
<listitem>
8281
<para>
83-
The name ofan index.
82+
The name(possibly schema-qualified)ofa table.
8483
</para>
8584
</listitem>
8685
</varlistentry>
8786

8887
<varlistentry>
89-
<term><replaceable class="PARAMETER">tablename</replaceable></term>
88+
<term><replaceable class="PARAMETER">indexname</replaceable></term>
9089
<listitem>
9190
<para>
92-
The name(possibly schema-qualified)ofa table.
91+
The name ofan index.
9392
</para>
9493
</listitem>
9594
</varlistentry>
@@ -172,17 +171,17 @@ CREATE TABLE <replaceable class="parameter">newtable</replaceable> AS
172171

173172
<para>
174173
Cluster the table <literal>employees</literal> on the basis of
175-
its index <literal>emp_ind</literal>:
174+
its index <literal>employees_ind</literal>:
176175
<programlisting>
177-
CLUSTERemp_ind ON emp;
176+
CLUSTERemployees USING employees_ind;
178177
</programlisting>
179178
</para>
180179

181180
<para>
182181
Cluster the <literal>employees</literal> table using the same
183182
index that was used before:
184183
<programlisting>
185-
CLUSTERemp;
184+
CLUSTERemployees;
186185
</programlisting>
187186
</para>
188187

@@ -198,7 +197,12 @@ CLUSTER;
198197
<title>Compatibility</title>
199198

200199
<para>
201-
There is no <command>CLUSTER</command> statement in the SQL standard.
200+
The syntax:
201+
<synopsis>
202+
CLUSTER <replaceable class="PARAMETER">indexname</replaceable> ON <replaceable class="PARAMETER">tablename</replaceable>
203+
</synopsis>
204+
is also supported for compatibility with pre-8.3 <productname>PostgreSQL</> installations.
205+
There is no <command>CLUSTER</command> statement in the SQL standard.
202206
</para>
203207
</refsect1>
204208

‎src/backend/parser/gram.y

Lines changed: 24 additions & 17 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.586 2007/04/02 22:20:53 momjian Exp $
14+
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.587 2007/04/08 00:26:34 momjian Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -209,7 +209,7 @@ static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args)
209209

210210
%type<str>relation_namecopy_file_name
211211
database_nameaccess_method_clauseaccess_methodattr_name
212-
index_namenamefile_name
212+
index_namenamefile_namecluster_index_specification
213213

214214
%type<list>func_namehandler_namequal_Opqual_all_Opsubquery_Op
215215
opt_classopt_validator
@@ -5084,7 +5084,7 @@ opt_check_option:
50845084
/*****************************************************************************
50855085
*
50865086
*QUERY:
5087-
*load "filename"
5087+
*LOAD "filename"
50885088
*
50895089
*****************************************************************************/
50905090

@@ -5346,25 +5346,18 @@ CreateConversionStmt:
53465346
/*****************************************************************************
53475347
*
53485348
*QUERY:
5349-
*cluster <index_name> on <qualified_name>
5350-
*cluster <qualified_name>
5351-
*cluster
5349+
*CLUSTER <qualified_name> [ USING <index_name> ]
5350+
*CLUSTER
5351+
*CLUSTER <index_name> ON <qualified_name> (for pre-8.3)
53525352
*
53535353
*****************************************************************************/
53545354

53555355
ClusterStmt:
5356-
CLUSTER index_name ON qualified_name
5357-
{
5358-
ClusterStmt *n = makeNode(ClusterStmt);
5359-
n->relation =$4;
5360-
n->indexname =$2;
5361-
$$ = (Node*)n;
5362-
}
5363-
| CLUSTER qualified_name
5356+
CLUSTER qualified_name cluster_index_specification
53645357
{
53655358
ClusterStmt *n = makeNode(ClusterStmt);
53665359
n->relation =$2;
5367-
n->indexname =NULL;
5360+
n->indexname =$3;
53685361
$$ = (Node*)n;
53695362
}
53705363
| CLUSTER
@@ -5374,13 +5367,27 @@ ClusterStmt:
53745367
n->indexname =NULL;
53755368
$$ = (Node*)n;
53765369
}
5370+
/* kept for pre-8.3 compatibility*/
5371+
| CLUSTER index_name ON qualified_name
5372+
{
5373+
ClusterStmt *n = makeNode(ClusterStmt);
5374+
n->relation =$4;
5375+
n->indexname =$2;
5376+
$$ = (Node*)n;
5377+
}
5378+
;
5379+
5380+
cluster_index_specification:
5381+
USING index_name{$$ =$2; }
5382+
|/*EMPTY*/{$$ =NULL; }
53775383
;
53785384

5385+
53795386
/*****************************************************************************
53805387
*
53815388
*QUERY:
5382-
*vacuum
5383-
*analyze
5389+
*VACUUM
5390+
*ANALYZE
53845391
*
53855392
*****************************************************************************/
53865393

‎src/bin/psql/tab-complete.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2007, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.160 2007/03/26 16:58:40 tgl Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.161 2007/04/08 00:26:34 momjian Exp $
77
*/
88

99
/*----------------------------------------------------------------------
@@ -822,11 +822,9 @@ psql_completion(char *text, int start, int end)
822822

823823
COMPLETE_WITH_LIST(list_COLUMNALTER);
824824
}
825-
elseif (pg_strcasecmp(prev3_wd,"TABLE")==0&&
826-
pg_strcasecmp(prev_wd,"CLUSTER")==0)
825+
elseif (pg_strcasecmp(prev3_wd,"TABLE")==0)
827826
COMPLETE_WITH_CONST("ON");
828827
elseif (pg_strcasecmp(prev4_wd,"TABLE")==0&&
829-
pg_strcasecmp(prev2_wd,"CLUSTER")==0&&
830828
pg_strcasecmp(prev_wd,"ON")==0)
831829
{
832830
completion_info_charp=prev3_wd;
@@ -929,24 +927,25 @@ psql_completion(char *text, int start, int end)
929927

930928
/*
931929
* If the previous word is CLUSTER and not without produce list of
932-
*indexes.
930+
*tables
933931
*/
934932
elseif (pg_strcasecmp(prev_wd,"CLUSTER")==0&&
935933
pg_strcasecmp(prev2_wd,"WITHOUT")!=0)
936-
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes,NULL);
937-
/* If we have CLUSTER <sth>, then add "ON" */
934+
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables,NULL);
935+
/* If we have CLUSTER <sth>, then add "USING" */
938936
elseif (pg_strcasecmp(prev2_wd,"CLUSTER")==0&&
939-
pg_strcasecmp(prev_wd,"ON")!=0)
940-
COMPLETE_WITH_CONST("ON");
937+
pg_strcasecmp(prev_wd,"ON")!=0) {
938+
COMPLETE_WITH_CONST("USING");
939+
}
941940

942941
/*
943-
* If we have CLUSTER <sth>ON, then add thecorrect tablename as well.
942+
* If we have CLUSTER <sth>ORDER BY, then add theindex as well.
944943
*/
945944
elseif (pg_strcasecmp(prev3_wd,"CLUSTER")==0&&
946-
pg_strcasecmp(prev_wd,"ON")==0)
945+
pg_strcasecmp(prev_wd,"USING")==0)
947946
{
948947
completion_info_charp=prev2_wd;
949-
COMPLETE_WITH_QUERY(Query_for_table_owning_index);
948+
COMPLETE_WITH_QUERY(Query_for_index_of_table);
950949
}
951950

952951
/* COMMENT */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ INSERT INTO clstr_3 VALUES (1);
329329
CLUSTER clstr_2;
330330
ERROR: there is no previously clustered index for table "clstr_2"
331331
CLUSTER clstr_1_pkey ON clstr_1;
332-
CLUSTERclstr_2_pkey ON clstr_2;
332+
CLUSTERclstr_2 USING clstr_2_pkey;
333333
SELECT * FROM clstr_1 UNION ALL
334334
SELECT * FROM clstr_2 UNION ALL
335335
SELECT * FROM clstr_3;

‎src/test/regress/sql/cluster.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ INSERT INTO clstr_3 VALUES (1);
122122
CLUSTER clstr_2;
123123

124124
CLUSTER clstr_1_pkeyON clstr_1;
125-
CLUSTERclstr_2_pkeyON clstr_2;
125+
CLUSTERclstr_2 USING clstr_2_pkey;
126126
SELECT*FROM clstr_1UNION ALL
127127
SELECT*FROM clstr_2UNION ALL
128128
SELECT*FROM clstr_3;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp