mirror of
https://github.com/postgres/postgres.git
synced 2025-11-25 12:03:53 +03:00
Fix rewrite code so that rules are in fact executed in order by name,
rather than being reordered according to INSTEAD attribute for implementation convenience. Also, increase compiled-in recursion depth limit from 10 to 100 rewrite cycles. 10 seems pretty marginal for situations where multiple rules exist for the same query. There was a complaint about this recently, so I'm going to bump it up. (Perhaps we should make the limit a GUC parameter, but that's too close to being a new feature to do in beta.)
This commit is contained in:
@@ -83,22 +83,25 @@ create rule rtest_t6_ins as on insert to rtest_t6
|
||||
--
|
||||
-- Tables and rules for the rule fire order test
|
||||
--
|
||||
-- As of PG 7.3, the rules should fire in order by name, regardless
|
||||
-- of INSTEAD attributes or creation order.
|
||||
--
|
||||
create table rtest_order1 (a int4);
|
||||
create table rtest_order2 (a int4, b int4, c text);
|
||||
create sequence rtest_seq;
|
||||
create rule rtest_order_r3 as on insert to rtest_order1 do instead
|
||||
insert into rtest_order2 values (new.a, nextval('rtest_seq'),
|
||||
'rule 3 - this should run 3rd or 4th');
|
||||
'rule 3 - this should run 3rd');
|
||||
create rule rtest_order_r4 as on insert to rtest_order1
|
||||
where a < 100 do instead
|
||||
insert into rtest_order2 values (new.a, nextval('rtest_seq'),
|
||||
'rule 4 - this should run 2nd');
|
||||
'rule 4 - this should run 4th');
|
||||
create rule rtest_order_r2 as on insert to rtest_order1 do
|
||||
insert into rtest_order2 values (new.a, nextval('rtest_seq'),
|
||||
'rule 2 - this should run 1st');
|
||||
'rule 2 - this should run 2nd');
|
||||
create rule rtest_order_r1 as on insert to rtest_order1 do instead
|
||||
insert into rtest_order2 values (new.a, nextval('rtest_seq'),
|
||||
'rule 1 - this should run 3rd or 4th');
|
||||
'rule 1 - this should run 1st');
|
||||
--
|
||||
-- Tables and rules for the instead nothing test
|
||||
--
|
||||
@@ -644,12 +647,12 @@ select * from rtest_t8;
|
||||
--
|
||||
insert into rtest_order1 values (1);
|
||||
select * from rtest_order2;
|
||||
a | b | c
|
||||
---+---+-------------------------------------
|
||||
1 | 1 | rule 2 - this should run 1st
|
||||
1 | 2 | rule 4 - this should run 2nd
|
||||
1 | 3 | rule 1 - this should run 3rd or 4th
|
||||
1 | 4 | rule 3 - this should run 3rd or 4th
|
||||
a | b | c
|
||||
---+---+------------------------------
|
||||
1 | 1 | rule 1 - this should run 1st
|
||||
1 | 2 | rule 2 - this should run 2nd
|
||||
1 | 3 | rule 3 - this should run 3rd
|
||||
1 | 4 | rule 4 - this should run 4th
|
||||
(4 rows)
|
||||
|
||||
--
|
||||
@@ -1321,10 +1324,10 @@ SELECT tablename, rulename, definition FROM pg_rules
|
||||
rtest_nothn1 | rtest_nothn_r2 | CREATE RULE rtest_nothn_r2 AS ON INSERT TO rtest_nothn1 WHERE ((new.a >= 30) AND (new.a < 40)) DO INSTEAD NOTHING;
|
||||
rtest_nothn2 | rtest_nothn_r3 | CREATE RULE rtest_nothn_r3 AS ON INSERT TO rtest_nothn2 WHERE (new.a >= 100) DO INSTEAD INSERT INTO rtest_nothn3 (a, b) VALUES (new.a, new.b);
|
||||
rtest_nothn2 | rtest_nothn_r4 | CREATE RULE rtest_nothn_r4 AS ON INSERT TO rtest_nothn2 DO INSTEAD NOTHING;
|
||||
rtest_order1 | rtest_order_r1 | CREATE RULE rtest_order_r1 AS ON INSERT TO rtest_order1 DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 1 - this should run 3rd or 4th'::text);
|
||||
rtest_order1 | rtest_order_r2 | CREATE RULE rtest_order_r2 AS ON INSERT TO rtest_order1 DO INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 2 - this should run 1st'::text);
|
||||
rtest_order1 | rtest_order_r3 | CREATE RULE rtest_order_r3 AS ON INSERT TO rtest_order1 DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 3 - this should run 3rd or 4th'::text);
|
||||
rtest_order1 | rtest_order_r4 | CREATE RULE rtest_order_r4 AS ON INSERT TO rtest_order1 WHERE (new.a < 100) DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 4 - this should run 2nd'::text);
|
||||
rtest_order1 | rtest_order_r1 | CREATE RULE rtest_order_r1 AS ON INSERT TO rtest_order1 DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 1 - this should run 1st'::text);
|
||||
rtest_order1 | rtest_order_r2 | CREATE RULE rtest_order_r2 AS ON INSERT TO rtest_order1 DO INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 2 - this should run 2nd'::text);
|
||||
rtest_order1 | rtest_order_r3 | CREATE RULE rtest_order_r3 AS ON INSERT TO rtest_order1 DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 3 - this should run 3rd'::text);
|
||||
rtest_order1 | rtest_order_r4 | CREATE RULE rtest_order_r4 AS ON INSERT TO rtest_order1 WHERE (new.a < 100) DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 4 - this should run 4th'::text);
|
||||
rtest_person | rtest_pers_del | CREATE RULE rtest_pers_del AS ON DELETE TO rtest_person DO DELETE FROM rtest_admin WHERE (rtest_admin.pname = old.pname);
|
||||
rtest_person | rtest_pers_upd | CREATE RULE rtest_pers_upd AS ON UPDATE TO rtest_person DO UPDATE rtest_admin SET pname = new.pname WHERE (rtest_admin.pname = old.pname);
|
||||
rtest_system | rtest_sys_del | CREATE RULE rtest_sys_del AS ON DELETE TO rtest_system DO (DELETE FROM rtest_interface WHERE (rtest_interface.sysname = old.sysname); DELETE FROM rtest_admin WHERE (rtest_admin.sysname = old.sysname); );
|
||||
|
||||
@@ -100,6 +100,9 @@ create rule rtest_t6_ins as on insert to rtest_t6
|
||||
--
|
||||
-- Tables and rules for the rule fire order test
|
||||
--
|
||||
-- As of PG 7.3, the rules should fire in order by name, regardless
|
||||
-- of INSTEAD attributes or creation order.
|
||||
--
|
||||
create table rtest_order1 (a int4);
|
||||
create table rtest_order2 (a int4, b int4, c text);
|
||||
|
||||
@@ -107,20 +110,20 @@ create sequence rtest_seq;
|
||||
|
||||
create rule rtest_order_r3 as on insert to rtest_order1 do instead
|
||||
insert into rtest_order2 values (new.a, nextval('rtest_seq'),
|
||||
'rule 3 - this should run 3rd or 4th');
|
||||
'rule 3 - this should run 3rd');
|
||||
|
||||
create rule rtest_order_r4 as on insert to rtest_order1
|
||||
where a < 100 do instead
|
||||
insert into rtest_order2 values (new.a, nextval('rtest_seq'),
|
||||
'rule 4 - this should run 2nd');
|
||||
'rule 4 - this should run 4th');
|
||||
|
||||
create rule rtest_order_r2 as on insert to rtest_order1 do
|
||||
insert into rtest_order2 values (new.a, nextval('rtest_seq'),
|
||||
'rule 2 - this should run 1st');
|
||||
'rule 2 - this should run 2nd');
|
||||
|
||||
create rule rtest_order_r1 as on insert to rtest_order1 do instead
|
||||
insert into rtest_order2 values (new.a, nextval('rtest_seq'),
|
||||
'rule 1 - this should run 3rd or 4th');
|
||||
'rule 1 - this should run 1st');
|
||||
|
||||
--
|
||||
-- Tables and rules for the instead nothing test
|
||||
|
||||
Reference in New Issue
Block a user