[PATCH] add CLUSTER table USING index (take 3)

Поиск
Список
Период
Сортировка
Искать

[PATCH] add CLUSTER table USING index (take 3)

От:
Holger Schurig <holgerschurig@gmx.de>
Дата:
SGML ref text (swapped parameter list, changed example text)

Also, I noticed that the text of the example spoke about a
table "employees", but the example used the table "emp". I
fixed this inconsistency.


Index: src/doc/src/sgml/ref/cluster.sgml
===================================================================
*** src.orig/doc/src/sgml/ref/cluster.sgml	2007-03-28 23:03:20.000000000 +0200
--- src/doc/src/sgml/ref/cluster.sgml	2007-03-29 21:32:26.000000000 +0200
***************
*** 20,27 ****
  
   
  
! CLUSTER indexname ON tablename
! CLUSTER tablename
  CLUSTER
  
   
--- 20,26 ----
  
   
  
! CLUSTER tablename [ USING indexname ]
  CLUSTER
  
   
***************
*** 77,95 ****
  
    
     
!     indexname
      
       
!       The name of an index.
       
      
     
  
     
!     tablename
      
       
!       The name (possibly schema-qualified) of a table.
       
      
     
--- 76,94 ----
  
    
     
!     tablename
      
       
!       The name (possibly schema-qualified) of a table.
       
      
     
  
     
!     indexname
      
       
!       The name of an index.
       
      
     
***************
*** 172,180 ****
  
    
     Cluster the table employees on the basis of
!    its index emp_ind:
  
! CLUSTER emp_ind ON emp;
  
    
  
--- 171,179 ----
  
    
     Cluster the table employees on the basis of
!    its index employees_ind:
  
! CLUSTER employees USING employees_ind;
  
    
  
***************
*** 182,188 ****
     Cluster the employees table using the same
     index that was used before:
  
! CLUSTER emp;
  
    
  
--- 181,187 ----
     Cluster the employees table using the same
     index that was used before:
  
! CLUSTER employees;
  
    
  
Index: src/src/backend/parser/gram.y
===================================================================
*** src.orig/src/backend/parser/gram.y	2007-03-28 23:03:20.000000000 +0200
--- src/src/backend/parser/gram.y	2007-03-28 23:03:35.000000000 +0200
***************
*** 209,215 ****
  
  %type 		relation_name copy_file_name
  				database_name access_method_clause access_method attr_name
! 				index_name name file_name
  
  %type 	func_name handler_name qual_Op qual_all_Op subquery_Op
  				opt_class opt_validator
--- 209,215 ----
  
  %type 		relation_name copy_file_name
  				database_name access_method_clause access_method attr_name
! 				index_name name file_name opt_cluster_using
  
  %type 	func_name handler_name qual_Op qual_all_Op subquery_Op
  				opt_class opt_validator
***************
*** 5327,5332 ****
--- 5327,5333 ----
   *
   *		QUERY:
   *				cluster  on 
+  *				cluster  USING 
   *				cluster 
   *				cluster
   *
***************
*** 5340,5350 ****
  				   n->indexname = $2;
  				   $$ = (Node*)n;
  				}
! 			| CLUSTER qualified_name
  				{
  			       ClusterStmt *n = makeNode(ClusterStmt);
  				   n->relation = $2;
! 				   n->indexname = NULL;
  				   $$ = (Node*)n;
  				}
  			| CLUSTER
--- 5341,5351 ----
  				   n->indexname = $2;
  				   $$ = (Node*)n;
  				}
! 			| CLUSTER qualified_name opt_cluster_using
  				{
  			       ClusterStmt *n = makeNode(ClusterStmt);
  				   n->relation = $2;
! 				   n->indexname = $3;
  				   $$ = (Node*)n;
  				}
  			| CLUSTER
***************
*** 5356,5361 ****
--- 5357,5368 ----
  				}
  		;
  
+ opt_cluster_using:
+ 			USING index_name			{ $$ = $2; }
+ 			| /*EMPTY*/				{ $$ = NULL; }
+ 		;
+ 
+ 
  /*****************************************************************************
   *
   *		QUERY:
Index: src/src/bin/psql/tab-complete.c
===================================================================
*** src.orig/src/bin/psql/tab-complete.c	2007-03-28 23:03:20.000000000 +0200
--- src/src/bin/psql/tab-complete.c	2007-03-28 23:03:35.000000000 +0200
***************
*** 822,832 ****
  
  		COMPLETE_WITH_LIST(list_COLUMNALTER);
  	}
! 	else if (pg_strcasecmp(prev3_wd, "TABLE") == 0 &&
! 			 pg_strcasecmp(prev_wd, "CLUSTER") == 0)
  		COMPLETE_WITH_CONST("ON");
  	else if (pg_strcasecmp(prev4_wd, "TABLE") == 0 &&
- 			 pg_strcasecmp(prev2_wd, "CLUSTER") == 0 &&
  			 pg_strcasecmp(prev_wd, "ON") == 0)
  	{
  		completion_info_charp = prev3_wd;
--- 822,830 ----
  
  		COMPLETE_WITH_LIST(list_COLUMNALTER);
  	}
! 	else if (pg_strcasecmp(prev3_wd, "TABLE") == 0)
  		COMPLETE_WITH_CONST("ON");
  	else if (pg_strcasecmp(prev4_wd, "TABLE") == 0 &&
  			 pg_strcasecmp(prev_wd, "ON") == 0)
  	{
  		completion_info_charp = prev3_wd;
***************
*** 929,952 ****
  
  	/*
  	 * If the previous word is CLUSTER and not without produce list of
! 	 * indexes.
  	 */
  	else if (pg_strcasecmp(prev_wd, "CLUSTER") == 0 &&
  			 pg_strcasecmp(prev2_wd, "WITHOUT") != 0)
! 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, NULL);
! 	/* If we have CLUSTER , then add "ON" */
  	else if (pg_strcasecmp(prev2_wd, "CLUSTER") == 0 &&
! 			 pg_strcasecmp(prev_wd, "ON") != 0)
! 		COMPLETE_WITH_CONST("ON");
  
  	/*
! 	 * If we have CLUSTER  ON, then add the correct tablename as well.
  	 */
  	else if (pg_strcasecmp(prev3_wd, "CLUSTER") == 0 &&
! 			 pg_strcasecmp(prev_wd, "ON") == 0)
  	{
  		completion_info_charp = prev2_wd;
! 		COMPLETE_WITH_QUERY(Query_for_table_owning_index);
  	}
  
  /* COMMENT */
--- 927,951 ----
  
  	/*
  	 * If the previous word is CLUSTER and not without produce list of
! 	 * tables
  	 */
  	else if (pg_strcasecmp(prev_wd, "CLUSTER") == 0 &&
  			 pg_strcasecmp(prev2_wd, "WITHOUT") != 0)
! 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
! 	/* If we have CLUSTER , then add "USING" */
  	else if (pg_strcasecmp(prev2_wd, "CLUSTER") == 0 &&
! 			 pg_strcasecmp(prev_wd, "ON") != 0) {
! 		COMPLETE_WITH_CONST("USING");
! 	}
  
  	/*
! 	 * If we have CLUSTER  ORDER BY, then add the index as well.
  	 */
  	else if (pg_strcasecmp(prev3_wd, "CLUSTER") == 0 &&
! 			 pg_strcasecmp(prev_wd, "USING") == 0)
  	{
  		completion_info_charp = prev2_wd;
! 		COMPLETE_WITH_QUERY(Query_for_index_of_table);
  	}
  
  /* COMMENT */
Index: src/src/test/regress/expected/cluster.out
===================================================================
*** src.orig/src/test/regress/expected/cluster.out	2007-03-28 23:03:20.000000000 +0200
--- src/src/test/regress/expected/cluster.out	2007-03-28 23:03:35.000000000 +0200
***************
*** 329,335 ****
  CLUSTER clstr_2;
  ERROR:  there is no previously clustered index for table "clstr_2"
  CLUSTER clstr_1_pkey ON clstr_1;
! CLUSTER clstr_2_pkey ON clstr_2;
  SELECT * FROM clstr_1 UNION ALL
    SELECT * FROM clstr_2 UNION ALL
    SELECT * FROM clstr_3;
--- 329,335 ----
  CLUSTER clstr_2;
  ERROR:  there is no previously clustered index for table "clstr_2"
  CLUSTER clstr_1_pkey ON clstr_1;
! CLUSTER clstr_2 USING clstr_2_pkey;
  SELECT * FROM clstr_1 UNION ALL
    SELECT * FROM clstr_2 UNION ALL
    SELECT * FROM clstr_3;
Index: src/src/test/regress/sql/cluster.sql
===================================================================
*** src.orig/src/test/regress/sql/cluster.sql	2007-03-28 23:03:20.000000000 +0200
--- src/src/test/regress/sql/cluster.sql	2007-03-28 23:03:35.000000000 +0200
***************
*** 122,128 ****
  CLUSTER clstr_2;
  
  CLUSTER clstr_1_pkey ON clstr_1;
! CLUSTER clstr_2_pkey ON clstr_2;
  SELECT * FROM clstr_1 UNION ALL
    SELECT * FROM clstr_2 UNION ALL
    SELECT * FROM clstr_3;
--- 122,128 ----
  CLUSTER clstr_2;
  
  CLUSTER clstr_1_pkey ON clstr_1;
! CLUSTER clstr_2 USING clstr_2_pkey;
  SELECT * FROM clstr_1 UNION ALL
    SELECT * FROM clstr_2 UNION ALL
    SELECT * FROM clstr_3;

Re: [PATCH] add CLUSTER table USING index (take 3)

От:
Bruce Momjian <bruce@momjian.us>
Дата:

Your patch has been added to the PostgreSQL unapplied patches list at:

	http://momjian.postgresql.org/cgi-bin/pgpatches

It will be applied as soon as one of the PostgreSQL committers reviews
and approves it.

---------------------------------------------------------------------------


Holger Schurig wrote:
> SGML ref text (swapped parameter list, changed example text)
> 
> Also, I noticed that the text of the example spoke about a
> table "employees", but the example used the table "emp". I
> fixed this inconsistency.
> 
> 
> Index: src/doc/src/sgml/ref/cluster.sgml
> ===================================================================
> *** src.orig/doc/src/sgml/ref/cluster.sgml	2007-03-28 23:03:20.000000000 +0200
> --- src/doc/src/sgml/ref/cluster.sgml	2007-03-29 21:32:26.000000000 +0200
> ***************
> *** 20,27 ****
>   
>    
>   
> ! CLUSTER indexname ON tablename
> ! CLUSTER tablename
>   CLUSTER
>   
>    
> --- 20,26 ----
>   
>    
>   
> ! CLUSTER tablename [ USING indexname ]
>   CLUSTER
>   
>    
> ***************
> *** 77,95 ****
>   
>     
>      
> !     indexname
>       
>        
> !       The name of an index.
>        
>       
>      
>   
>      
> !     tablename
>       
>        
> !       The name (possibly schema-qualified) of a table.
>        
>       
>      
> --- 76,94 ----
>   
>     
>      
> !     tablename
>       
>        
> !       The name (possibly schema-qualified) of a table.
>        
>       
>      
>   
>      
> !     indexname
>       
>        
> !       The name of an index.
>        
>       
>      
> ***************
> *** 172,180 ****
>   
>     
>      Cluster the table employees on the basis of
> !    its index emp_ind:
>   
> ! CLUSTER emp_ind ON emp;
>   
>     
>   
> --- 171,179 ----
>   
>     
>      Cluster the table employees on the basis of
> !    its index employees_ind:
>   
> ! CLUSTER employees USING employees_ind;
>   
>     
>   
> ***************
> *** 182,188 ****
>      Cluster the employees table using the same
>      index that was used before:
>   
> ! CLUSTER emp;
>   
>     
>   
> --- 181,187 ----
>      Cluster the employees table using the same
>      index that was used before:
>   
> ! CLUSTER employees;
>   
>     
>   
> Index: src/src/backend/parser/gram.y
> ===================================================================
> *** src.orig/src/backend/parser/gram.y	2007-03-28 23:03:20.000000000 +0200
> --- src/src/backend/parser/gram.y	2007-03-28 23:03:35.000000000 +0200
> ***************
> *** 209,215 ****
>   
>   %type 		relation_name copy_file_name
>   				database_name access_method_clause access_method attr_name
> ! 				index_name name file_name
>   
>   %type 	func_name handler_name qual_Op qual_all_Op subquery_Op
>   				opt_class opt_validator
> --- 209,215 ----
>   
>   %type 		relation_name copy_file_name
>   				database_name access_method_clause access_method attr_name
> ! 				index_name name file_name opt_cluster_using
>   
>   %type 	func_name handler_name qual_Op qual_all_Op subquery_Op
>   				opt_class opt_validator
> ***************
> *** 5327,5332 ****
> --- 5327,5333 ----
>    *
>    *		QUERY:
>    *				cluster  on 
> +  *				cluster  USING 
>    *				cluster 
>    *				cluster
>    *
> ***************
> *** 5340,5350 ****
>   				   n->indexname = $2;
>   				   $$ = (Node*)n;
>   				}
> ! 			| CLUSTER qualified_name
>   				{
>   			       ClusterStmt *n = makeNode(ClusterStmt);
>   				   n->relation = $2;
> ! 				   n->indexname = NULL;
>   				   $$ = (Node*)n;
>   				}
>   			| CLUSTER
> --- 5341,5351 ----
>   				   n->indexname = $2;
>   				   $$ = (Node*)n;
>   				}
> ! 			| CLUSTER qualified_name opt_cluster_using
>   				{
>   			       ClusterStmt *n = makeNode(ClusterStmt);
>   				   n->relation = $2;
> ! 				   n->indexname = $3;
>   				   $$ = (Node*)n;
>   				}
>   			| CLUSTER
> ***************
> *** 5356,5361 ****
> --- 5357,5368 ----
>   				}
>   		;
>   
> + opt_cluster_using:
> + 			USING index_name			{ $$ = $2; }
> + 			| /*EMPTY*/				{ $$ = NULL; }
> + 		;
> + 
> + 
>   /*****************************************************************************
>    *
>    *		QUERY:
> Index: src/src/bin/psql/tab-complete.c
> ===================================================================
> *** src.orig/src/bin/psql/tab-complete.c	2007-03-28 23:03:20.000000000 +0200
> --- src/src/bin/psql/tab-complete.c	2007-03-28 23:03:35.000000000 +0200
> ***************
> *** 822,832 ****
>   
>   		COMPLETE_WITH_LIST(list_COLUMNALTER);
>   	}
> ! 	else if (pg_strcasecmp(prev3_wd, "TABLE") == 0 &&
> ! 			 pg_strcasecmp(prev_wd, "CLUSTER") == 0)
>   		COMPLETE_WITH_CONST("ON");
>   	else if (pg_strcasecmp(prev4_wd, "TABLE") == 0 &&
> - 			 pg_strcasecmp(prev2_wd, "CLUSTER") == 0 &&
>   			 pg_strcasecmp(prev_wd, "ON") == 0)
>   	{
>   		completion_info_charp = prev3_wd;
> --- 822,830 ----
>   
>   		COMPLETE_WITH_LIST(list_COLUMNALTER);
>   	}
> ! 	else if (pg_strcasecmp(prev3_wd, "TABLE") == 0)
>   		COMPLETE_WITH_CONST("ON");
>   	else if (pg_strcasecmp(prev4_wd, "TABLE") == 0 &&
>   			 pg_strcasecmp(prev_wd, "ON") == 0)
>   	{
>   		completion_info_charp = prev3_wd;
> ***************
> *** 929,952 ****
>   
>   	/*
>   	 * If the previous word is CLUSTER and not without produce list of
> ! 	 * indexes.
>   	 */
>   	else if (pg_strcasecmp(prev_wd, "CLUSTER") == 0 &&
>   			 pg_strcasecmp(prev2_wd, "WITHOUT") != 0)
> ! 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, NULL);
> ! 	/* If we have CLUSTER , then add "ON" */
>   	else if (pg_strcasecmp(prev2_wd, "CLUSTER") == 0 &&
> ! 			 pg_strcasecmp(prev_wd, "ON") != 0)
> ! 		COMPLETE_WITH_CONST("ON");
>   
>   	/*
> ! 	 * If we have CLUSTER  ON, then add the correct tablename as well.
>   	 */
>   	else if (pg_strcasecmp(prev3_wd, "CLUSTER") == 0 &&
> ! 			 pg_strcasecmp(prev_wd, "ON") == 0)
>   	{
>   		completion_info_charp = prev2_wd;
> ! 		COMPLETE_WITH_QUERY(Query_for_table_owning_index);
>   	}
>   
>   /* COMMENT */
> --- 927,951 ----
>   
>   	/*
>   	 * If the previous word is CLUSTER and not without produce list of
> ! 	 * tables
>   	 */
>   	else if (pg_strcasecmp(prev_wd, "CLUSTER") == 0 &&
>   			 pg_strcasecmp(prev2_wd, "WITHOUT") != 0)
> ! 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
> ! 	/* If we have CLUSTER , then add "USING" */
>   	else if (pg_strcasecmp(prev2_wd, "CLUSTER") == 0 &&
> ! 			 pg_strcasecmp(prev_wd, "ON") != 0) {
> ! 		COMPLETE_WITH_CONST("USING");
> ! 	}
>   
>   	/*
> ! 	 * If we have CLUSTER  ORDER BY, then add the index as well.
>   	 */
>   	else if (pg_strcasecmp(prev3_wd, "CLUSTER") == 0 &&
> ! 			 pg_strcasecmp(prev_wd, "USING") == 0)
>   	{
>   		completion_info_charp = prev2_wd;
> ! 		COMPLETE_WITH_QUERY(Query_for_index_of_table);
>   	}
>   
>   /* COMMENT */
> Index: src/src/test/regress/expected/cluster.out
> ===================================================================
> *** src.orig/src/test/regress/expected/cluster.out	2007-03-28 23:03:20.000000000 +0200
> --- src/src/test/regress/expected/cluster.out	2007-03-28 23:03:35.000000000 +0200
> ***************
> *** 329,335 ****
>   CLUSTER clstr_2;
>   ERROR:  there is no previously clustered index for table "clstr_2"
>   CLUSTER clstr_1_pkey ON clstr_1;
> ! CLUSTER clstr_2_pkey ON clstr_2;
>   SELECT * FROM clstr_1 UNION ALL
>     SELECT * FROM clstr_2 UNION ALL
>     SELECT * FROM clstr_3;
> --- 329,335 ----
>   CLUSTER clstr_2;
>   ERROR:  there is no previously clustered index for table "clstr_2"
>   CLUSTER clstr_1_pkey ON clstr_1;
> ! CLUSTER clstr_2 USING clstr_2_pkey;
>   SELECT * FROM clstr_1 UNION ALL
>     SELECT * FROM clstr_2 UNION ALL
>     SELECT * FROM clstr_3;
> Index: src/src/test/regress/sql/cluster.sql
> ===================================================================
> *** src.orig/src/test/regress/sql/cluster.sql	2007-03-28 23:03:20.000000000 +0200
> --- src/src/test/regress/sql/cluster.sql	2007-03-28 23:03:35.000000000 +0200
> ***************
> *** 122,128 ****
>   CLUSTER clstr_2;
>   
>   CLUSTER clstr_1_pkey ON clstr_1;
> ! CLUSTER clstr_2_pkey ON clstr_2;
>   SELECT * FROM clstr_1 UNION ALL
>     SELECT * FROM clstr_2 UNION ALL
>     SELECT * FROM clstr_3;
> --- 122,128 ----
>   CLUSTER clstr_2;
>   
>   CLUSTER clstr_1_pkey ON clstr_1;
> ! CLUSTER clstr_2 USING clstr_2_pkey;
>   SELECT * FROM clstr_1 UNION ALL
>     SELECT * FROM clstr_2 UNION ALL
>     SELECT * FROM clstr_3;
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
> 
>                http://archives.postgresql.org

-- 
  Bruce Momjian            http://momjian.us
  EnterpriseDB                               http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

Re: [PATCH] add CLUSTER table USING index (take 3)

От:
Bruce Momjian <bruce@momjian.us>
Дата:

Updated patch applied.  Thanks.

I added a mention of the old syntax at the bottom of the CLUSTER manual
page, and cleaned up the grammar a little.  Also did a little comment
cleaning in gram.y.

---------------------------------------------------------------------------



Holger Schurig wrote:
> SGML ref text (swapped parameter list, changed example text)
> 
> Also, I noticed that the text of the example spoke about a
> table "employees", but the example used the table "emp". I
> fixed this inconsistency.
> 

-- 
  Bruce Momjian            http://momjian.us
  EnterpriseDB                               http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +
Index: doc/src/sgml/ref/cluster.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/ref/cluster.sgml,v
retrieving revision 1.40
diff -c -c -r1.40 cluster.sgml
*** doc/src/sgml/ref/cluster.sgml	1 Feb 2007 00:28:18 -0000	1.40
--- doc/src/sgml/ref/cluster.sgml	8 Apr 2007 00:23:30 -0000
***************
*** 20,27 ****
  
   
  
! CLUSTER indexname ON tablename
! CLUSTER tablename
  CLUSTER
  
   
--- 20,26 ----
  
   
  
! CLUSTER tablename [ USING indexname ]
  CLUSTER
  
   
***************
*** 77,95 ****
  
    
     
!     indexname
      
       
!       The name of an index.
       
      
     
  
     
!     tablename
      
       
!       The name (possibly schema-qualified) of a table.
       
      
     
--- 76,94 ----
  
    
     
!     tablename
      
       
!       The name (possibly schema-qualified) of a table.
       
      
     
  
     
!     indexname
      
       
!       The name of an index.
       
      
     
***************
*** 172,180 ****
  
    
     Cluster the table employees on the basis of
!    its index emp_ind:
  
! CLUSTER emp_ind ON emp;
  
    
  
--- 171,179 ----
  
    
     Cluster the table employees on the basis of
!    its index employees_ind:
  
! CLUSTER employees USING employees_ind;
  
    
  
***************
*** 182,188 ****
     Cluster the employees table using the same
     index that was used before:
  
! CLUSTER emp;
  
    
  
--- 181,187 ----
     Cluster the employees table using the same
     index that was used before:
  
! CLUSTER employees;
  
    
  
***************
*** 198,204 ****
    Compatibility
  
    
!    There is no CLUSTER statement in the SQL standard.
    
   
  
--- 197,208 ----
    Compatibility
  
    
!    The syntax:
! 
! CLUSTER indexname ON tablename
! 
!   is also supported for compatibility with pre-8.3 PostgreSQL</> installations.
!   There is no CLUSTER statement in the SQL standard.
    
   
  
Index: src/backend/parser/gram.y
===================================================================
RCS file: /cvsroot/pgsql/src/backend/parser/gram.y,v
retrieving revision 2.586
diff -c -c -r2.586 gram.y
*** src/backend/parser/gram.y	2 Apr 2007 22:20:53 -0000	2.586
--- src/backend/parser/gram.y	8 Apr 2007 00:23:32 -0000
***************
*** 209,215 ****
  
  %type 		relation_name copy_file_name
  				database_name access_method_clause access_method attr_name
! 				index_name name file_name
  
  %type 	func_name handler_name qual_Op qual_all_Op subquery_Op
  				opt_class opt_validator
--- 209,215 ----
  
  %type 		relation_name copy_file_name
  				database_name access_method_clause access_method attr_name
! 				index_name name file_name cluster_index_specification
  
  %type 	func_name handler_name qual_Op qual_all_Op subquery_Op
  				opt_class opt_validator
***************
*** 5084,5090 ****
  /*****************************************************************************
   *
   *		QUERY:
!  *				load "filename"
   *
   *****************************************************************************/
  
--- 5084,5090 ----
  /*****************************************************************************
   *
   *		QUERY:
!  *				LOAD "filename"
   *
   *****************************************************************************/
  
***************
*** 5346,5370 ****
  /*****************************************************************************
   *
   *		QUERY:
!  *				cluster  on 
!  *				cluster 
!  *				cluster
   *
   *****************************************************************************/
  
  ClusterStmt:
! 			CLUSTER index_name ON qualified_name
! 				{
! 				   ClusterStmt *n = makeNode(ClusterStmt);
! 				   n->relation = $4;
! 				   n->indexname = $2;
! 				   $$ = (Node*)n;
! 				}
! 			| CLUSTER qualified_name
  				{
  			       ClusterStmt *n = makeNode(ClusterStmt);
  				   n->relation = $2;
! 				   n->indexname = NULL;
  				   $$ = (Node*)n;
  				}
  			| CLUSTER
--- 5346,5363 ----
  /*****************************************************************************
   *
   *		QUERY:
!  *				CLUSTER  [ USING  ]
!  *				CLUSTER
!  *				CLUSTER  ON  (for pre-8.3)
   *
   *****************************************************************************/
  
  ClusterStmt:
! 			CLUSTER qualified_name cluster_index_specification
  				{
  			       ClusterStmt *n = makeNode(ClusterStmt);
  				   n->relation = $2;
! 				   n->indexname = $3;
  				   $$ = (Node*)n;
  				}
  			| CLUSTER
***************
*** 5374,5386 ****
  				   n->indexname = NULL;
  				   $$ = (Node*)n;
  				}
  		;
  
  /*****************************************************************************
   *
   *		QUERY:
!  *				vacuum
!  *				analyze
   *
   *****************************************************************************/
  
--- 5367,5393 ----
  				   n->indexname = NULL;
  				   $$ = (Node*)n;
  				}
+ 			/* kept for pre-8.3 compatibility */
+ 			| CLUSTER index_name ON qualified_name
+ 				{
+ 				   ClusterStmt *n = makeNode(ClusterStmt);
+ 				   n->relation = $4;
+ 				   n->indexname = $2;
+ 				   $$ = (Node*)n;
+ 				}
+ 		;
+ 
+ cluster_index_specification:
+ 			USING index_name		{ $$ = $2; }
+ 			| /*EMPTY*/				{ $$ = NULL; }
  		;
  
+ 
  /*****************************************************************************
   *
   *		QUERY:
!  *				VACUUM
!  *				ANALYZE
   *
   *****************************************************************************/
  
Index: src/bin/psql/tab-complete.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v
retrieving revision 1.160
diff -c -c -r1.160 tab-complete.c
*** src/bin/psql/tab-complete.c	26 Mar 2007 16:58:40 -0000	1.160
--- src/bin/psql/tab-complete.c	8 Apr 2007 00:23:33 -0000
***************
*** 822,832 ****
  
  		COMPLETE_WITH_LIST(list_COLUMNALTER);
  	}
! 	else if (pg_strcasecmp(prev3_wd, "TABLE") == 0 &&
! 			 pg_strcasecmp(prev_wd, "CLUSTER") == 0)
  		COMPLETE_WITH_CONST("ON");
  	else if (pg_strcasecmp(prev4_wd, "TABLE") == 0 &&
- 			 pg_strcasecmp(prev2_wd, "CLUSTER") == 0 &&
  			 pg_strcasecmp(prev_wd, "ON") == 0)
  	{
  		completion_info_charp = prev3_wd;
--- 822,830 ----
  
  		COMPLETE_WITH_LIST(list_COLUMNALTER);
  	}
! 	else if (pg_strcasecmp(prev3_wd, "TABLE") == 0)
  		COMPLETE_WITH_CONST("ON");
  	else if (pg_strcasecmp(prev4_wd, "TABLE") == 0 &&
  			 pg_strcasecmp(prev_wd, "ON") == 0)
  	{
  		completion_info_charp = prev3_wd;
***************
*** 929,952 ****
  
  	/*
  	 * If the previous word is CLUSTER and not without produce list of
! 	 * indexes.
  	 */
  	else if (pg_strcasecmp(prev_wd, "CLUSTER") == 0 &&
  			 pg_strcasecmp(prev2_wd, "WITHOUT") != 0)
! 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, NULL);
! 	/* If we have CLUSTER , then add "ON" */
  	else if (pg_strcasecmp(prev2_wd, "CLUSTER") == 0 &&
! 			 pg_strcasecmp(prev_wd, "ON") != 0)
! 		COMPLETE_WITH_CONST("ON");
  
  	/*
! 	 * If we have CLUSTER  ON, then add the correct tablename as well.
  	 */
  	else if (pg_strcasecmp(prev3_wd, "CLUSTER") == 0 &&
! 			 pg_strcasecmp(prev_wd, "ON") == 0)
  	{
  		completion_info_charp = prev2_wd;
! 		COMPLETE_WITH_QUERY(Query_for_table_owning_index);
  	}
  
  /* COMMENT */
--- 927,951 ----
  
  	/*
  	 * If the previous word is CLUSTER and not without produce list of
! 	 * tables
  	 */
  	else if (pg_strcasecmp(prev_wd, "CLUSTER") == 0 &&
  			 pg_strcasecmp(prev2_wd, "WITHOUT") != 0)
! 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
! 	/* If we have CLUSTER , then add "USING" */
  	else if (pg_strcasecmp(prev2_wd, "CLUSTER") == 0 &&
! 			 pg_strcasecmp(prev_wd, "ON") != 0) {
! 		COMPLETE_WITH_CONST("USING");
! 	}
  
  	/*
! 	 * If we have CLUSTER  ORDER BY, then add the index as well.
  	 */
  	else if (pg_strcasecmp(prev3_wd, "CLUSTER") == 0 &&
! 			 pg_strcasecmp(prev_wd, "USING") == 0)
  	{
  		completion_info_charp = prev2_wd;
! 		COMPLETE_WITH_QUERY(Query_for_index_of_table);
  	}
  
  /* COMMENT */
Index: src/test/regress/expected/cluster.out
===================================================================
RCS file: /cvsroot/pgsql/src/test/regress/expected/cluster.out,v
retrieving revision 1.17
diff -c -c -r1.17 cluster.out
*** src/test/regress/expected/cluster.out	7 Jul 2005 20:40:01 -0000	1.17
--- src/test/regress/expected/cluster.out	8 Apr 2007 00:23:36 -0000
***************
*** 329,335 ****
  CLUSTER clstr_2;
  ERROR:  there is no previously clustered index for table "clstr_2"
  CLUSTER clstr_1_pkey ON clstr_1;
! CLUSTER clstr_2_pkey ON clstr_2;
  SELECT * FROM clstr_1 UNION ALL
    SELECT * FROM clstr_2 UNION ALL
    SELECT * FROM clstr_3;
--- 329,335 ----
  CLUSTER clstr_2;
  ERROR:  there is no previously clustered index for table "clstr_2"
  CLUSTER clstr_1_pkey ON clstr_1;
! CLUSTER clstr_2 USING clstr_2_pkey;
  SELECT * FROM clstr_1 UNION ALL
    SELECT * FROM clstr_2 UNION ALL
    SELECT * FROM clstr_3;
Index: src/test/regress/sql/cluster.sql
===================================================================
RCS file: /cvsroot/pgsql/src/test/regress/sql/cluster.sql,v
retrieving revision 1.9
diff -c -c -r1.9 cluster.sql
*** src/test/regress/sql/cluster.sql	7 Jul 2005 20:40:02 -0000	1.9
--- src/test/regress/sql/cluster.sql	8 Apr 2007 00:23:36 -0000
***************
*** 122,128 ****
  CLUSTER clstr_2;
  
  CLUSTER clstr_1_pkey ON clstr_1;
! CLUSTER clstr_2_pkey ON clstr_2;
  SELECT * FROM clstr_1 UNION ALL
    SELECT * FROM clstr_2 UNION ALL
    SELECT * FROM clstr_3;
--- 122,128 ----
  CLUSTER clstr_2;
  
  CLUSTER clstr_1_pkey ON clstr_1;
! CLUSTER clstr_2 USING clstr_2_pkey;
  SELECT * FROM clstr_1 UNION ALL
    SELECT * FROM clstr_2 UNION ALL
    SELECT * FROM clstr_3;
FAQ