Trigger vs Rule

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all.

There are two tables:

create table device_types (
id int,
name varchar
);
about 1000 rows

create table devices (
id int,
type int REFERENCES device_types(id),
name varchar,
data float
);
about 200000 rows

And about 1000 functions:
create function device_type1(int) returns ..
create function device_type2(int) returns ..
...
create function device_type1000(int) returns ..


What is faster?

One trigger with 1000 ELSE IF
if old.type=1 then 
    select device_type1(old.id);
else if old.type=2 then
	select device_type2(old.id);
...
else if old.type=1000 then
	select device_type1000(old.id);
end if;

Or 1000 rules
create rule device_type1 AS ON update to devices 
	where old.type=1  
    DO select device_type1(old.id);
create rule device_type2 AS ON update to devices 
    where old.type=2
    DO select device_type2(old.id);
...
create rule device_type1000 AS ON update to devices 
    where old.type=1000
    DO select device_type1000(old.id);

thx.

-- 
С уважением,
Ключников А.С.


[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux