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

Commit1e08414

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 parent296128a commit1e08414

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,6 +1933,26 @@ selectDumpablePublicationObject(DumpableObject *dobj, Archive *fout)
19331933
DUMP_COMPONENT_ALL : DUMP_COMPONENT_NONE;
19341934
}
19351935

1936+
/*
1937+
* selectDumpableStatisticsObject: policy-setting subroutine
1938+
*Mark an extended statistics object as to be dumped or not
1939+
*
1940+
* We dump an extended statistics object if the schema it's in and the table
1941+
* it's for are being dumped. (This'll need more thought if statistics
1942+
* objects ever support cross-table stats.)
1943+
*/
1944+
static void
1945+
selectDumpableStatisticsObject(StatsExtInfo *sobj, Archive *fout)
1946+
{
1947+
if (checkExtensionMembership(&sobj->dobj, fout))
1948+
return;/* extension membership overrides all else */
1949+
1950+
sobj->dobj.dump = sobj->dobj.namespace->dobj.dump_contains;
1951+
if (sobj->stattable == NULL ||
1952+
!(sobj->stattable->dobj.dump & DUMP_COMPONENT_DEFINITION))
1953+
sobj->dobj.dump = DUMP_COMPONENT_NONE;
1954+
}
1955+
19361956
/*
19371957
* selectDumpableObject: policy-setting subroutine
19381958
*Mark a generic dumpable object as to be dumped or not
@@ -7096,6 +7116,7 @@ getExtendedStatistics(Archive *fout)
70967116
inti_stxname;
70977117
inti_stxnamespace;
70987118
inti_stxowner;
7119+
inti_stxrelid;
70997120
inti_stattarget;
71007121
inti;
71017122

@@ -7107,11 +7128,11 @@ getExtendedStatistics(Archive *fout)
71077128

71087129
if (fout->remoteVersion < 130000)
71097130
appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
7110-
"stxnamespace, stxowner, (-1) AS stxstattarget "
7131+
"stxnamespace, stxowner,stxrelid,(-1) AS stxstattarget "
71117132
"FROM pg_catalog.pg_statistic_ext");
71127133
else
71137134
appendPQExpBuffer(query, "SELECT tableoid, oid, stxname, "
7114-
"stxnamespace, stxowner, stxstattarget "
7135+
"stxnamespace, stxowner,stxrelid,stxstattarget "
71157136
"FROM pg_catalog.pg_statistic_ext");
71167137

71177138
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
@@ -7123,6 +7144,7 @@ getExtendedStatistics(Archive *fout)
71237144
i_stxname = PQfnumber(res, "stxname");
71247145
i_stxnamespace = PQfnumber(res, "stxnamespace");
71257146
i_stxowner = PQfnumber(res, "stxowner");
7147+
i_stxrelid = PQfnumber(res, "stxrelid");
71267148
i_stattarget = PQfnumber(res, "stxstattarget");
71277149

71287150
statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
@@ -7137,10 +7159,12 @@ getExtendedStatistics(Archive *fout)
71377159
statsextinfo[i].dobj.namespace =
71387160
findNamespace(atooid(PQgetvalue(res, i, i_stxnamespace)));
71397161
statsextinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_stxowner));
7162+
statsextinfo[i].stattable =
7163+
findTableByOid(atooid(PQgetvalue(res, i, i_stxrelid)));
71407164
statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
71417165

71427166
/* Decide whether we want to dump it */
7143-
selectDumpableObject(&(statsextinfo[i].dobj), fout);
7167+
selectDumpableStatisticsObject(&(statsextinfo[i]), fout);
71447168
}
71457169

71467170
PQclear(res);

‎src/bin/pg_dump/pg_dump.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,8 @@ typedef struct _indexAttachInfo
418418
typedefstruct_statsExtInfo
419419
{
420420
DumpableObjectdobj;
421-
constchar*rolname;
421+
constchar*rolname;/* owner */
422+
TableInfo*stattable;/* link to table the stats are for */
422423
intstattarget;/* statistics target */
423424
}StatsExtInfo;
424425

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3136,13 +3136,13 @@
31363136
'CREATE STATISTICS extended_stats_no_options' => {
31373137
create_order => 97,
31383138
create_sql => 'CREATE STATISTICS dump_test.test_ext_stats_no_options
3139-
ON col1, col2 FROM dump_test.test_fifth_table',
3139+
ON col1, col2 FROM dump_test.test_table',
31403140
regexp => qr/^
3141-
\QCREATE STATISTICS dump_test.test_ext_stats_no_options ON col1, col2 FROM dump_test.test_fifth_table;\E
3141+
\QCREATE STATISTICS dump_test.test_ext_stats_no_options ON col1, col2 FROM dump_test.test_table;\E
31423142
/xms,
31433143
like =>
31443144
{%full_runs,%dump_test_schema_runs, section_post_data => 1, },
3145-
unlike => { exclude_dump_test_schema => 1, },
3145+
unlike => { exclude_dump_test_schema => 1,exclude_test_table => 1,},
31463146
},
31473147
31483148
'CREATE STATISTICS extended_stats_options' => {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp