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

Commit7944d2d

Browse files
committed
Prevent pgstats from getting confused when relkind of a relation changes
When the relkind of a relache entry changes, because a table is converted intoa view, pgstats can get confused in 15+, leading to crashes or assertionfailures.For HEAD, Tom fixed this inb23cd18, by removing support for converting atable to a view, removing the source of the inconsistency. This commit justadds an assertion that a relcache entry's relkind does not change, just incase we end up with another case of that in the future. As there's no cases ofchanging relkind anymore, we can't add a test that that's handled correctly.For 15, fix the problem by not maintaining the association with the old pgstatentry when the relkind changes during a relcache invalidation processing. Inthat case the pgstat entry needs to be unlinked first, to avoidPgStat_TableStatus->relation getting out of sync. Also add a test reproducingthe issues.No known problem exists in 11-14, so just add the test there.Reported-by: vignesh C <vignesh21@gmail.com>Author: Andres Freund <andres@anarazel.de>Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>Discussion:https://postgr.es/m/CALDaNm2yXz+zOtv7y5zBd5WKT8O0Ld3YxikuU3dcyCvxF7gypA@mail.gmail.comDiscussion:https://postgr.es/m/CALDaNm3oZA-8Wbps2Jd1g5_Gjrr-x3YWrJPek-mF5Asrrvz2Dg@mail.gmail.comBackpatch: 15-
1 parenta844052 commit7944d2d

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

‎src/test/regress/expected/create_view.out

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1898,6 +1898,29 @@ select pg_get_viewdef('tt26v', true);
18981898
FROM ( VALUES (1,2,3)) v(x, y, z);
18991899
(1 row)
19001900

1901+
-- Test that changing the relkind of a relcache entry doesn't cause
1902+
-- trouble. Prior instances of where it did:
1903+
-- CALDaNm2yXz+zOtv7y5zBd5WKT8O0Ld3YxikuU3dcyCvxF7gypA@mail.gmail.com
1904+
-- CALDaNm3oZA-8Wbps2Jd1g5_Gjrr-x3YWrJPek-mF5Asrrvz2Dg@mail.gmail.com
1905+
CREATE TABLE tt26(c int);
1906+
BEGIN;
1907+
CREATE TABLE tt27(c int);
1908+
SAVEPOINT q;
1909+
CREATE RULE "_RETURN" AS ON SELECT TO tt27 DO INSTEAD SELECT * FROM tt26;
1910+
SELECT * FROM tt27;
1911+
c
1912+
---
1913+
(0 rows)
1914+
1915+
ROLLBACK TO q;
1916+
CREATE RULE "_RETURN" AS ON SELECT TO tt27 DO INSTEAD SELECT * FROM tt26;
1917+
ROLLBACK;
1918+
BEGIN;
1919+
CREATE TABLE tt28(c int);
1920+
CREATE RULE "_RETURN" AS ON SELECT TO tt28 DO INSTEAD SELECT * FROM tt26;
1921+
CREATE RULE "_RETURN" AS ON SELECT TO tt28 DO INSTEAD SELECT * FROM tt26;
1922+
ERROR: "tt28" is already a view
1923+
ROLLBACK;
19011924
-- clean up all the random objects we made above
19021925
DROP SCHEMA temp_view_test CASCADE;
19031926
NOTICE: drop cascades to 27 other objects
@@ -1929,7 +1952,7 @@ drop cascades to view aliased_view_2
19291952
drop cascades to view aliased_view_3
19301953
drop cascades to view aliased_view_4
19311954
DROP SCHEMA testviewschm2 CASCADE;
1932-
NOTICE: drop cascades to68 other objects
1955+
NOTICE: drop cascades to69 other objects
19331956
DETAIL: drop cascades to table t1
19341957
drop cascades to view temporal1
19351958
drop cascades to view temporal2
@@ -1998,3 +2021,4 @@ drop cascades to view tt23v
19982021
drop cascades to view tt24v
19992022
drop cascades to view tt25v
20002023
drop cascades to view tt26v
2024+
drop cascades to table tt26

‎src/test/regress/sql/create_view.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,29 @@ select x + y + z as c1,
649649
from (values(1,2,3)) v(x,y,z);
650650
select pg_get_viewdef('tt26v', true);
651651

652+
653+
-- Test that changing the relkind of a relcache entry doesn't cause
654+
-- trouble. Prior instances of where it did:
655+
-- CALDaNm2yXz+zOtv7y5zBd5WKT8O0Ld3YxikuU3dcyCvxF7gypA@mail.gmail.com
656+
-- CALDaNm3oZA-8Wbps2Jd1g5_Gjrr-x3YWrJPek-mF5Asrrvz2Dg@mail.gmail.com
657+
CREATETABLEtt26(cint);
658+
659+
BEGIN;
660+
CREATETABLEtt27(cint);
661+
SAVEPOINT q;
662+
CREATERULE "_RETURN"ASONSELECT TO tt27 DO INSTEADSELECT*FROM tt26;
663+
SELECT*FROM tt27;
664+
ROLLBACK TO q;
665+
CREATERULE "_RETURN"ASONSELECT TO tt27 DO INSTEADSELECT*FROM tt26;
666+
ROLLBACK;
667+
668+
BEGIN;
669+
CREATETABLEtt28(cint);
670+
CREATERULE "_RETURN"ASONSELECT TO tt28 DO INSTEADSELECT*FROM tt26;
671+
CREATERULE "_RETURN"ASONSELECT TO tt28 DO INSTEADSELECT*FROM tt26;
672+
ROLLBACK;
673+
674+
652675
-- clean up all the random objects we made above
653676
DROPSCHEMA temp_view_test CASCADE;
654677
DROPSCHEMA testviewschm2 CASCADE;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp