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

Commit69d7edb

Browse files
committed
In pg_dump, don't dump a stats object unless dumping underlying table.
If the underlying table isn't being dumped, it's useless to dumpan extended statistics object; it'll just cause errors at restore.We have always applied similar policies to, say, indexes.(When and if we get cross-table stats objects, it might be profitableto think a little harder about what to do with them. But for nowthere seems no point in considering a stats object as anything butan appendage of its table.)Rian McGuire and Tom Lane, per report from Rian McGuire.Back-patch to supported branches.Discussion:https://postgr.es/m/7075d3aa-3f05-44a5-b68f-47dc6a8a0550@buildkite.com
1 parentb901961 commit69d7edb

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,26 @@ selectDumpablePublicationTable(DumpableObject *dobj, Archive *fout)
17611761
DUMP_COMPONENT_ALL : DUMP_COMPONENT_NONE;
17621762
}
17631763

1764+
/*
1765+
* selectDumpableStatisticsObject: policy-setting subroutine
1766+
*Mark an extended statistics object as to be dumped or not
1767+
*
1768+
* We dump an extended statistics object if the schema it's in and the table
1769+
* it's for are being dumped. (This'll need more thought if statistics
1770+
* objects ever support cross-table stats.)
1771+
*/
1772+
static void
1773+
selectDumpableStatisticsObject(StatsExtInfo *sobj, Archive *fout)
1774+
{
1775+
if (checkExtensionMembership(&sobj->dobj, fout))
1776+
return;/* extension membership overrides all else */
1777+
1778+
sobj->dobj.dump = sobj->dobj.namespace->dobj.dump_contains;
1779+
if (sobj->stattable == NULL ||
1780+
!(sobj->stattable->dobj.dump & DUMP_COMPONENT_DEFINITION))
1781+
sobj->dobj.dump = DUMP_COMPONENT_NONE;
1782+
}
1783+
17641784
/*
17651785
* selectDumpableObject: policy-setting subroutine
17661786
*Mark a generic dumpable object as to be dumped or not
@@ -7381,6 +7401,7 @@ getExtendedStatistics(Archive *fout)
73817401
inti_stxname;
73827402
inti_stxnamespace;
73837403
inti_rolname;
7404+
inti_stxrelid;
73847405
inti;
73857406

73867407
/* Extended statistics were new in v10 */
@@ -7390,7 +7411,7 @@ getExtendedStatistics(Archive *fout)
73907411
query = createPQExpBuffer();
73917412

73927413
appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
7393-
"stxnamespace, (%s stxowner) AS rolname "
7414+
"stxnamespace, (%s stxowner) AS rolname, stxrelid "
73947415
"FROM pg_catalog.pg_statistic_ext",
73957416
username_subquery);
73967417

@@ -7403,6 +7424,7 @@ getExtendedStatistics(Archive *fout)
74037424
i_stxname = PQfnumber(res, "stxname");
74047425
i_stxnamespace = PQfnumber(res, "stxnamespace");
74057426
i_rolname = PQfnumber(res, "rolname");
7427+
i_stxrelid = PQfnumber(res, "stxrelid");
74067428

74077429
statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
74087430

@@ -7417,9 +7439,11 @@ getExtendedStatistics(Archive *fout)
74177439
findNamespace(fout,
74187440
atooid(PQgetvalue(res, i, i_stxnamespace)));
74197441
statsextinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
7442+
statsextinfo[i].stattable =
7443+
findTableByOid(atooid(PQgetvalue(res, i, i_stxrelid)));
74207444

74217445
/* Decide whether we want to dump it */
7422-
selectDumpableObject(&(statsextinfo[i].dobj), fout);
7446+
selectDumpableStatisticsObject(&(statsextinfo[i]), fout);
74237447

74247448
/* Stats objects do not currently have ACLs. */
74257449
statsextinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;

‎src/bin/pg_dump/pg_dump.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ typedef struct _statsExtInfo
390390
{
391391
DumpableObjectdobj;
392392
char*rolname;/* name of owner, or empty string */
393+
TableInfo*stattable;/* link to table the stats are for */
393394
}StatsExtInfo;
394395

395396
typedefstruct_ruleInfo

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,13 +2737,13 @@
27372737
'CREATE STATISTICS extended_stats_no_options' => {
27382738
create_order => 97,
27392739
create_sql => 'CREATE STATISTICS dump_test.test_ext_stats_no_options
2740-
ON col1, col2 FROM dump_test.test_fifth_table',
2740+
ON col1, col2 FROM dump_test.test_table',
27412741
regexp => qr/^
2742-
\QCREATE STATISTICS dump_test.test_ext_stats_no_options ON col1, col2 FROM dump_test.test_fifth_table;\E
2742+
\QCREATE STATISTICS dump_test.test_ext_stats_no_options ON col1, col2 FROM dump_test.test_table;\E
27432743
/xms,
27442744
like =>
27452745
{%full_runs,%dump_test_schema_runs, section_post_data => 1, },
2746-
unlike => { exclude_dump_test_schema => 1, },
2746+
unlike => { exclude_dump_test_schema => 1,exclude_test_table => 1,},
27472747
},
27482748
27492749
'CREATE STATISTICS extended_stats_options' => {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp