postgresql/src/bin
Tom Lane d8c05aff56 Fix pg_dump's handling of circular dependencies in views.
pg_dump's traditional solution for breaking a circular dependency involving
a view was to create the view with CREATE TABLE and then later issue CREATE
RULE "_RETURN" ... to convert the table to a view, relying on the backend's
very very ancient code that supports making views that way.  We've wanted
to get rid of that kluge for a long time, but the thing that finally
motivates doing something about it is the recognition that this method
fails with the --clean option, because it leads to issuing DROP RULE
"_RETURN" followed by DROP TABLE --- and the backend won't let you drop a
view's _RETURN rule.

Instead, let's break circular dependencies by initially creating the view
using CREATE VIEW AS SELECT NULL::columntype AS columnname, ... (so that
it has the right column names and types to support external references,
but no dependencies beyond the column data types), and then later dumping
the ON SELECT rule using the spelling CREATE OR REPLACE VIEW.  This method
wasn't available when this code was originally written, but it's been
possible since PG 7.3, so it seems fine to start relying on it now.

To solve the --clean problem, make the dropStmt for an ON SELECT rule
be CREATE OR REPLACE VIEW with the same dummy target list as above.
In this way, during the DROP phase, we first reduce the view to have
no extra dependencies, and then we can drop it entirely when we've
gotten rid of whatever had a circular dependency on it.

(Note: this should work adequately well with the --if-exists option, since
the CREATE OR REPLACE VIEW will go through whether the view exists or not.
It could fail if the view exists with a conflicting column set, but we
don't really support --clean against a non-matching database anyway.)

This allows cleaning up some other kluges inside pg_dump, notably that
we don't need a notion of reloptions attached to a rule anymore.

Although this is a bug fix, commit to HEAD only for now.  The problem's
existed for a long time and we've had relatively few complaints, so it
doesn't really seem worth taking risks to fix it in the back branches.
We might revisit that choice if no problems emerge.

Discussion: <19092.1479325184@sss.pgh.pa.us>
2016-11-17 15:25:59 -05:00
..
initdb Rename "pg_xlog" directory to "pg_wal". 2016-10-20 11:32:18 -04:00
pg_archivecleanup pg_archivecleanup: Add NLS 2016-11-04 10:40:05 -04:00
pg_basebackup Change qr/foo$/m to qr/foo\n/m, for Perl 5.8.8. 2016-11-07 20:27:30 -05:00
pg_config Translation updates 2016-08-08 11:08:00 -04:00
pg_controldata Fix CRC check handling in get_controlfile 2016-09-28 12:00:00 -04:00
pg_ctl pg_ctl: Add long option for -o 2016-10-19 08:48:48 -04:00
pg_dump Fix pg_dump's handling of circular dependencies in views. 2016-11-17 15:25:59 -05:00
pg_resetxlog Rename "pg_xlog" directory to "pg_wal". 2016-10-20 11:32:18 -04:00
pg_rewind pg_rewing pg_upgrade: Fix translation markers 2016-11-07 09:31:26 -05:00
pg_test_fsync pg_test_fsync: Add NLS 2016-11-04 10:40:05 -04:00
pg_test_timing pg_test_timing: Add NLS 2016-11-04 10:40:05 -04:00
pg_upgrade pg_upgrade: Upgrade sequence data via pg_dump 2016-11-13 21:44:58 -05:00
pg_xlogdump pg_xlogdump: Add NLS 2016-11-04 10:40:05 -04:00
pgbench pgbench: Increase maximum size of log filename from 64 to MAXPGPATH. 2016-11-15 09:11:51 -05:00
pgevent Update copyright for 2016 2016-01-02 13:33:40 -05:00
psql psql: Tab completion for renaming enum values. 2016-11-08 16:30:51 -05:00
scripts Include <sys/select.h> where needed 2016-09-27 01:05:21 -03:00
Makefile Update copyright for 2016 2016-01-02 13:33:40 -05:00