summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane2007-05-26 18:23:02 +0000
committerTom Lane2007-05-26 18:23:02 +0000
commitcadb78330eedceafeda99bf12ac690cda773be62 (patch)
tree6d4b9004701763c29fb88f1afecef8c81207df9e /src/test
parent604ffd280b955100e5fc24649ee4d42a6f3ebf35 (diff)
Repair two constraint-exclusion corner cases triggered by proving that an
inheritance child of an UPDATE/DELETE target relation can be excluded by constraints. I had rearranged some code in set_append_rel_pathlist() to avoid "useless" work when a child is excluded, but overdid it and left the child with no cheapest_path entry, causing possible failure later if the appendrel was involved in a join. Also, it seems that the dummy plan generated by inheritance_planner() when all branches are excluded has to be a bit less dummy now than was required in 8.2. Per report from Jan Wieck. Add his test case to the regression tests.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/rules.out58
-rw-r--r--src/test/regress/sql/rules.sql38
2 files changed, 96 insertions, 0 deletions
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 112891bbb2..e1098fd684 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -1493,3 +1493,61 @@ select * from id_ordered;
set client_min_messages to warning; -- suppress cascade notices
drop table id cascade;
+reset client_min_messages;
+--
+-- check corner case where an entirely-dummy subplan is created by
+-- constraint exclusion
+--
+create temp table t1 (a integer primary key);
+NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "t1_pkey" for table "t1"
+create temp table t1_1 (check (a >= 0 and a < 10)) inherits (t1);
+create temp table t1_2 (check (a >= 10 and a < 20)) inherits (t1);
+create rule t1_ins_1 as on insert to t1
+ where new.a >= 0 and new.a < 10
+ do instead
+ insert into t1_1 values (new.a);
+create rule t1_ins_2 as on insert to t1
+ where new.a >= 10 and new.a < 20
+ do instead
+ insert into t1_2 values (new.a);
+create rule t1_upd_1 as on update to t1
+ where old.a >= 0 and old.a < 10
+ do instead
+ update t1_1 set a = new.a where a = old.a;
+create rule t1_upd_2 as on update to t1
+ where old.a >= 10 and old.a < 20
+ do instead
+ update t1_2 set a = new.a where a = old.a;
+set constraint_exclusion = on;
+insert into t1 select * from generate_series(5,19,1) g;
+update t1 set a = 4 where a = 5;
+select * from only t1;
+ a
+---
+(0 rows)
+
+select * from only t1_1;
+ a
+---
+ 6
+ 7
+ 8
+ 9
+ 4
+(5 rows)
+
+select * from only t1_2;
+ a
+----
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+(10 rows)
+
diff --git a/src/test/regress/sql/rules.sql b/src/test/regress/sql/rules.sql
index 374e11d671..e898336d92 100644
--- a/src/test/regress/sql/rules.sql
+++ b/src/test/regress/sql/rules.sql
@@ -881,3 +881,41 @@ select * from id_ordered;
set client_min_messages to warning; -- suppress cascade notices
drop table id cascade;
+reset client_min_messages;
+
+--
+-- check corner case where an entirely-dummy subplan is created by
+-- constraint exclusion
+--
+
+create temp table t1 (a integer primary key);
+
+create temp table t1_1 (check (a >= 0 and a < 10)) inherits (t1);
+create temp table t1_2 (check (a >= 10 and a < 20)) inherits (t1);
+
+create rule t1_ins_1 as on insert to t1
+ where new.a >= 0 and new.a < 10
+ do instead
+ insert into t1_1 values (new.a);
+create rule t1_ins_2 as on insert to t1
+ where new.a >= 10 and new.a < 20
+ do instead
+ insert into t1_2 values (new.a);
+
+create rule t1_upd_1 as on update to t1
+ where old.a >= 0 and old.a < 10
+ do instead
+ update t1_1 set a = new.a where a = old.a;
+create rule t1_upd_2 as on update to t1
+ where old.a >= 10 and old.a < 20
+ do instead
+ update t1_2 set a = new.a where a = old.a;
+
+set constraint_exclusion = on;
+
+insert into t1 select * from generate_series(5,19,1) g;
+update t1 set a = 4 where a = 5;
+
+select * from only t1;
+select * from only t1_1;
+select * from only t1_2;