aboutsummaryrefslogtreecommitdiff
path: root/src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-01-18 13:23:57 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2023-01-18 13:23:57 -0500
commit47bb9db75996232ea71fc1e1888ffb0e70579b54 (patch)
tree745e1a7755802a7e92cd267bce642358a1f37a0a /src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm
parent8d83a5d0a2673174dc478e707de1f502935391a5 (diff)
downloadpostgresql-47bb9db75996232ea71fc1e1888ffb0e70579b54.tar.gz
postgresql-47bb9db75996232ea71fc1e1888ffb0e70579b54.zip
Get rid of the "new" and "old" entries in a view's rangetable.
The rule system needs "old" and/or "new" pseudo-RTEs in rule actions that are ON INSERT/UPDATE/DELETE. Historically it's put such entries into the ON SELECT rules of views as well, but those are really quite vestigial. The only thing we've used them for is to carry the view's relid forward to AcquireExecutorLocks (so that we can re-lock the view to verify it hasn't changed before re-using a plan) and to carry its relid and permissions data forward to execution-time permissions checks. What we can do instead of that is to retain these fields of the RTE_RELATION RTE for the view even after we convert it to an RTE_SUBQUERY RTE. This requires a tiny amount of extra complication in the planner and AcquireExecutorLocks, but on the other hand we can get rid of the logic that moves that data from one place to another. The principal immediate benefit of doing this, aside from a small saving in the pg_rewrite data for views, is that these pseudo-RTEs no longer trigger ruleutils.c's heuristic about qualifying variable names when the rangetable's length is more than 1. That results in quite a number of small simplifications in regression test outputs, which are all to the good IMO. Bump catversion because we need to dump a few more fields of RTE_SUBQUERY RTEs. While those will always be zeroes anyway in stored rules (because we'd never populate them until query rewrite) they are useful for debugging, and it seems like we'd better make sure to transmit such RTEs accurately in plans sent to parallel workers. I don't think the executor actually examines these fields after startup, but someday it might. This is a second attempt at committing 1b4d280ea. The difference from the first time is that now we can add some filtering rules to AdjustUpgrade.pm to allow cross-version upgrade testing to pass despite all the cosmetic changes in CREATE VIEW outputs. Amit Langote (filtering rules by me) Discussion: https://postgr.es/m/CA+HiwqEf7gPN4Hn+LoZ4tP2q_Qt7n3vw7-6fJKOf92tSEnX6Gg@mail.gmail.com Discussion: https://postgr.es/m/891521.1673657296@sss.pgh.pa.us
Diffstat (limited to 'src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm')
-rw-r--r--src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm133
1 files changed, 133 insertions, 0 deletions
diff --git a/src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm b/src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm
index 7cf4ced392f..5bed1d68395 100644
--- a/src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm
+++ b/src/test/perl/PostgreSQL/Test/AdjustUpgrade.pm
@@ -268,6 +268,12 @@ sub adjust_old_dumpfile
# Version comments will certainly not match.
$dump =~ s/^-- Dumped from database version.*\n//mg;
+ if ($old_version < 16)
+ {
+ # Fix up some view queries that no longer require table-qualification.
+ $dump = _mash_view_qualifiers($dump);
+ }
+
if ($old_version >= 14 && $old_version < 16)
{
# Fix up some privilege-set discrepancies.
@@ -396,6 +402,133 @@ sub adjust_old_dumpfile
return $dump;
}
+
+# Data for _mash_view_qualifiers
+my @_unused_view_qualifiers = (
+ # Present at least since 9.2
+ { obj => 'VIEW public.trigger_test_view', qual => 'trigger_test' },
+ { obj => 'VIEW public.domview', qual => 'domtab' },
+ { obj => 'VIEW public.my_property_normal', qual => 'customer' },
+ { obj => 'VIEW public.my_property_secure', qual => 'customer' },
+ { obj => 'VIEW public.pfield_v1', qual => 'pf' },
+ { obj => 'VIEW public.rtest_v1', qual => 'rtest_t1' },
+ { obj => 'VIEW public.rtest_vview1', qual => 'x' },
+ { obj => 'VIEW public.rtest_vview2', qual => 'rtest_view1' },
+ { obj => 'VIEW public.rtest_vview3', qual => 'x' },
+ { obj => 'VIEW public.rtest_vview5', qual => 'rtest_view1' },
+ { obj => 'VIEW public.shoelace_obsolete', qual => 'shoelace' },
+ { obj => 'VIEW public.shoelace_candelete', qual => 'shoelace_obsolete' },
+ { obj => 'VIEW public.toyemp', qual => 'emp' },
+ { obj => 'VIEW public.xmlview4', qual => 'emp' },
+ # Since 9.3 (some of these were removed in 9.6)
+ { obj => 'VIEW public.tv', qual => 't' },
+ { obj => 'MATERIALIZED VIEW mvschema.tvm', qual => 'tv' },
+ { obj => 'VIEW public.tvv', qual => 'tv' },
+ { obj => 'MATERIALIZED VIEW public.tvvm', qual => 'tvv' },
+ { obj => 'VIEW public.tvvmv', qual => 'tvvm' },
+ { obj => 'MATERIALIZED VIEW public.bb', qual => 'tvvmv' },
+ { obj => 'VIEW public.nums', qual => 'nums' },
+ { obj => 'VIEW public.sums_1_100', qual => 't' },
+ { obj => 'MATERIALIZED VIEW public.tm', qual => 't' },
+ { obj => 'MATERIALIZED VIEW public.tmm', qual => 'tm' },
+ { obj => 'MATERIALIZED VIEW public.tvmm', qual => 'tvm' },
+ # Since 9.4
+ {
+ obj => 'MATERIALIZED VIEW public.citext_matview',
+ qual => 'citext_table'
+ },
+ {
+ obj => 'OR REPLACE VIEW public.key_dependent_view',
+ qual => 'view_base_table'
+ },
+ {
+ obj => 'OR REPLACE VIEW public.key_dependent_view_no_cols',
+ qual => 'view_base_table'
+ },
+ # Since 9.5
+ {
+ obj => 'VIEW public.dummy_seclabel_view1',
+ qual => 'dummy_seclabel_tbl2'
+ },
+ { obj => 'VIEW public.vv', qual => 'test_tablesample' },
+ { obj => 'VIEW public.test_tablesample_v1', qual => 'test_tablesample' },
+ { obj => 'VIEW public.test_tablesample_v2', qual => 'test_tablesample' },
+ # Since 9.6
+ {
+ obj => 'MATERIALIZED VIEW public.test_pg_dump_mv1',
+ qual => 'test_pg_dump_t1'
+ },
+ { obj => 'VIEW public.test_pg_dump_v1', qual => 'test_pg_dump_t1' },
+ { obj => 'VIEW public.mvtest_tv', qual => 'mvtest_t' },
+ {
+ obj => 'MATERIALIZED VIEW mvtest_mvschema.mvtest_tvm',
+ qual => 'mvtest_tv'
+ },
+ { obj => 'VIEW public.mvtest_tvv', qual => 'mvtest_tv' },
+ { obj => 'MATERIALIZED VIEW public.mvtest_tvvm', qual => 'mvtest_tvv' },
+ { obj => 'VIEW public.mvtest_tvvmv', qual => 'mvtest_tvvm' },
+ { obj => 'MATERIALIZED VIEW public.mvtest_bb', qual => 'mvtest_tvvmv' },
+ { obj => 'MATERIALIZED VIEW public.mvtest_tm', qual => 'mvtest_t' },
+ { obj => 'MATERIALIZED VIEW public.mvtest_tmm', qual => 'mvtest_tm' },
+ { obj => 'MATERIALIZED VIEW public.mvtest_tvmm', qual => 'mvtest_tvm' },
+ # Since 10 (some removed in 12)
+ { obj => 'VIEW public.itestv10', qual => 'itest10' },
+ { obj => 'VIEW public.itestv11', qual => 'itest11' },
+ { obj => 'VIEW public.xmltableview2', qual => '"xmltable"' },
+ # Since 12
+ {
+ obj => 'MATERIALIZED VIEW public.tableam_tblmv_heap2',
+ qual => 'tableam_tbl_heap2'
+ },
+ # Since 13
+ { obj => 'VIEW public.limit_thousand_v_1', qual => 'onek' },
+ { obj => 'VIEW public.limit_thousand_v_2', qual => 'onek' },
+ { obj => 'VIEW public.limit_thousand_v_3', qual => 'onek' },
+ { obj => 'VIEW public.limit_thousand_v_4', qual => 'onek' });
+
+# Internal subroutine to remove no-longer-used table qualifiers from
+# CREATE [MATERIALIZED] VIEW commands. See list of targeted views above.
+sub _mash_view_qualifiers
+{
+ my ($dump) = @_;
+
+ for my $uvq (@_unused_view_qualifiers)
+ {
+ my $leader = "CREATE $uvq->{obj} ";
+ my $qualifier = $uvq->{qual};
+ # Note: we loop because there are presently some cases where the same
+ # view name appears in multiple databases. Fortunately, the same
+ # qualifier removal applies or is harmless for each instance ... but
+ # we might want to rename some things to avoid assuming that.
+ my @splitchunks = split $leader, $dump;
+ $dump = shift(@splitchunks);
+ foreach my $chunk (@splitchunks)
+ {
+ my @thischunks = split /;/, $chunk, 2;
+ my $stmt = shift(@thischunks);
+ my $ostmt = $stmt;
+
+ # now $stmt is just the body of the CREATE [MATERIALIZED] VIEW
+ $stmt =~ s/$qualifier\.//g;
+
+ $dump .= $leader . $stmt . ';' . $thischunks[0];
+ }
+ }
+
+ # Further hack a few cases where not all occurrences of the qualifier
+ # should be removed.
+ $dump =~ s {^(CREATE VIEW public\.rtest_vview1 .*?)(a\)\)\);)}
+ {$1x.$2}ms;
+ $dump =~ s {^(CREATE VIEW public\.rtest_vview3 .*?)(a\)\)\);)}
+ {$1x.$2}ms;
+ $dump =~
+ s {^(CREATE VIEW public\.shoelace_obsolete .*?)(sl_color\)\)\)\);)}
+ {$1shoelace.$2}ms;
+
+ return $dump;
+}
+
+
# Internal subroutine to mangle whitespace within view/rule commands.
# Any consecutive sequence of whitespace is reduced to one space.
sub _mash_view_whitespace