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

Commita1ec740

Browse files
committed
Revert "Make pg_dump emit ATTACH PARTITION instead of PARTITION OF"
... and fallout (from branches 10, 11 and master). The change wasill-considered, and it broke a few normal use cases; since we don't havetime to fix it, we'll try again after this week's minor releases.Reported-by: Rushabh LathiaDiscussion:https://postgr.es/m/CAGPqQf0iQV=PPOv2Btog9J9AwOQp6HmuVd6SbGTR_v3Zp2XT1w@mail.gmail.com
1 parent9124860 commita1ec740

File tree

2 files changed

+75
-60
lines changed

2 files changed

+75
-60
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 72 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8602,12 +8602,9 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
86028602
* Normally this is always true, but it's false for dropped columns, as well
86038603
* as those that were inherited without any local definition. (If we print
86048604
* such a column it will mistakenly get pg_attribute.attislocal set to true.)
8605-
* For partitions, it's always true, because we want the partitions to be
8606-
* created independently and ATTACH PARTITION used afterwards.
8607-
*
8608-
* In binary_upgrade mode, we must print all columns and fix the attislocal/
8609-
* attisdropped state later, so as to keep control of the physical column
8610-
* order.
8605+
* However, in binary_upgrade mode, we must print all such columns anyway and
8606+
* fix the attislocal/attisdropped state later, so as to keep control of the
8607+
* physical column order.
86118608
*
86128609
* This function exists because there are scattered nonobvious places that
86138610
* must be kept in sync with this decision.
@@ -8617,9 +8614,7 @@ shouldPrintColumn(DumpOptions *dopt, TableInfo *tbinfo, int colno)
86178614
{
86188615
if (dopt->binary_upgrade)
86198616
return true;
8620-
if (tbinfo->attisdropped[colno])
8621-
return false;
8622-
return (tbinfo->attislocal[colno] || tbinfo->ispartition);
8617+
return (tbinfo->attislocal[colno] && !tbinfo->attisdropped[colno]);
86238618
}
86248619

86258620

@@ -15570,6 +15565,27 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1557015565
if (tbinfo->reloftype && !dopt->binary_upgrade)
1557115566
appendPQExpBuffer(q, " OF %s", tbinfo->reloftype);
1557215567

15568+
/*
15569+
* If the table is a partition, dump it as such; except in the case of
15570+
* a binary upgrade, we dump the table normally and attach it to the
15571+
* parent afterward.
15572+
*/
15573+
if (tbinfo->ispartition && !dopt->binary_upgrade)
15574+
{
15575+
TableInfo *parentRel = tbinfo->parents[0];
15576+
15577+
/*
15578+
* With partitions, unlike inheritance, there can only be one
15579+
* parent.
15580+
*/
15581+
if (tbinfo->numParents != 1)
15582+
fatal("invalid number of parents %d for table \"%s\"",
15583+
tbinfo->numParents, tbinfo->dobj.name);
15584+
15585+
appendPQExpBuffer(q, " PARTITION OF %s",
15586+
fmtQualifiedDumpable(parentRel));
15587+
}
15588+
1557315589
if (tbinfo->relkind != RELKIND_MATVIEW)
1557415590
{
1557515591
/* Dump the attributes */
@@ -15598,9 +15614,12 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1559815614
(!tbinfo->inhNotNull[j] ||
1559915615
dopt->binary_upgrade));
1560015616

15601-
/* Skip column if fully defined by reloftype */
15602-
if (tbinfo->reloftype && !has_default && !has_notnull &&
15603-
!dopt->binary_upgrade)
15617+
/*
15618+
* Skip column if fully defined by reloftype or the
15619+
* partition parent.
15620+
*/
15621+
if ((tbinfo->reloftype || tbinfo->ispartition) &&
15622+
!has_default && !has_notnull && !dopt->binary_upgrade)
1560415623
continue;
1560515624

1560615625
/* Format properly if not first attr */
@@ -15623,16 +15642,20 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1562315642
* clean things up later.
1562415643
*/
1562515644
appendPQExpBufferStr(q, " INTEGER /* dummy */");
15626-
/*and skip tothenext column */
15645+
/*Skip alltherest, too */
1562715646
continue;
1562815647
}
1562915648

