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

Commit8d4e8b7

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 parentd2580bc commit8d4e8b7

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,6 +1815,26 @@ selectDumpablePublicationTable(DumpableObject *dobj, Archive *fout)
18151815
DUMP_COMPONENT_ALL : DUMP_COMPONENT_NONE;
18161816
}
18171817

1818+
/*
1819+
* selectDumpableStatisticsObject: policy-setting subroutine
1820+
*Mark an extended statistics object as to be dumped or not
1821+
*
1822+
* We dump an extended statistics object if the schema it's in and the table
1823+
* it's for are being dumped. (This'll need more thought if statistics
1824+
* objects ever support cross-table stats.)
1825+
*/
1826+
static void
1827+
selectDumpableStatisticsObject(StatsExtInfo *sobj, Archive *fout)
1828+
{
1829+
if (checkExtensionMembership(&sobj->dobj, fout))
1830+
return;/* extension membership overrides all else */
1831+
1832+
sobj->dobj.dump = sobj->dobj.namespace->dobj.dump_contains;
1833+
if (sobj->stattable == NULL ||
1834+
!(sobj->stattable->dobj.dump & DUMP_COMPONENT_DEFINITION))
1835+
sobj->dobj.dump = DUMP_COMPONENT_NONE;
1836+
}
1837+
18181838
/*
18191839
* selectDumpableObject: policy-setting subroutine
18201840
*Mark a generic dumpable object as to be dumped or not
@@ -7492,6 +7512,7 @@ getExtendedStatistics(Archive *fout)
74927512
inti_stxname;
74937513
inti_stxnamespace;
74947514
inti_rolname;
7515+
inti_stxrelid;
74957516
inti_stattarget;
74967517
inti;
74977518

@@ -7503,12 +7524,12 @@ getExtendedStatistics(Archive *fout)
75037524

75047525
if (fout->remoteVersion < 130000)
75057526
appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
7506-
"stxnamespace, (%s stxowner) AS rolname, (-1) AS stxstattarget "
7527+
"stxnamespace, (%s stxowner) AS rolname,stxrelid,(-1) AS stxstattarget "
75077528
"FROM pg_catalog.pg_statistic_ext",
75087529
username_subquery);
75097530
else
75107531
appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
7511-
"stxnamespace, (%s stxowner) AS rolname, stxstattarget "
7532+
"stxnamespace, (%s stxowner) AS rolname,stxrelid,stxstattarget "
75127533
"FROM pg_catalog.pg_statistic_ext",
75137534
username_subquery);
75147535

@@ -7521,6 +7542,7 @@ getExtendedStatistics(Archive *fout)
75217542
i_stxname = PQfnumber(res, "stxname");
75227543
i_stxnamespace = PQfnumber(res, "stxnamespace");
75237544
i_rolname = PQfnumber(res, "rolname");
7545+
i_stxrelid = PQfnumber(res, "stxrelid");
75247546
i_stattarget = PQfnumber(res, "stxstattarget");
75257547

75267548
statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
@@ -7536,10 +7558,12 @@ getExtendedStatistics(Archive *fout)
75367558
findNamespace(fout,
75377559
atooid(PQgetvalue(res, i, i_stxnamespace)));
75387560
statsextinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
7561+
statsextinfo[i].stattable =
7562+
findTableByOid(atooid(PQgetvalue(res, i, i_stxrelid)));
75397563
statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
75407564

75417565
/* Decide whether we want to dump it */
7542-
selectDumpableObject(&(statsextinfo[i].dobj), fout);
7566+
selectDumpableStatisticsObject(&(statsextinfo[i]), fout);
75437567

75447568
/* Stats objects do not currently have ACLs. */
75457569
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
@@ -387,6 +387,7 @@ typedef struct _statsExtInfo
387387
{
388388
DumpableObjectdobj;
389389
char*rolname;/* name of owner, or empty string */
390+
TableInfo*stattable;/* link to table the stats are for */
390391
intstattarget;/* statistics target */
391392
}StatsExtInfo;
392393

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,13 +2751,13 @@
27512751
'CREATE STATISTICS extended_stats_no_options' => {
27522752
create_order => 97,
27532753
create_sql => 'CREATE STATISTICS dump_test.test_ext_stats_no_options
2754-
ON col1, col2 FROM dump_test.test_fifth_table',
2754+
ON col1, col2 FROM dump_test.test_table',
27552755
regexp => qr/^
2756-
\QCREATE STATISTICS dump_test.test_ext_stats_no_options ON col1, col2 FROM dump_test.test_fifth_table;\E
2756+
\QCREATE STATISTICS dump_test.test_ext_stats_no_options ON col1, col2 FROM dump_test.test_table;\E
27572757
/xms,
27582758
like =>
27592759
{%full_runs,%dump_test_schema_runs, section_post_data => 1, },
2760-
unlike => { exclude_dump_test_schema => 1, },
2760+
unlike => { exclude_dump_test_schema => 1,exclude_test_table => 1,},
27612761
},
27622762
27632763
'CREATE STATISTICS extended_stats_options' => {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp