1212 *by PostgreSQL
1313 *
1414 * IDENTIFICATION
15- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.323 2003/03/27 16:39:17 momjian Exp $
15+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.324 2003/03/27 16:43:07 momjian Exp $
1616 *
1717 *-------------------------------------------------------------------------
1818 */
@@ -5730,6 +5730,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
57305730int i_indexdef ;
57315731int i_contype ;
57325732int i_indkey ;
5733+ int i_indisclustered ;
57335734int i_indnkeys ;
57345735
57355736for (i = 0 ;i < numTables ;i ++ )
@@ -5759,7 +5760,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
57595760"SELECT i.indexrelid as indexreloid, "
57605761"coalesce(c.conname, t.relname) as indexrelname, "
57615762"pg_catalog.pg_get_indexdef(i.indexrelid) as indexdef, "
5762- "i.indkey, "
5763+ "i.indkey,i.indisclustered, "
57635764"t.relnatts as indnkeys, "
57645765"coalesce(c.contype, '0') as contype "
57655766"FROM pg_catalog.pg_index i "
@@ -5779,7 +5780,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
57795780"SELECT i.indexrelid as indexreloid, "
57805781"t.relname as indexrelname, "
57815782"pg_get_indexdef(i.indexrelid) as indexdef, "
5782- "i.indkey, "
5783+ "i.indkey,false as indisclustered, "
57835784"t.relnatts as indnkeys, "
57845785"CASE WHEN i.indisprimary THEN 'p'::char "
57855786"ELSE '0'::char END as contype "
@@ -5804,6 +5805,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
58045805i_indexdef = PQfnumber (res ,"indexdef" );
58055806i_contype = PQfnumber (res ,"contype" );
58065807i_indkey = PQfnumber (res ,"indkey" );
5808+ i_indisclustered = PQfnumber (res ,"indisclustered" );
58075809i_indnkeys = PQfnumber (res ,"indnkeys" );
58085810
58095811for (j = 0 ;j < ntups ;j ++ )
@@ -5812,6 +5814,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
58125814const char * indexrelname = PQgetvalue (res ,j ,i_indexrelname );
58135815const char * indexdef = PQgetvalue (res ,j ,i_indexdef );
58145816char contype = * (PQgetvalue (res ,j ,i_contype ));
5817+ bool indisclustered = (PQgetvalue (res ,j ,i_indisclustered )[0 ]== 't' );
58155818
58165819resetPQExpBuffer (q );
58175820resetPQExpBuffer (delq );
@@ -5864,6 +5867,13 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
58645867fmtId (tbinfo -> relname ));
58655868appendPQExpBuffer (delq ,"DROP CONSTRAINT %s;\n" ,
58665869fmtId (indexrelname ));
5870+ /* If the index is clustered, we need to record that. */
5871+ if (indisclustered ) {
5872+ appendPQExpBuffer (q ,"\nALTER TABLE %s CLUSTER" ,
5873+ fmtId (tbinfo -> relname ));
5874+ appendPQExpBuffer (q ," ON %s;\n" ,
5875+ fmtId (indexrelname ));
5876+ }
58675877
58685878ArchiveEntry (fout ,indexreloid ,
58695879indexrelname ,
@@ -5882,6 +5892,14 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
58825892/* Plain secondary index */
58835893appendPQExpBuffer (q ,"%s;\n" ,indexdef );
58845894
5895+ /* If the index is clustered, we need to record that. */
5896+ if (indisclustered ) {
5897+ appendPQExpBuffer (q ,"\nALTER TABLE %s CLUSTER" ,
5898+ fmtId (tbinfo -> relname ));
5899+ appendPQExpBuffer (q ," ON %s;\n" ,
5900+ fmtId (indexrelname ));
5901+ }
5902+
58855903/*
58865904 * DROP must be fully qualified in case same name appears
58875905 * in pg_catalog