1563015649
/*
15631-
* Attribute type; print it except when creating a typed
15632-
* table ('OF type_name'), but in binary-upgrade mode,
15633-
* print it in that case too.
15650+
* Attribute type
15651+
*
15652+
* In binary-upgrade mode, we always include the type. If
15653+
* we aren't in binary-upgrade mode, then we skip the type
15654+
* when creating a typed table ('OF type_name') or a
15655+
* partition ('PARTITION OF'), since the type comes from
15656+
* the parent/partitioned table.
1563415657
*/
15635-
if (dopt->binary_upgrade || !tbinfo->reloftype)
15658+
if (dopt->binary_upgrade ||(!tbinfo->reloftype && !tbinfo->ispartition))
1563615659
{
1563715660
appendPQExpBuffer(q, " %s",
1563815661
tbinfo->atttypnames[j]);
@@ -15689,20 +15712,25 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1568915712

1569015713
if (actual_atts)
1569115714
appendPQExpBufferStr(q, "\n)");
15692-
else if (!(tbinfo->reloftype && !dopt->binary_upgrade))
15715+
else if (!((tbinfo->reloftype || tbinfo->ispartition) &&
15716+
!dopt->binary_upgrade))
1569315717
{
1569415718
/*
15695-
*No attributes? wemust have a parenthesized attribute list,
15696-
*even thoughempty, when not using the OF TYPE syntax.
15719+
*Wemust have a parenthesized attribute list, even though
15720+
* empty, when not using the OF TYPE or PARTITION OF syntax.
1569715721
*/
1569815722
appendPQExpBufferStr(q, " (\n)");
1569915723
}
1570015724

15701-
/*
15702-
* Emit the INHERITS clause (not for partitions), except in
15703-
* binary-upgrade mode.
15704-
*/
15705-
if (numParents > 0 && !tbinfo->ispartition &&
15725+
if (tbinfo->ispartition && !dopt->binary_upgrade)
15726+
{
15727+
appendPQExpBufferChar(q, '\n');
15728+
appendPQExpBufferStr(q, tbinfo->partbound);
15729+
}
15730+
15731+
/* Emit the INHERITS clause, except if this is a partition. */
15732+
if (numParents > 0 &&
15733+
!tbinfo->ispartition &&
1570615734
!dopt->binary_upgrade)
1570715735
{
1570815736
appendPQExpBufferStr(q, "\nINHERITS (");
@@ -15875,16 +15903,30 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1587515903
appendPQExpBufferStr(q, "::pg_catalog.regclass;\n");
1587615904
}
1587715905

15878-
if (numParents > 0 && !tbinfo->ispartition)
15906+
if (numParents > 0)
1587915907
{
15880-
appendPQExpBufferStr(q, "\n-- For binary upgrade, set up inheritance this way.\n");
15908+
appendPQExpBufferStr(q, "\n-- For binary upgrade, set up inheritanceand partitioningthis way.\n");
1588115909
for (k = 0; k < numParents; k++)
1588215910
{
1588315911
TableInfo *parentRel = parents[k];
1588415912

15885-
appendPQExpBuffer(q, "ALTER TABLE ONLY %s INHERIT %s;\n",
15886-
qualrelname,
15887-
fmtQualifiedDumpable(parentRel));
15913+
/* In the partitioning case, we alter the parent */
15914+
if (tbinfo->ispartition)
15915+
appendPQExpBuffer(q,
15916+
"ALTER TABLE ONLY %s ATTACH PARTITION ",
15917+
fmtQualifiedDumpable(parentRel));
15918+
else
15919+
appendPQExpBuffer(q, "ALTER TABLE ONLY %s INHERIT ",
15920+
qualrelname);
15921+
15922+
/* Partition needs specifying the bounds */
15923+
if (tbinfo->ispartition)
15924+
appendPQExpBuffer(q, "%s %s;\n",
15925+
qualrelname,
15926+
tbinfo->partbound);
15927+
else
15928+
appendPQExpBuffer(q, "%s;\n",
15929+
fmtQualifiedDumpable(parentRel));
1588815930
}
1588915931
}
1589015932

@@ -15897,27 +15939,6 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1589715939
}
1589815940
}
1589915941

15900-
/*
15901-
* For partitioned tables, emit the ATTACH PARTITION clause. Note
15902-
* that we always want to create partitions this way instead of using
15903-
* CREATE TABLE .. PARTITION OF, mainly to preserve a possible column
15904-
* layout discrepancy with the parent, but also to ensure it gets the
15905-
* correct tablespace setting if it differs from the parent's.
15906-
*/
15907-
if (tbinfo->ispartition)
15908-
{
15909-
/* With partitions there can only be one parent */
15910-
if (tbinfo->numParents != 1)
15911-
fatal("invalid number of parents %d for table \"%s\"",
15912-
tbinfo->numParents, tbinfo->dobj.name);
15913-
15914-
/* Perform ALTER TABLE on the parent */
15915-
appendPQExpBuffer(q,
15916-
"ALTER TABLE ONLY %s ATTACH PARTITION %s %s;\n",
15917-
fmtQualifiedDumpable(parents[0]),
15918-
qualrelname, tbinfo->partbound);
15919-
}
15920-
1592115942
/*
1592215943
* In binary_upgrade mode, arrange to restore the old relfrozenxid and
1592315944
* relminmxid of all vacuumable relations. (While vacuum.c processes

‎src/bin/pg_dump/t/002_pg_dump.pl

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -733,12 +733,7 @@
733733
\QALTER TABLE ONLY dump_test.measurement ATTACH PARTITION dump_test_second_schema.measurement_y2006m2\E
734734
\QFOR VALUES FROM ('2006-02-01') TO ('2006-03-01');\E\n
735735
/xm,
736-
like=> {
737-
%full_runs,
738-
role=> 1,
739-
section_pre_data=> 1,
740-
binary_upgrade=> 1,
741-
},
736+
like=> {binary_upgrade=> 1, },
742737
},
743738

744739
'ALTER TABLE test_table CLUSTER ON test_table_pkey'=> {
@@ -2327,13 +2322,12 @@
23272322
\)\n
23282323
\QFOR VALUES FROM ('2006-02-01') TO ('2006-03-01');\E\n
23292324
/xm,
2330-
like => {},
2331-
unlike => {
2325+
like => {
23322326
%full_runs,
23332327
role => 1,
23342328
section_pre_data => 1,
2335-
binary_upgrade => 1,
23362329
},
2330+
unlike => { binary_upgrade => 1, },
23372331
},
23382332
23392333
'CREATE TABLE test_fourth_table_zero_col' => {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp