]> granicus.if.org Git - postgresql/commitdiff
Add test case exercising formerly-unreached code in inheritance_planner.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 31 Mar 2019 19:49:06 +0000 (15:49 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 31 Mar 2019 19:49:06 +0000 (15:49 -0400)
There was some debate about whether the code I'd added to remap
AppendRelInfos obtained from the initial SELECT planning run is
actually necessary.  Add a test case demonstrating that it is.

Discussion: https://postgr.es/m/23831.1553873385@sss.pgh.pa.us

src/test/regress/expected/updatable_views.out
src/test/regress/sql/updatable_views.sql

index 6ce058f3123ad5cfa5fb6c8e0eec56873745b53e..86a2642d39517da8570a7274d0990250df487057 100644 (file)
@@ -1542,10 +1542,67 @@ SELECT * FROM base_tbl_child ORDER BY a;
  20
 (6 rows)
 
+CREATE TABLE other_tbl_parent (id int);
+CREATE TABLE other_tbl_child () INHERITS (other_tbl_parent);
+INSERT INTO other_tbl_parent VALUES (7),(200);
+INSERT INTO other_tbl_child VALUES (8),(100);
+EXPLAIN (costs off)
+UPDATE rw_view1 SET a = a + 1000 FROM other_tbl_parent WHERE a = id;
+                          QUERY PLAN                          
+--------------------------------------------------------------
+ Update on base_tbl_parent
+   Update on base_tbl_parent
+   Update on base_tbl_child
+   ->  Hash Join
+         Hash Cond: (other_tbl_parent.id = base_tbl_parent.a)
+         ->  Append
+               ->  Seq Scan on other_tbl_parent
+               ->  Seq Scan on other_tbl_child
+         ->  Hash
+               ->  Seq Scan on base_tbl_parent
+   ->  Merge Join
+         Merge Cond: (base_tbl_child.a = other_tbl_parent.id)
+         ->  Sort
+               Sort Key: base_tbl_child.a
+               ->  Seq Scan on base_tbl_child
+         ->  Sort
+               Sort Key: other_tbl_parent.id
+               ->  Append
+                     ->  Seq Scan on other_tbl_parent
+                     ->  Seq Scan on other_tbl_child
+(20 rows)
+
+UPDATE rw_view1 SET a = a + 1000 FROM other_tbl_parent WHERE a = id;
+SELECT * FROM ONLY base_tbl_parent ORDER BY a;
+  a   
+------
+ -200
+ -100
+  -40
+  -30
+  -20
+  -10
+ 1100
+ 1200
+(8 rows)
+
+SELECT * FROM base_tbl_child ORDER BY a;
+  a   
+------
+    3
+    4
+   10
+   20
+ 1007
+ 1008
+(6 rows)
+
 DROP TABLE base_tbl_parent, base_tbl_child CASCADE;
 NOTICE:  drop cascades to 2 other objects
 DETAIL:  drop cascades to view rw_view1
 drop cascades to view rw_view2
+DROP TABLE other_tbl_parent CASCADE;
+NOTICE:  drop cascades to table other_tbl_child
 -- simple WITH CHECK OPTION
 CREATE TABLE base_tbl (a int, b int DEFAULT 10);
 INSERT INTO base_tbl VALUES (1,2), (2,3), (1,-1);
index f5f88a11164bdddd2fc83c35f1f5d1e85c13c758..e50a4c52ee701877bfc7182eabbe2d3843070ff5 100644 (file)
@@ -713,7 +713,20 @@ DELETE FROM ONLY rw_view2 WHERE a IN (-8, 8); -- Should delete -8 only
 SELECT * FROM ONLY base_tbl_parent ORDER BY a;
 SELECT * FROM base_tbl_child ORDER BY a;
 
+CREATE TABLE other_tbl_parent (id int);
+CREATE TABLE other_tbl_child () INHERITS (other_tbl_parent);
+INSERT INTO other_tbl_parent VALUES (7),(200);
+INSERT INTO other_tbl_child VALUES (8),(100);
+
+EXPLAIN (costs off)
+UPDATE rw_view1 SET a = a + 1000 FROM other_tbl_parent WHERE a = id;
+UPDATE rw_view1 SET a = a + 1000 FROM other_tbl_parent WHERE a = id;
+
+SELECT * FROM ONLY base_tbl_parent ORDER BY a;
+SELECT * FROM base_tbl_child ORDER BY a;
+
 DROP TABLE base_tbl_parent, base_tbl_child CASCADE;
+DROP TABLE other_tbl_parent CASCADE;
 
 -- simple WITH CHECK OPTION