]> granicus.if.org Git - postgresql/commitdiff
Adds
authorBruce Momjian <bruce@momjian.us>
Thu, 27 Mar 2003 16:43:07 +0000 (16:43 +0000)
committerBruce Momjian <bruce@momjian.us>
Thu, 27 Mar 2003 16:43:07 +0000 (16:43 +0000)
ALTER TABLE foo CLUSTER ON bar;

In pg_dumps, to preserve cluster settings.

Christopher Kings-Lynne

src/bin/pg_dump/pg_dump.c

index 995144daae460d7cd6287854e8a0d7865a428870..cb2eb0d2016f0bb40abb32d9d7376cf5679d20d1 100644 (file)
@@ -12,7 +12,7 @@
  *     by PostgreSQL
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.323 2003/03/27 16:39:17 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.324 2003/03/27 16:43:07 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -5730,6 +5730,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
        int                     i_indexdef;
        int                     i_contype;
        int                     i_indkey;
+       int                     i_indisclustered;
        int                     i_indnkeys;
 
        for (i = 0; i < numTables; i++)
@@ -5759,7 +5760,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
                                                          "SELECT i.indexrelid as indexreloid, "
                                           "coalesce(c.conname, t.relname) as indexrelname, "
                                 "pg_catalog.pg_get_indexdef(i.indexrelid) as indexdef, "
-                                                         "i.indkey, "
+                                                         "i.indkey, i.indisclustered, "
                                                          "t.relnatts as indnkeys, "
                                                          "coalesce(c.contype, '0') as contype "
                                                          "FROM pg_catalog.pg_index i "
@@ -5779,7 +5780,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
                                                          "SELECT i.indexrelid as indexreloid, "
                                                          "t.relname as indexrelname, "
                                                        "pg_get_indexdef(i.indexrelid) as indexdef, "
-                                                         "i.indkey, "
+                                                         "i.indkey, false as indisclustered, "
                                                          "t.relnatts as indnkeys, "
                                                          "CASE WHEN i.indisprimary THEN 'p'::char "
                                                          "ELSE '0'::char END as contype "
@@ -5804,6 +5805,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
                i_indexdef = PQfnumber(res, "indexdef");
                i_contype = PQfnumber(res, "contype");
                i_indkey = PQfnumber(res, "indkey");
+               i_indisclustered = PQfnumber(res, "indisclustered");
                i_indnkeys = PQfnumber(res, "indnkeys");
 
                for (j = 0; j < ntups; j++)
@@ -5812,6 +5814,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
                        const char *indexrelname = PQgetvalue(res, j, i_indexrelname);
                        const char *indexdef = PQgetvalue(res, j, i_indexdef);
                        char            contype = *(PQgetvalue(res, j, i_contype));
+                       bool    indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
 
                        resetPQExpBuffer(q);
                        resetPQExpBuffer(delq);
@@ -5864,6 +5867,13 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
                                                                  fmtId(tbinfo->relname));
                                appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
                                                                  fmtId(indexrelname));
+                               /* If the index is clustered, we need to record that. */
+                               if (indisclustered) {
+                                       appendPQExpBuffer(q, "\nALTER TABLE %s CLUSTER", 
+                                                                fmtId(tbinfo->relname));
+                                       appendPQExpBuffer(q, " ON %s;\n", 
+                                                                fmtId(indexrelname));
+                               }
 
                                ArchiveEntry(fout, indexreloid,
                                                         indexrelname,
@@ -5882,6 +5892,14 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
                                /* Plain secondary index */
                                appendPQExpBuffer(q, "%s;\n", indexdef);
 
+                               /* If the index is clustered, we need to record that. */
+                               if (indisclustered) {
+                                       appendPQExpBuffer(q, "\nALTER TABLE %s CLUSTER", 
+                                                                fmtId(tbinfo->relname));
+                                       appendPQExpBuffer(q, " ON %s;\n", 
+                                                                fmtId(indexrelname));
+                               }
+
                                /*
                                 * DROP must be fully qualified in case same name appears
                                 * in pg_catalog