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

Commitab17fd1

Browse files
committed
- Handle overridden attrs as per discussions 2-Apr-2001
- Dump CHECK constraints in OID order
1 parent08bf4d7 commitab17fd1

File tree

4 files changed

+126
-26
lines changed

4 files changed

+126
-26
lines changed

‎src/bin/pg_dump/common.c

Lines changed: 107 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.54 2001/03/22 04:00:11 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.55 2001/04/03 08:52:59 pjw Exp $
1212
*
1313
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
1414
*
@@ -21,6 +21,10 @@
2121
*string to return - formatted type, or base type. If the base type
2222
*is returned then fmtId is called on the string.
2323
*
24+
* Modifications 4-Apr-2001 - pjw@rhyme.com.au
25+
*-Changed flagInhAttrs to check all parent tables for overridden settings
26+
*and set flags accordingly.
27+
*
2428
*BEWARE: Since fmtId uses a static buffer, using 'useBaseTypeName' on more
2529
*than one call in a line will cause problems.
2630
*
@@ -39,7 +43,8 @@
3943
staticchar**findParentsByOid(TableInfo*tbinfo,intnumTables,
4044
InhInfo*inhinfo,intnumInherits,
4145
constchar*oid,
42-
int*numParents);
46+
int*numParents,
47+
int (**parentIndices)[]);
4348
staticintfindTableByOid(TableInfo*tbinfo,intnumTables,constchar*oid);
4449
staticvoidflagInhAttrs(TableInfo*tbinfo,intnumTables,
4550
InhInfo*inhinfo,intnumInherits);
@@ -122,7 +127,7 @@ findOprByOid(OprInfo *oprinfo, int numOprs, const char *oid)
122127
/*
123128
* findParentsByOid
124129
* given the oid of a class, return the names of its parent classes
125-
* and assign the number of parentsto the lastargument.
130+
* and assign the number of parents, and parent indicesto the lastarguments.
126131
*
127132
*
128133
* returns NULL if none
@@ -131,7 +136,7 @@ findOprByOid(OprInfo *oprinfo, int numOprs, const char *oid)
131136
staticchar**
132137
findParentsByOid(TableInfo*tblinfo,intnumTables,
133138
InhInfo*inhinfo,intnumInherits,constchar*oid,
134-
int*numParentsPtr)
139+
int*numParentsPtr,int (**parentIndices)[])
135140
{
136141
inti,
137142
j;
@@ -152,6 +157,7 @@ findParentsByOid(TableInfo *tblinfo, int numTables,
152157
if (numParents>0)
153158
{
154159
result= (char**)malloc(sizeof(char*)*numParents);
160+
(*parentIndices)=malloc(sizeof(int)*numParents);
155161
j=0;
156162
for (i=0;i<numInherits;i++)
157163
{
@@ -169,13 +175,17 @@ findParentsByOid(TableInfo *tblinfo, int numTables,
169175
oid);
170176
exit(2);
171177
}
178+
(**parentIndices)[j]=parentInd;
172179
result[j++]=tblinfo[parentInd].relname;
173180
}
174181
}
175182
returnresult;
176183
}
177184
else
185+
{
186+
(*parentIndices)=NULL;
178187
returnNULL;
188+
}
179189
}
180190

181191
/*
@@ -415,6 +425,14 @@ flagInhAttrs(TableInfo *tblinfo, int numTables,
415425
j,
416426
k;
417427
intparentInd;
428+
intinhAttrInd;
429+
int(*parentIndices)[];
430+
boolfoundAttr;/* Attr was found in a parent */
431+
boolfoundNotNull;/* Attr was NOT NULL in a parent */
432+
booldefaultsMatch;/* All non-empty defaults match */
433+
booldefaultsFound;/* Found a default in a parent */
434+
char*attrDef;
435+
char*inhDef;
418436

419437
/*
420438
* we go backwards because the tables in tblinfo are in OID order,
@@ -423,27 +441,97 @@ flagInhAttrs(TableInfo *tblinfo, int numTables,
423441
*/
424442
for (i=numTables-1;i >=0;i--)
425443
{
444+
445+
/* Sequences can never have parents, and attr info is undefined */
446+
if (tblinfo[i].sequence)
447+
continue;
448+
449+
/* Get all the parents and their indexes. */
426450
tblinfo[i].parentRels=findParentsByOid(tblinfo,numTables,
427451
inhinfo,numInherits,
428452
tblinfo[i].oid,
429-
&tblinfo[i].numParents);
430-
for (k=0;k<tblinfo[i].numParents;k++)
453+
&tblinfo[i].numParents,
454+
&parentIndices);
455+
456+
/*
457+
* For each attr, check the parent info: if no parent has
458+
* an attr with the same name, then it's not inherited. If there
459+
* *is* an attr with the same name, then only dump it if:
460+
*
461+
* - it is NOT NULL and zero parents are NOT NULL
462+
* OR
463+
* - it has a default value AND the default value
464+
* does not match all parent default values, or
465+
* no parents specify a default.
466+
*
467+
* See discussion on -hackers around 2-Apr-2001.
468+
*/
469+
for (j=0;j<tblinfo[i].numatts;j++)
431470
{
432-
parentInd=findTableByName(tblinfo,numTables,
433-
tblinfo[i].parentRels[k]);
434-
if (parentInd<0)
471+
foundAttr= false;
472+
foundNotNull= false;
473+
defaultsMatch= true;
474+
defaultsFound= false;
475+
476+
attrDef=tblinfo[i].adef_expr[j];
477+
478+
for (k=0;k<tblinfo[i].numParents;k++)
435479
{
436-
/* shouldn't happen unless findParentsByOid is broken */
437-
fprintf(stderr,"failed sanity check, table %s not found by flagInhAttrs\n",
438-
tblinfo[i].parentRels[k]);
439-
exit(2);
440-
}
441-
for (j=0;j<tblinfo[i].numatts;j++)
480+
parentInd= (*parentIndices)[k];
481+
482+
if (parentInd<0)
483+
{
484+
/* shouldn't happen unless findParentsByOid is broken */
485+
fprintf(stderr,"failed sanity check, table %s not found by flagInhAttrs\n",
486+
tblinfo[i].parentRels[k]);
487+
exit(2);
488+
};
489+
490+
inhAttrInd=strInArray(tblinfo[i].attnames[j],
491+
tblinfo[parentInd].attnames,
492+
tblinfo[parentInd].numatts);
493+
494+
if (inhAttrInd!=-1)
495+
{
496+
foundAttr= true;
497+
foundNotNull |=tblinfo[parentInd].notnull[inhAttrInd];
498+
if (attrDef!=NULL)/* It we have a default, check parent */
499+
{
500+
inhDef=tblinfo[parentInd].adef_expr[inhAttrInd];
501+
502+
if (inhDef!=NULL)
503+
{
504+
defaultsFound= true;
505+
defaultsMatch &= (strcmp(attrDef,inhDef)==0);
506+
};
507+
};
508+
};
509+
};
510+
511+
/*
512+
* Based on the scan of the parents, decide if we
513+
* can rely on the inherited attr
514+
*/
515+
if (foundAttr)/* Attr was inherited */
442516
{
443-
if (strInArray(tblinfo[i].attnames[j],
444-
tblinfo[parentInd].attnames,
445-
tblinfo[parentInd].numatts)!=-1)
446-
tblinfo[i].inhAttrs[j]=1;
517+
/* Set inherited flag by default */
518+
tblinfo[i].inhAttrs[j]=1;
519+
tblinfo[i].inhAttrDef[j]=1;
520+
tblinfo[i].inhNotNull[j]=1;
521+
522+
/* Clear it if attr had a default, but parents did not, or mismatch */
523+
if ( (attrDef!=NULL)&& (!defaultsFound|| !defaultsMatch) )
524+
{
525+
tblinfo[i].inhAttrs[j]=0;
526+
tblinfo[i].inhAttrDef[j]=0;
527+
}
528+
529+
/* Clear it if NOT NULL and none of the parents were NOT NULL */
530+
if (tblinfo[i].notnull[j]&& !foundNotNull)
531+
{
532+
tblinfo[i].inhAttrs[j]=0;
533+
tblinfo[i].inhNotNull[j]=0;
534+
}
447535
}
448536
}
449537
}

‎src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
*
1919
* IDENTIFICATION
20-
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.28 2001/04/01 05:42:51 pjw Exp $
20+
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.29 2001/04/03 08:52:59 pjw Exp $
2121
*
2222
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
2323
*-Initial version.
@@ -68,7 +68,7 @@ typedef z_stream *z_streamp;
6868

6969
#defineK_VERS_MAJOR 1
7070
#defineK_VERS_MINOR 5
71-
#defineK_VERS_REV0
71+
#defineK_VERS_REV1
7272

7373
/* Data block types */
7474
#defineBLK_DATA 1

‎src/bin/pg_dump/pg_dump.c

Lines changed: 14 additions & 4 deletions
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.198 2001/04/01 05:42:51 pjw Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.199 2001/04/03 08:52:59 pjw Exp $
2626
*
2727
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2828
*
@@ -1603,6 +1603,10 @@ clearTableInfo(TableInfo *tblinfo, int numTables)
16031603
free((int*)tblinfo[i].atttypmod);
16041604
if (tblinfo[i].inhAttrs)
16051605
free((int*)tblinfo[i].inhAttrs);
1606+
if (tblinfo[i].inhAttrDef)
1607+
free((int*)tblinfo[i].inhAttrDef);
1608+
if (tblinfo[i].inhNotNull)
1609+
free((int*)tblinfo[i].inhNotNull);
16061610
if (tblinfo[i].attnames)
16071611
free(tblinfo[i].attnames);
16081612
if (tblinfo[i].atttypedefns)
@@ -2138,7 +2142,8 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
21382142
" where i.inhrelid = pg_relcheck.rcrelid "
21392143
" and c.rcname = pg_relcheck.rcname "
21402144
" and c.rcsrc = pg_relcheck.rcsrc "
2141-
" and c.rcrelid = i.inhparent) ",
2145+
" and c.rcrelid = i.inhparent) "
2146+
" Order By oid ",
21422147
tblinfo[i].oid);
21432148
res2=PQexec(g_conn,query->data);
21442149
if (!res2||
@@ -2656,6 +2661,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
26562661
tblinfo[i].typnames= (char**)malloc(ntups*sizeof(char*));
26572662
tblinfo[i].atttypmod= (int*)malloc(ntups*sizeof(int));
26582663
tblinfo[i].inhAttrs= (int*)malloc(ntups*sizeof(int));
2664+
tblinfo[i].inhAttrDef= (int*)malloc(ntups*sizeof(int));
2665+
tblinfo[i].inhNotNull= (int*)malloc(ntups*sizeof(int));
26592666
tblinfo[i].notnull= (bool*)malloc(ntups*sizeof(bool));
26602667
tblinfo[i].adef_expr= (char**)malloc(ntups*sizeof(char*));
26612668
tblinfo[i].parentRels=NULL;
@@ -2678,6 +2685,9 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
26782685
tblinfo[i].atttypmod[j]=atoi(PQgetvalue(res,j,i_atttypmod));
26792686
tblinfo[i].inhAttrs[j]=0;/* this flag is set in
26802687
* flagInhAttrs() */
2688+
tblinfo[i].inhAttrDef[j]=0;
2689+
tblinfo[i].inhNotNull[j]=0;
2690+
26812691
tblinfo[i].notnull[j]= (PQgetvalue(res,j,i_attnotnull)[0]=='t') ? true : false;
26822692
if (PQgetvalue(res,j,i_atthasdef)[0]=='t')
26832693
{
@@ -3829,12 +3839,12 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
38293839
tblinfo[i].atttypedefns[j]);
38303840

38313841
/* Default value */
3832-
if (tblinfo[i].adef_expr[j]!=NULL)
3842+
if (tblinfo[i].adef_expr[j]!=NULL&&tblinfo[i].inhAttrDef[j]==0)
38333843
appendPQExpBuffer(q," DEFAULT %s",
38343844
tblinfo[i].adef_expr[j]);
38353845

38363846
/* Not Null constraint */
3837-
if (tblinfo[i].notnull[j])
3847+
if (tblinfo[i].notnull[j]&&tblinfo[i].inhNotNull[j]==0)
38383848
appendPQExpBuffer(q," NOT NULL");
38393849

38403850
actual_atts++;

‎src/bin/pg_dump/pg_dump.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: pg_dump.h,v 1.60 2001/03/23 04:49:56 momjian Exp $
9+
* $Id: pg_dump.h,v 1.61 2001/04/03 08:52:59 pjw Exp $
1010
*
1111
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
1212
*
@@ -93,6 +93,8 @@ typedef struct _tableInfo
9393
int*inhAttrs;/* an array of flags, one for each
9494
* attribute if the value is 1, then this
9595
* attribute is an inherited attribute */
96+
int*inhAttrDef;/* Flags indicating if attrdef is inherited */
97+
int*inhNotNull;/* Flags indicating if NOT NULL in inherited */
9698
char**attnames;/* the attribute names */
9799
char**attoids;/* oids of the various attributes */
98100
char**atttypedefns;/* formatted column type definitions */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp