Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ba8e20a

Browse files
committed
> Alvaro Herrera <alvherre@atentus.com> writes:
> > I'm looking at pg_dump/common.c:flagInhAttrs() and suspect that it can > > be more or less rewritten completely, and probably should to get rigth > > all the cases mentioned in the past attisinherited discussion. Is this > > desirable for 7.3? It can probably be hacked around and the rewrite > > kept for 7.4, but I think it will be much simpler after the rewrite. > > If it's a bug then it's fair game to fix in 7.3. But keep in mind that > pg_dump has to behave at least somewhat sanely when called against older > servers ... will your rewrite behave reasonably if the server does not > offer attinhcount values? Nah. I don't think it's worth it: I had forgotten that older versions should be supported. I just left the code as is and added a version-specific test. This patch allows pg_dump to dump correctly local definition of columns. In particular, CREATE TABLE p1 (f1 int, f2 int); CREATE TABLE p2 (f1 int); CREATE TABLE c () INHERITS (p1, p2); ALTER TABLE ONLY p1 DROP COLUMN f1; CREATE TABLE p3 (f1 int); CREATE TABLE c2 (f1 int) INHERITS (p3); Will be dumped as CREATE TABLE p1 (f2 int); CREATE TABLE p2 (f1 int); CREATE TABLE c (f1 int) INHERITS (p1, p2); CREATE TABLE c2 (f1 int) INHERITS (p3); (Previous version will dump CREATE TABLE c () INHERITS (p1, p2) CREATE TABLE c2 () INHERITS (p3) ) Alvaro Herrera
1 parent d015dcb commit ba8e20a

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

src/bin/pg_dump/common.c

+13-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.70 2002/09/04 20:31:34 momjian Exp $
14+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.71 2002/10/09 16:20:25 momjian Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -284,16 +284,18 @@ flagInhAttrs(TableInfo *tblinfo, int numTables,
284284
if (numParents == 0)
285285
continue; /* nothing to see here, move along */
286286

287-
/*
287+
/*----------------------------------------------------------------
288288
* For each attr, check the parent info: if no parent has an attr
289289
* with the same name, then it's not inherited. If there *is* an
290290
* attr with the same name, then only dump it if:
291291
*
292-
* - it is NOT NULL and zero parents are NOT NULL OR - it has a
293-
* default value AND the default value does not match all parent
294-
* default values, or no parents specify a default.
292+
* - it is NOT NULL and zero parents are NOT NULL
293+
* OR
294+
* - it has a default value AND the default value does not match
295+
* all parent default values, or no parents specify a default.
295296
*
296297
* See discussion on -hackers around 2-Apr-2001.
298+
*----------------------------------------------------------------
297299
*/
298300
for (j = 0; j < tblinfo[i].numatts; j++)
299301
{
@@ -359,6 +361,12 @@ flagInhAttrs(TableInfo *tblinfo, int numTables,
359361
tblinfo[i].inhAttrs[j] = false;
360362
tblinfo[i].inhNotNull[j] = false;
361363
}
364+
365+
/* Clear it if attr has local definition */
366+
if (g_fout->remoteVersion >= 70300 && tblinfo[i].attislocal[j])
367+
{
368+
tblinfo[i].inhAttrs[j] = false;
369+
}
362370
}
363371
}
364372
}

src/bin/pg_dump/pg_dump.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.301 2002/09/24 23:14:25 tgl Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.302 2002/10/09 16:20:25 momjian Exp $
2626
*
2727
*-------------------------------------------------------------------------
2828
*/
@@ -2356,6 +2356,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
23562356
int i_attnotnull;
23572357
int i_atthasdef;
23582358
int i_attisdropped;
2359+
int i_attislocal;
23592360
PGresult *res;
23602361
int ntups;
23612362
bool hasdefaults;
@@ -2397,7 +2398,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
23972398
if (g_fout->remoteVersion >= 70300)
23982399
{
23992400
appendPQExpBuffer(q, "SELECT attnum, attname, atttypmod, attstattarget, "
2400-
"attnotnull, atthasdef, attisdropped, "
2401+
"attnotnull, atthasdef, attisdropped, attislocal, "
24012402
"pg_catalog.format_type(atttypid,atttypmod) as atttypname "
24022403
"from pg_catalog.pg_attribute a "
24032404
"where attrelid = '%s'::pg_catalog.oid "
@@ -2413,7 +2414,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
24132414
* been explicitly set or was just a default.
24142415
*/
24152416
appendPQExpBuffer(q, "SELECT attnum, attname, atttypmod, -1 as attstattarget, "
2416-
"attnotnull, atthasdef, false as attisdropped, "
2417+
"attnotnull, atthasdef, false as attisdropped, null as attislocal, "
24172418
"format_type(atttypid,atttypmod) as atttypname "
24182419
"from pg_attribute a "
24192420
"where attrelid = '%s'::oid "
@@ -2425,7 +2426,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
24252426
{
24262427
/* format_type not available before 7.1 */
24272428
appendPQExpBuffer(q, "SELECT attnum, attname, atttypmod, -1 as attstattarget, "
2428-
"attnotnull, atthasdef, false as attisdropped, "
2429+
"attnotnull, atthasdef, false as attisdropped, null as attislocal, "
24292430
"(select typname from pg_type where oid = atttypid) as atttypname "
24302431
"from pg_attribute a "
24312432
"where attrelid = '%s'::oid "
@@ -2451,13 +2452,15 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
24512452
i_attnotnull = PQfnumber(res, "attnotnull");
24522453
i_atthasdef = PQfnumber(res, "atthasdef");
24532454
i_attisdropped = PQfnumber(res, "attisdropped");
2455+
i_attislocal = PQfnumber(res, "attislocal");
24542456

24552457
tbinfo->numatts = ntups;
24562458
tbinfo->attnames = (char **) malloc(ntups * sizeof(char *));
24572459
tbinfo->atttypnames = (char **) malloc(ntups * sizeof(char *));
24582460
tbinfo->atttypmod = (int *) malloc(ntups * sizeof(int));
24592461
tbinfo->attstattarget = (int *) malloc(ntups * sizeof(int));
24602462
tbinfo->attisdropped = (bool *) malloc(ntups * sizeof(bool));
2463+
tbinfo->attislocal = (bool *) malloc(ntups * sizeof(bool));
24612464
tbinfo->attisserial = (bool *) malloc(ntups * sizeof(bool));
24622465
tbinfo->notnull = (bool *) malloc(ntups * sizeof(bool));
24632466
tbinfo->adef_expr = (char **) malloc(ntups * sizeof(char *));
@@ -2473,6 +2476,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
24732476
tbinfo->atttypmod[j] = atoi(PQgetvalue(res, j, i_atttypmod));
24742477
tbinfo->attstattarget[j] = atoi(PQgetvalue(res, j, i_attstattarget));
24752478
tbinfo->attisdropped[j] = (PQgetvalue(res, j, i_attisdropped)[0] == 't');
2479+
tbinfo->attislocal[j] = (PQgetvalue(res, j, i_attislocal)[0] == 't');
24762480
tbinfo->attisserial[j] = false; /* fix below */
24772481
tbinfo->notnull[j] = (PQgetvalue(res, j, i_attnotnull)[0] == 't');
24782482
tbinfo->adef_expr[j] = NULL; /* fix below */

src/bin/pg_dump/pg_dump.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: pg_dump.h,v 1.99 2002/09/04 20:31:35 momjian Exp $
9+
* $Id: pg_dump.h,v 1.100 2002/10/09 16:20:25 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -129,6 +129,7 @@ typedef struct _tableInfo
129129
int *atttypmod; /* type-specific type modifiers */
130130
int *attstattarget; /* attribute statistics targets */
131131
bool *attisdropped; /* true if attr is dropped; don't dump it */
132+
bool *attislocal; /* true if attr has local definition */
132133
bool *attisserial; /* true if attr is serial or bigserial */
133134

134135
/*

0 commit comments

Comments
 (0)