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

Commitb2c9936

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 parenta78b0b3 commitb2c9936

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,6 +2029,26 @@ selectDumpablePublicationObject(DumpableObject *dobj, Archive *fout)
20292029
DUMP_COMPONENT_ALL : DUMP_COMPONENT_NONE;
20302030
}
20312031

2032+
/*
2033+
* selectDumpableStatisticsObject: policy-setting subroutine
2034+
*Mark an extended statistics object as to be dumped or not
2035+
*
2036+
* We dump an extended statistics object if the schema it's in and the table
2037+
* it's for are being dumped. (This'll need more thought if statistics
2038+
* objects ever support cross-table stats.)
2039+
*/
2040+
static void
2041+
selectDumpableStatisticsObject(StatsExtInfo *sobj, Archive *fout)
2042+
{
2043+
if (checkExtensionMembership(&sobj->dobj, fout))
2044+
return;/* extension membership overrides all else */
2045+
2046+
sobj->dobj.dump = sobj->dobj.namespace->dobj.dump_contains;
2047+
if (sobj->stattable == NULL ||
2048+
!(sobj->stattable->dobj.dump & DUMP_COMPONENT_DEFINITION))
2049+
sobj->dobj.dump = DUMP_COMPONENT_NONE;
2050+
}
2051+
20322052
/*
20332053
* selectDumpableObject: policy-setting subroutine
20342054
*Mark a generic dumpable object as to be dumped or not
@@ -7269,6 +7289,7 @@ getExtendedStatistics(Archive *fout)
72697289
inti_stxname;
72707290
inti_stxnamespace;
72717291
inti_stxowner;
7292+
inti_stxrelid;
72727293
inti_stattarget;
72737294
inti;
72747295

@@ -7280,11 +7301,11 @@ getExtendedStatistics(Archive *fout)
72807301

72817302
if (fout->remoteVersion < 130000)
72827303
appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
7283-
"stxnamespace, stxowner, (-1) AS stxstattarget "
7304+
"stxnamespace, stxowner,stxrelid,(-1) AS stxstattarget "
72847305
"FROM pg_catalog.pg_statistic_ext");
72857306
else
72867307
appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
7287-
"stxnamespace, stxowner, stxstattarget "
7308+
"stxnamespace, stxowner,stxrelid,stxstattarget "
72887309
"FROM pg_catalog.pg_statistic_ext");
72897310

72907311
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
@@ -7296,6 +7317,7 @@ getExtendedStatistics(Archive *fout)
72967317
i_stxname = PQfnumber(res, "stxname");
72977318
i_stxnamespace = PQfnumber(res, "stxnamespace");
72987319
i_stxowner = PQfnumber(res, "stxowner");
7320+
i_stxrelid = PQfnumber(res, "stxrelid");
72997321
i_stattarget = PQfnumber(res, "stxstattarget");
73007322

73017323
statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
@@ -7310,10 +7332,12 @@ getExtendedStatistics(Archive *fout)
73107332
statsextinfo[i].dobj.namespace =
73117333
findNamespace(atooid(PQgetvalue(res, i, i_stxnamespace)));
73127334
statsextinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_stxowner));
7335+
statsextinfo[i].stattable =
7336+
findTableByOid(atooid(PQgetvalue(res, i, i_stxrelid)));
73137337
statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
73147338

73157339
/* Decide whether we want to dump it */
7316-
selectDumpableObject(&(statsextinfo[i].dobj), fout);
7340+
selectDumpableStatisticsObject(&(statsextinfo[i]), fout);
73177341
}
73187342

73197343
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3731,14 +3731,15 @@
37313731
'CREATE STATISTICS extended_stats_no_options' => {
37323732
create_order => 97,
37333733
create_sql => 'CREATE STATISTICS dump_test.test_ext_stats_no_options
3734-
ON col1, col2 FROM dump_test.test_fifth_table',
3734+
ON col1, col2 FROM dump_test.test_table',
37353735
regexp => qr/^
3736-
\QCREATE STATISTICS dump_test.test_ext_stats_no_options ON col1, col2 FROM dump_test.test_fifth_table;\E
3736+
\QCREATE STATISTICS dump_test.test_ext_stats_no_options ON col1, col2 FROM dump_test.test_table;\E
37373737
/xms,
37383738
like =>
37393739
{%full_runs,%dump_test_schema_runs, section_post_data => 1, },
37403740
unlike => {
37413741
exclude_dump_test_schema => 1,
3742+
exclude_test_table => 1,
37423743
only_dump_measurement => 1,
37433744
},
37443745
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp