12
12
*by PostgreSQL
13
13
*
14
14
* 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 $
16
16
*
17
17
*-------------------------------------------------------------------------
18
18
*/
@@ -5730,6 +5730,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
5730
5730
int i_indexdef ;
5731
5731
int i_contype ;
5732
5732
int i_indkey ;
5733
+ int i_indisclustered ;
5733
5734
int i_indnkeys ;
5734
5735
5735
5736
for (i = 0 ;i < numTables ;i ++ )
@@ -5759,7 +5760,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
5759
5760
"SELECT i.indexrelid as indexreloid, "
5760
5761
"coalesce(c.conname, t.relname) as indexrelname, "
5761
5762
"pg_catalog.pg_get_indexdef(i.indexrelid) as indexdef, "
5762
- "i.indkey, "
5763
+ "i.indkey,i.indisclustered, "
5763
5764
"t.relnatts as indnkeys, "
5764
5765
"coalesce(c.contype, '0') as contype "
5765
5766
"FROM pg_catalog.pg_index i "
@@ -5779,7 +5780,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
5779
5780
"SELECT i.indexrelid as indexreloid, "
5780
5781
"t.relname as indexrelname, "
5781
5782
"pg_get_indexdef(i.indexrelid) as indexdef, "
5782
- "i.indkey, "
5783
+ "i.indkey,false as indisclustered, "
5783
5784
"t.relnatts as indnkeys, "
5784
5785
"CASE WHEN i.indisprimary THEN 'p'::char "
5785
5786
"ELSE '0'::char END as contype "
@@ -5804,6 +5805,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
5804
5805
i_indexdef = PQfnumber (res ,"indexdef" );
5805
5806
i_contype = PQfnumber (res ,"contype" );
5806
5807
i_indkey = PQfnumber (res ,"indkey" );
5808
+ i_indisclustered = PQfnumber (res ,"indisclustered" );
5807
5809
i_indnkeys = PQfnumber (res ,"indnkeys" );
5808
5810
5809
5811
for (j = 0 ;j < ntups ;j ++ )
@@ -5812,6 +5814,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
5812
5814
const char * indexrelname = PQgetvalue (res ,j ,i_indexrelname );
5813
5815
const char * indexdef = PQgetvalue (res ,j ,i_indexdef );
5814
5816
char contype = * (PQgetvalue (res ,j ,i_contype ));
5817
+ bool indisclustered = (PQgetvalue (res ,j ,i_indisclustered )[0 ]== 't' );
5815
5818
5816
5819
resetPQExpBuffer (q );
5817
5820
resetPQExpBuffer (delq );
@@ -5864,6 +5867,13 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
5864
5867
fmtId (tbinfo -> relname ));
5865
5868
appendPQExpBuffer (delq ,"DROP CONSTRAINT %s;\n" ,
5866
5869
fmtId (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
+ }
5867
5877
5868
5878
ArchiveEntry (fout ,indexreloid ,
5869
5879
indexrelname ,
@@ -5882,6 +5892,14 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
5882
5892
/* Plain secondary index */
5883
5893
appendPQExpBuffer (q ,"%s;\n" ,indexdef );
5884
5894
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
+
5885
5903
/*
5886
5904
* DROP must be fully qualified in case same name appears
5887
5905
* in pg_catalog