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

Commitaa2e323

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 parent020e4a1 commitaa2e323

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
@@ -1957,6 +1957,26 @@ selectDumpablePublicationTable(DumpableObject *dobj, Archive *fout)
19571957
DUMP_COMPONENT_ALL : DUMP_COMPONENT_NONE;
19581958
}
19591959

1960+
/*
1961+
* selectDumpableStatisticsObject: policy-setting subroutine
1962+
*Mark an extended statistics object as to be dumped or not
1963+
*
1964+
* We dump an extended statistics object if the schema it's in and the table
1965+
* it's for are being dumped. (This'll need more thought if statistics
1966+
* objects ever support cross-table stats.)
1967+
*/
1968+
static void
1969+
selectDumpableStatisticsObject(StatsExtInfo *sobj, Archive *fout)
1970+
{
1971+
if (checkExtensionMembership(&sobj->dobj, fout))
1972+
return;/* extension membership overrides all else */
1973+
1974+
sobj->dobj.dump = sobj->dobj.namespace->dobj.dump_contains;
1975+
if (sobj->stattable == NULL ||
1976+
!(sobj->stattable->dobj.dump & DUMP_COMPONENT_DEFINITION))
1977+
sobj->dobj.dump = DUMP_COMPONENT_NONE;
1978+
}
1979+
19601980
/*
19611981
* selectDumpableObject: policy-setting subroutine
19621982
*Mark a generic dumpable object as to be dumped or not
@@ -7683,6 +7703,7 @@ getExtendedStatistics(Archive *fout)
76837703
inti_stxname;
76847704
inti_stxnamespace;
76857705
inti_rolname;
7706+
inti_stxrelid;
76867707
inti_stattarget;
76877708
inti;
76887709

@@ -7694,12 +7715,12 @@ getExtendedStatistics(Archive *fout)
76947715

76957716
if (fout->remoteVersion < 130000)
76967717
appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
7697-
"stxnamespace, (%s stxowner) AS rolname, (-1) AS stxstattarget "
7718+
"stxnamespace, (%s stxowner) AS rolname,stxrelid,(-1) AS stxstattarget "
76987719
"FROM pg_catalog.pg_statistic_ext",
76997720
username_subquery);
77007721
else
77017722
appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
7702-
"stxnamespace, (%s stxowner) AS rolname, stxstattarget "
7723+
"stxnamespace, (%s stxowner) AS rolname,stxrelid,stxstattarget "
77037724
"FROM pg_catalog.pg_statistic_ext",
77047725
username_subquery);
77057726

@@ -7712,6 +7733,7 @@ getExtendedStatistics(Archive *fout)
77127733
i_stxname = PQfnumber(res, "stxname");
77137734
i_stxnamespace = PQfnumber(res, "stxnamespace");
77147735
i_rolname = PQfnumber(res, "rolname");
7736+
i_stxrelid = PQfnumber(res, "stxrelid");
77157737
i_stattarget = PQfnumber(res, "stxstattarget");
77167738

77177739
statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
@@ -7726,10 +7748,12 @@ getExtendedStatistics(Archive *fout)
77267748
statsextinfo[i].dobj.namespace =
77277749
findNamespace(atooid(PQgetvalue(res, i, i_stxnamespace)));
77287750
statsextinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
7751+
statsextinfo[i].stattable =
7752+
findTableByOid(atooid(PQgetvalue(res, i, i_stxrelid)));
77297753
statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
77307754

77317755
/* Decide whether we want to dump it */
7732-
selectDumpableObject(&(statsextinfo[i].dobj), fout);
7756+
selectDumpableStatisticsObject(&(statsextinfo[i]), fout);
77337757

77347758
/* Stats objects do not currently have ACLs. */
77357759
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
@@ -398,6 +398,7 @@ typedef struct _statsExtInfo
398398
{
399399
DumpableObjectdobj;
400400
char*rolname;/* name of owner, or empty string */
401+
TableInfo*stattable;/* link to table the stats are for */
401402
intstattarget;/* statistics target */
402403
}StatsExtInfo;
403404

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,13 +2855,13 @@
28552855
'CREATE STATISTICS extended_stats_no_options' => {
28562856
create_order => 97,
28572857
create_sql => 'CREATE STATISTICS dump_test.test_ext_stats_no_options
2858-
ON col1, col2 FROM dump_test.test_fifth_table',
2858+
ON col1, col2 FROM dump_test.test_table',
28592859
regexp => qr/^
2860-
\QCREATE STATISTICS dump_test.test_ext_stats_no_options ON col1, col2 FROM dump_test.test_fifth_table;\E
2860+
\QCREATE STATISTICS dump_test.test_ext_stats_no_options ON col1, col2 FROM dump_test.test_table;\E
28612861
/xms,
28622862
like =>
28632863
{%full_runs,%dump_test_schema_runs, section_post_data => 1, },
2864-
unlike => { exclude_dump_test_schema => 1, },
2864+
unlike => { exclude_dump_test_schema => 1,exclude_test_table => 1,},
28652865
},
28662866
28672867
'CREATE STATISTICS extended_stats_options' => {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp