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

Commit9d6f5ee

Browse files
committed
Adds
ALTER TABLE foo CLUSTER ON bar;In pg_dumps, to preserve cluster settings.Christopher Kings-Lynne
1 parentb099d9e commit9d6f5ee

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
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)
57305730
inti_indexdef;
57315731
inti_contype;
57325732
inti_indkey;
5733+
inti_indisclustered;
57335734
inti_indnkeys;
57345735

57355736
for (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)
58045805
i_indexdef=PQfnumber(res,"indexdef");
58055806
i_contype=PQfnumber(res,"contype");
58065807
i_indkey=PQfnumber(res,"indkey");
5808+
i_indisclustered=PQfnumber(res,"indisclustered");
58075809
i_indnkeys=PQfnumber(res,"indnkeys");
58085810

58095811
for (j=0;j<ntups;j++)
@@ -5812,6 +5814,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
58125814
constchar*indexrelname=PQgetvalue(res,j,i_indexrelname);
58135815
constchar*indexdef=PQgetvalue(res,j,i_indexdef);
58145816
charcontype=*(PQgetvalue(res,j,i_contype));
5817+
boolindisclustered= (PQgetvalue(res,j,i_indisclustered)[0]=='t');
58155818

58165819
resetPQExpBuffer(q);
58175820
resetPQExpBuffer(delq);
@@ -5864,6 +5867,13 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
58645867
fmtId(tbinfo->relname));
58655868
appendPQExpBuffer(delq,"DROP CONSTRAINT %s;\n",
58665869
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+
}
58675877

58685878
ArchiveEntry(fout,indexreloid,
58695879
indexrelname,
@@ -5882,6 +5892,14 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
58825892
/* Plain secondary index */
58835893
appendPQExpBuffer(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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp