postgresql/src/bin/pg_dump
Tom Lane 5c9f2564fa Fix assorted errors in pg_dump's handling of extended statistics objects.
pg_dump supposed that a stats object necessarily shares the same schema
as its underlying table, and that it doesn't have a separate owner.
These things may have been true during early development of the feature,
but they are not true as of v10 release.

Failure to track the object's schema separately turns out to have only
limited consequences, because pg_get_statisticsobjdef() always schema-
qualifies the target object name in the generated CREATE STATISTICS command
(a decision out of step with the rest of ruleutils.c, but I digress).
Therefore the restored object would be in the right schema, so that the
only problem is that the TOC entry would be mislabeled as to schema.  That
could lead to wrong decisions for schema-selective restores, for example.

The ownership issue is a bit more serious: not only was the TOC entry
potentially mislabeled as to owner, but pg_dump didn't bother to issue an
ALTER OWNER command at all, so that after restore the stats object would
continue to be owned by the restoring superuser.

A final point is that decisions as to whether to dump a stats object or
not were driven by whether the underlying table was dumped or not.  While
that's not wrong on its face, it won't scale nicely to the planned future
extension to cross-table statistics.  Moreover, that design decision comes
out of the view of stats objects as being auxiliary to a particular table,
like a rule or trigger, which is exactly where the above problems came
from.  Since we're now treating stats objects more like independent objects
in their own right, they ought to behave like standalone objects for this
purpose too.  So change to using the generic selectDumpableObject() logic
for them (which presently amounts to "dump if containing schema is to be
dumped").

Along the way to fixing this, restructure so that getExtendedStatistics
collects the identity info (only) for all extended stats objects in one
query, and then for each object actually being dumped, we retrieve the
definition in dumpStatisticsExt.  This is necessary to ensure that
schema-qualification in the generated CREATE STATISTICS command happens
with respect to the search path that pg_dump will now be using at restore
time (ie, the schema the stats object is in, not that of the underlying
table).  It's probably also significantly faster in the typical scenario
where only a minority of tables have extended stats.

Back-patch to v10 where extended stats were introduced.

Discussion: https://postgr.es/m/18272.1518328606@sss.pgh.pa.us
2018-02-11 13:24:15 -05:00
..
po Translation updates 2017-08-07 13:55:34 -04:00
t Fix assorted errors in pg_dump's handling of extended statistics objects. 2018-02-11 13:24:15 -05:00
.gitignore Clean up after pg_dump test runs. 2016-05-06 22:28:01 -04:00
Makefile Update copyright for 2018 2018-01-02 23:30:12 -05:00
common.c Fix assorted errors in pg_dump's handling of extended statistics objects. 2018-02-11 13:24:15 -05:00
compress_io.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
compress_io.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
dumputils.c Move handling of database properties from pg_dumpall into pg_dump. 2018-01-22 14:09:09 -05:00
dumputils.h Move handling of database properties from pg_dumpall into pg_dump. 2018-01-22 14:09:09 -05:00
nls.mk Translation updates 2017-08-07 13:55:34 -04:00
parallel.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
parallel.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
pg_backup.h Support --no-comments in pg_dump, pg_dumpall, pg_restore. 2018-01-25 15:27:24 -05:00
pg_backup_archiver.c Fix assorted errors in pg_dump's handling of extended statistics objects. 2018-02-11 13:24:15 -05:00
pg_backup_archiver.h In pg_dump, force reconnection after issuing ALTER DATABASE SET command(s). 2018-01-23 10:55:16 -05:00
pg_backup_custom.c Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
pg_backup_db.c In pg_dump, force reconnection after issuing ALTER DATABASE SET command(s). 2018-01-23 10:55:16 -05:00
pg_backup_db.h Add some const decorations to prototypes 2017-11-10 13:38:57 -05:00
pg_backup_directory.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
pg_backup_null.c Reduce excessive dereferencing of function pointers 2017-09-07 13:56:09 -04:00
pg_backup_tar.c Final pgindent + perltidy run for v10. 2017-08-14 17:29:33 -04:00
pg_backup_tar.h Fix tar files emitted by pg_dump and pg_basebackup to be POSIX conformant. 2012-09-28 15:19:15 -04:00
pg_backup_utils.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
pg_backup_utils.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
pg_dump.c Fix assorted errors in pg_dump's handling of extended statistics objects. 2018-02-11 13:24:15 -05:00
pg_dump.h Fix assorted errors in pg_dump's handling of extended statistics objects. 2018-02-11 13:24:15 -05:00
pg_dump_sort.c Local partitioned indexes 2018-01-19 11:49:22 -03:00
pg_dumpall.c Support --no-comments in pg_dump, pg_dumpall, pg_restore. 2018-01-25 15:27:24 -05:00
pg_restore.c Support --no-comments in pg_dump, pg_dumpall, pg_restore. 2018-01-25 15:27:24 -05:00