@ -8618,9 +8618,12 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
* Normally this is always true , but it ' s false for dropped columns , as well
* Normally this is always true , but it ' s false for dropped columns , as well
* as those that were inherited without any local definition . ( If we print
* as those that were inherited without any local definition . ( If we print
* such a column it will mistakenly get pg_attribute . attislocal set to true . )
* such a column it will mistakenly get pg_attribute . attislocal set to true . )
* However , in binary_upgrade mode , we must print all such columns anyway and
* For partitions , it ' s always true , because we want the partitions to be
* fix the attislocal / attisdropped state later , so as to keep control of the
* created independently and ATTACH PARTITION used afterwards .
* physical column order .
*
* In binary_upgrade mode , we must print all columns and fix the attislocal /
* attisdropped state later , so as to keep control of the physical column
* order .
*
*
* This function exists because there are scattered nonobvious places that
* This function exists because there are scattered nonobvious places that
* must be kept in sync with this decision .
* must be kept in sync with this decision .
@ -8630,7 +8633,9 @@ shouldPrintColumn(DumpOptions *dopt, TableInfo *tbinfo, int colno)
{
{
if ( dopt - > binary_upgrade )
if ( dopt - > binary_upgrade )
return true ;
return true ;
return ( tbinfo - > attislocal [ colno ] & & ! tbinfo - > attisdropped [ colno ] ) ;
if ( tbinfo - > attisdropped [ colno ] )
return false ;
return ( tbinfo - > attislocal [ colno ] | | tbinfo - > ispartition ) ;
}
}
@ -15599,27 +15604,6 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
if ( tbinfo - > reloftype & & ! dopt - > binary_upgrade )
if ( tbinfo - > reloftype & & ! dopt - > binary_upgrade )
appendPQExpBuffer ( q , " OF %s " , tbinfo - > reloftype ) ;
appendPQExpBuffer ( q , " OF %s " , tbinfo - > reloftype ) ;
/*
* If the table is a partition , dump it as such ; except in the case of
* a binary upgrade , we dump the table normally and attach it to the
* parent afterward .
*/
if ( tbinfo - > ispartition & & ! dopt - > binary_upgrade )
{
TableInfo * parentRel = tbinfo - > parents [ 0 ] ;
/*
* With partitions , unlike inheritance , there can only be one
* parent .
*/
if ( tbinfo - > numParents ! = 1 )
fatal ( " invalid number of parents %d for table \" %s \" " ,
tbinfo - > numParents , tbinfo - > dobj . name ) ;
appendPQExpBuffer ( q , " PARTITION OF %s " ,
fmtQualifiedDumpable ( parentRel ) ) ;
}
if ( tbinfo - > relkind ! = RELKIND_MATVIEW )
if ( tbinfo - > relkind ! = RELKIND_MATVIEW )
{
{
/* Dump the attributes */
/* Dump the attributes */
@ -15648,12 +15632,9 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
( ! tbinfo - > inhNotNull [ j ] | |
( ! tbinfo - > inhNotNull [ j ] | |
dopt - > binary_upgrade ) ) ;
dopt - > binary_upgrade ) ) ;
/*
/* Skip column if fully defined by reloftype */
* Skip column if fully defined by reloftype or the
if ( tbinfo - > reloftype & & ! has_default & & ! has_notnull & &
* partition parent .
! dopt - > binary_upgrade )
*/
if ( ( tbinfo - > reloftype | | tbinfo - > ispartition ) & &
! has_default & & ! has_notnull & & ! dopt - > binary_upgrade )
continue ;
continue ;
/* Format properly if not first attr */
/* Format properly if not first attr */
@ -15676,20 +15657,16 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
* clean things up later .
* clean things up later .
*/
*/
appendPQExpBufferStr ( q , " INTEGER /* dummy */ " ) ;
appendPQExpBufferStr ( q , " INTEGER /* dummy */ " ) ;
/* Skip all the rest, too */
/* and skip to the next column */
continue ;
continue ;
}
}
/*
/*
* Attribute type
* Attribute type ; print it except when creating a typed
*
* table ( ' OF type_name ' ) , but in binary - upgrade mode ,
* In binary - upgrade mode , we always include the type . If
* print it in that case too .
* we aren ' t in binary - upgrade mode , then we skip the type
* when creating a typed table ( ' OF type_name ' ) or a
* partition ( ' PARTITION OF ' ) , since the type comes from
* the parent / partitioned table .
*/
*/
if ( dopt - > binary_upgrade | | ( ! tbinfo - > reloftype & & ! tbinfo - > ispartition ) )
if ( dopt - > binary_upgrade | | ! tbinfo - > reloftype )
{
{
appendPQExpBuffer ( q , " %s " ,
appendPQExpBuffer ( q , " %s " ,
tbinfo - > atttypnames [ j ] ) ;
tbinfo - > atttypnames [ j ] ) ;
@ -15746,25 +15723,20 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
if ( actual_atts )
if ( actual_atts )
appendPQExpBufferStr ( q , " \n ) " ) ;
appendPQExpBufferStr ( q , " \n ) " ) ;
else if ( ! ( ( tbinfo - > reloftype | | tbinfo - > ispartition ) & &
else if ( ! ( tbinfo - > reloftype & & ! dopt - > binary_upgrade ) )
! dopt - > binary_upgrade ) )
{
{
/*
/*
* W e must have a parenthesized attribute list , even though
* No attributes ? w e must have a parenthesized attribute list ,
* empty , when not using the OF TYPE or PARTITION OF syntax .
* even though e mpty , when not using the OF TYPE syntax .
*/
*/
appendPQExpBufferStr ( q , " ( \n ) " ) ;
appendPQExpBufferStr ( q , " ( \n ) " ) ;
}
}
if ( tbinfo - > ispartition & & ! dopt - > binary_upgrade )
/*
{
* Emit the INHERITS clause ( not for partitions ) , except in
appendPQExpBufferChar ( q , ' \n ' ) ;
* binary - upgrade mode .
appendPQExpBufferStr ( q , tbinfo - > partbound ) ;
*/
}
if ( numParents > 0 & & ! tbinfo - > ispartition & &
/* Emit the INHERITS clause, except if this is a partition. */
if ( numParents > 0 & &
! tbinfo - > ispartition & &
! dopt - > binary_upgrade )
! dopt - > binary_upgrade )
{
{
appendPQExpBufferStr ( q , " \n INHERITS ( " ) ;
appendPQExpBufferStr ( q , " \n INHERITS ( " ) ;
@ -15937,30 +15909,16 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
appendPQExpBufferStr ( q , " ::pg_catalog.regclass; \n " ) ;
appendPQExpBufferStr ( q , " ::pg_catalog.regclass; \n " ) ;
}
}
if ( numParents > 0 )
if ( numParents > 0 & & ! tbinfo - > ispartition )
{
{
appendPQExpBufferStr ( q , " \n -- For binary upgrade, set up inheritance and partitioning this way. \n " ) ;
appendPQExpBufferStr ( q , " \n -- For binary upgrade, set up inheritance this way. \n " ) ;
for ( k = 0 ; k < numParents ; k + + )
for ( k = 0 ; k < numParents ; k + + )
{
{
TableInfo * parentRel = parents [ k ] ;
TableInfo * parentRel = parents [ k ] ;
/* In the partitioning case, we alter the parent */
appendPQExpBuffer ( q , " ALTER TABLE ONLY %s INHERIT %s; \n " ,
if ( tbinfo - > ispartition )
qualrelname ,
appendPQExpBuffer ( q ,
fmtQualifiedDumpable ( parentRel ) ) ;
" ALTER TABLE ONLY %s ATTACH PARTITION " ,
fmtQualifiedDumpable ( parentRel ) ) ;
else
appendPQExpBuffer ( q , " ALTER TABLE ONLY %s INHERIT " ,
qualrelname ) ;
/* Partition needs specifying the bounds */
if ( tbinfo - > ispartition )
appendPQExpBuffer ( q , " %s %s; \n " ,
qualrelname ,
tbinfo - > partbound ) ;
else
appendPQExpBuffer ( q , " %s; \n " ,
fmtQualifiedDumpable ( parentRel ) ) ;
}
}
}
}
@ -15973,6 +15931,27 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
}
}
}
}
/*
* For partitioned tables , emit the ATTACH PARTITION clause . Note
* that we always want to create partitions this way instead of using
* CREATE TABLE . . PARTITION OF , mainly to preserve a possible column
* layout discrepancy with the parent , but also to ensure it gets the
* correct tablespace setting if it differs from the parent ' s .
*/
if ( tbinfo - > ispartition )
{
/* With partitions there can only be one parent */
if ( tbinfo - > numParents ! = 1 )
fatal ( " invalid number of parents %d for table \" %s \" " ,
tbinfo - > numParents , tbinfo - > dobj . name ) ;
/* Perform ALTER TABLE on the parent */
appendPQExpBuffer ( q ,
" ALTER TABLE ONLY %s ATTACH PARTITION %s %s; \n " ,
fmtQualifiedDumpable ( parents [ 0 ] ) ,
qualrelname , tbinfo - > partbound ) ;
}
/*
/*
* In binary_upgrade mode , arrange to restore the old relfrozenxid and
* In binary_upgrade mode , arrange to restore the old relfrozenxid and
* relminmxid of all vacuumable relations . ( While vacuum . c processes
* relminmxid of all vacuumable relations . ( While vacuum . c processes