Commit 1b3d4cef authored by Bruce Momjian's avatar Bruce Momjian

It has been tested only against CVS backend, however. Some checking of the

changes to the SQL to retrieve attributes for older versions of Postgres is
probably wise.  Also, please make sure that I have mapped the storage types
to the correct storage names, as this is relatively poorly documented.

I think that this patch might need to be considered for back-porting to
7.3.3 since at the moment, people will be losing valuable information after
upgrades.

Will dump:

CREATE TABLE test (
    a text,
    b text,
    c text,
    d text
);
ALTER TABLE ONLY test ALTER COLUMN a SET STATISTICS 55;
ALTER TABLE ONLY test ALTER COLUMN a SET STORAGE PLAIN;
ALTER TABLE ONLY test ALTER COLUMN b SET STATISTICS 1000;
ALTER TABLE ONLY test ALTER COLUMN c SET STORAGE EXTERNAL;
ALTER TABLE ONLY test ALTER COLUMN d SET STORAGE MAIN;

Christopher Kings-Lynne
parent 44aba280
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* by PostgreSQL * by PostgreSQL
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.320 2003/03/20 05:18:14 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.321 2003/03/20 06:26:30 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2415,6 +2415,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -2415,6 +2415,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
int i_atttypname; int i_atttypname;
int i_atttypmod; int i_atttypmod;
int i_attstattarget; int i_attstattarget;
int i_attstorage;
int i_typstorage;
int i_attnotnull; int i_attnotnull;
int i_atthasdef; int i_atthasdef;
int i_attisdropped; int i_attisdropped;
...@@ -2459,13 +2461,14 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -2459,13 +2461,14 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
if (g_fout->remoteVersion >= 70300) if (g_fout->remoteVersion >= 70300)
{ {
appendPQExpBuffer(q, "SELECT attnum, attname, atttypmod, attstattarget, " appendPQExpBuffer(q, "SELECT a.attnum, a.attname, a.atttypmod, a.attstattarget, a.attstorage, t.typstorage, "
"attnotnull, atthasdef, attisdropped, attislocal, " "a.attnotnull, a.atthasdef, a.attisdropped, a.attislocal, "
"pg_catalog.format_type(atttypid,atttypmod) as atttypname " "pg_catalog.format_type(a.atttypid,a.atttypmod) as atttypname "
"from pg_catalog.pg_attribute a " "from pg_catalog.pg_attribute a, pg_catalog.pg_type t "
"where attrelid = '%s'::pg_catalog.oid " "where a.atttypid = t.oid "
"and attnum > 0::pg_catalog.int2 " "and a.attrelid = '%s'::pg_catalog.oid "
"order by attrelid, attnum", "and a.attnum > 0::pg_catalog.int2 "
"order by a.attrelid, a.attnum",
tbinfo->oid); tbinfo->oid);
} }
else if (g_fout->remoteVersion >= 70100) else if (g_fout->remoteVersion >= 70100)
...@@ -2475,19 +2478,20 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -2475,19 +2478,20 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
* but we don't dump it because we can't tell whether it's * but we don't dump it because we can't tell whether it's
* been explicitly set or was just a default. * been explicitly set or was just a default.
*/ */
appendPQExpBuffer(q, "SELECT attnum, attname, atttypmod, -1 as attstattarget, " appendPQExpBuffer(q, "SELECT a.attnum, a.attname, a.atttypmod, -1 as attstattarget, a.attstorage, t.typstorage, "
"attnotnull, atthasdef, false as attisdropped, null as attislocal, " "a.attnotnull, a.atthasdef, false as attisdropped, null as attislocal, "
"format_type(atttypid,atttypmod) as atttypname " "format_type(a.atttypid,a.atttypmod) as atttypname "
"from pg_attribute a " "from pg_attribute a, pg_type t "
"where attrelid = '%s'::oid " "where a.atttypid = t.oid"
"and attnum > 0::int2 " "and a.attrelid = '%s'::oid "
"order by attrelid, attnum", "and a.attnum > 0::int2 "
"order by a.attrelid, a.attnum",
tbinfo->oid); tbinfo->oid);
} }
else else
{ {
/* format_type not available before 7.1 */ /* format_type not available before 7.1 */
appendPQExpBuffer(q, "SELECT attnum, attname, atttypmod, -1 as attstattarget, " appendPQExpBuffer(q, "SELECT attnum, attname, atttypmod, -1 as attstattarget, attstorage, 'p' as typstorage, "
"attnotnull, atthasdef, false as attisdropped, null as attislocal, " "attnotnull, atthasdef, false as attisdropped, null as attislocal, "
"(select typname from pg_type where oid = atttypid) as atttypname " "(select typname from pg_type where oid = atttypid) as atttypname "
"from pg_attribute a " "from pg_attribute a "
...@@ -2511,6 +2515,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -2511,6 +2515,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
i_atttypname = PQfnumber(res, "atttypname"); i_atttypname = PQfnumber(res, "atttypname");
i_atttypmod = PQfnumber(res, "atttypmod"); i_atttypmod = PQfnumber(res, "atttypmod");
i_attstattarget = PQfnumber(res, "attstattarget"); i_attstattarget = PQfnumber(res, "attstattarget");
i_attstorage = PQfnumber(res, "attstorage");
i_typstorage = PQfnumber(res, "typstorage");
i_attnotnull = PQfnumber(res, "attnotnull"); i_attnotnull = PQfnumber(res, "attnotnull");
i_atthasdef = PQfnumber(res, "atthasdef"); i_atthasdef = PQfnumber(res, "atthasdef");
i_attisdropped = PQfnumber(res, "attisdropped"); i_attisdropped = PQfnumber(res, "attisdropped");
...@@ -2521,6 +2527,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -2521,6 +2527,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
tbinfo->atttypnames = (char **) malloc(ntups * sizeof(char *)); tbinfo->atttypnames = (char **) malloc(ntups * sizeof(char *));
tbinfo->atttypmod = (int *) malloc(ntups * sizeof(int)); tbinfo->atttypmod = (int *) malloc(ntups * sizeof(int));
tbinfo->attstattarget = (int *) malloc(ntups * sizeof(int)); tbinfo->attstattarget = (int *) malloc(ntups * sizeof(int));
tbinfo->attstorage = (char *) malloc(ntups * sizeof(char));
tbinfo->typstorage = (char *) malloc(ntups * sizeof(char));
tbinfo->attisdropped = (bool *) malloc(ntups * sizeof(bool)); tbinfo->attisdropped = (bool *) malloc(ntups * sizeof(bool));
tbinfo->attislocal = (bool *) malloc(ntups * sizeof(bool)); tbinfo->attislocal = (bool *) malloc(ntups * sizeof(bool));
tbinfo->attisserial = (bool *) malloc(ntups * sizeof(bool)); tbinfo->attisserial = (bool *) malloc(ntups * sizeof(bool));
...@@ -2537,6 +2545,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -2537,6 +2545,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
tbinfo->atttypnames[j] = strdup(PQgetvalue(res, j, i_atttypname)); tbinfo->atttypnames[j] = strdup(PQgetvalue(res, j, i_atttypname));
tbinfo->atttypmod[j] = atoi(PQgetvalue(res, j, i_atttypmod)); tbinfo->atttypmod[j] = atoi(PQgetvalue(res, j, i_atttypmod));
tbinfo->attstattarget[j] = atoi(PQgetvalue(res, j, i_attstattarget)); tbinfo->attstattarget[j] = atoi(PQgetvalue(res, j, i_attstattarget));
tbinfo->attstorage[j] = *(PQgetvalue(res, j, i_attstorage));
tbinfo->typstorage[j] = *(PQgetvalue(res, j, i_typstorage));
tbinfo->attisdropped[j] = (PQgetvalue(res, j, i_attisdropped)[0] == 't'); tbinfo->attisdropped[j] = (PQgetvalue(res, j, i_attisdropped)[0] == 't');
tbinfo->attislocal[j] = (PQgetvalue(res, j, i_attislocal)[0] == 't'); tbinfo->attislocal[j] = (PQgetvalue(res, j, i_attislocal)[0] == 't');
tbinfo->attisserial[j] = false; /* fix below */ tbinfo->attisserial[j] = false; /* fix below */
...@@ -5254,6 +5264,7 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) ...@@ -5254,6 +5264,7 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo)
int *parentIndexes; int *parentIndexes;
int actual_atts; /* number of attrs in this CREATE statment */ int actual_atts; /* number of attrs in this CREATE statment */
char *reltypename; char *reltypename;
char *storage;
char *objoid; char *objoid;
const char *((*commentDeps)[]); const char *((*commentDeps)[]);
int j, int j,
...@@ -5566,13 +5577,14 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) ...@@ -5566,13 +5577,14 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo)
appendPQExpBuffer(q, ";\n"); appendPQExpBuffer(q, ";\n");
/* Loop dumping statistics and storage statements */
for (j = 0; j < tbinfo->numatts; j++)
{
/* /*
* Dump per-column statistics information. We only issue an ALTER * Dump per-column statistics information. We only issue an ALTER
* TABLE statement if the attstattarget entry for this column is * TABLE statement if the attstattarget entry for this column is
* non-negative (i.e. it's not the default value) * non-negative (i.e. it's not the default value)
*/ */
for (j = 0; j < tbinfo->numatts; j++)
{
if (tbinfo->attstattarget[j] >= 0 && if (tbinfo->attstattarget[j] >= 0 &&
!tbinfo->attisdropped[j]) !tbinfo->attisdropped[j])
{ {
...@@ -5583,6 +5595,39 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) ...@@ -5583,6 +5595,39 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo)
appendPQExpBuffer(q, "SET STATISTICS %d;\n", appendPQExpBuffer(q, "SET STATISTICS %d;\n",
tbinfo->attstattarget[j]); tbinfo->attstattarget[j]);
} }
/*
* Dump per-column storage information. The statement is only dumped if
* the storage has been changed.
*/
if(!tbinfo->attisdropped[j] && tbinfo->attstorage[j] != tbinfo->typstorage[j])
{
switch (tbinfo->attstorage[j]) {
case 'p':
storage = "PLAIN";
break;
case 'e':
storage = "EXTERNAL";
break;
case 'm':
storage = "MAIN";
break;
case 'x':
storage = "EXTENDED";
break;
default:
storage = NULL;
}
/* Only dump the statement if it's a storage type we recognize */
if (storage != NULL) {
appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
fmtId(tbinfo->relname));
appendPQExpBuffer(q, "ALTER COLUMN %s ",
fmtId(tbinfo->attnames[j]));
appendPQExpBuffer(q, "SET STORAGE %s;\n",
storage);
}
}
} }
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: pg_dump.h,v 1.100 2002/10/09 16:20:25 momjian Exp $ * $Id: pg_dump.h,v 1.101 2003/03/20 06:26:30 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -128,6 +128,8 @@ typedef struct _tableInfo ...@@ -128,6 +128,8 @@ typedef struct _tableInfo
char **atttypnames; /* attribute type names */ char **atttypnames; /* attribute type names */
int *atttypmod; /* type-specific type modifiers */ int *atttypmod; /* type-specific type modifiers */
int *attstattarget; /* attribute statistics targets */ int *attstattarget; /* attribute statistics targets */
char *attstorage; /* attribute storage scheme */
char *typstorage; /* type storage scheme */
bool *attisdropped; /* true if attr is dropped; don't dump it */ bool *attisdropped; /* true if attr is dropped; don't dump it */
bool *attislocal; /* true if attr has local definition */ bool *attislocal; /* true if attr has local definition */
bool *attisserial; /* true if attr is serial or bigserial */ bool *attisserial; /* true if attr is serial or bigserial */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment