更复杂的是,这样的触发逻辑可能很快就会变得太复杂,我们最终可能会决定在某个时候触发完全刷新这样的解决方案。@MarkBarinstein同意,不幸的是,DB2fori不支持系统维护的MQT。但是,如果您需要对MQT进行实时更新,那么更新MQT的触发器是唯一
更复杂的是,这样的触发逻辑可能很快就会变得太复杂,我们最终可能会决定在某个时候触发完全刷新这样的解决方案。@MarkBarinstein同意,不幸的是,DB2fori不支持系统维护的MQT。但是,如果您需要对MQT进行实时更新,那么更新MQT的触发器是唯一,db2,database-trigger,db2-400,materialized-views,Db2,Database Trigger,Db2 400,Materialized Views,更复杂的是,这样的触发逻辑可能很快就会变得太复杂,我们最终可能会决定在某个时候触发完全刷新这样的解决方案。@MarkBarinstein同意,不幸的是,DB2fori不支持系统维护的MQT。但是,如果您需要对MQT进行实时更新,那么更新MQT的触发器是唯一的选项。如果不需要实时,则可以进行计划刷新(使用刷新语句或用户程序)。让触发器使用刷新命令没有意义。 REFERENCING OLD TABLE AS ___ NEW TABLE AS ___ create table
更复杂的是,这样的触发逻辑可能很快就会变得太复杂,我们最终可能会决定在某个时候触发完全刷新这样的解决方案。@MarkBarinstein同意,不幸的是,DB2fori不支持系统维护的MQT。但是,如果您需要对MQT进行实时更新,那么更新MQT的触发器是唯一的选项。如果不需要实时,则可以进行计划刷新(使用刷新语句或用户程序)。让触发器使用刷新命令没有意义。
REFERENCING OLD TABLE AS ___
NEW TABLE AS ___
create table test (id int not null primary key, a int)@
create table test_mqt (cnt) as (select sum(a) from test) data initially deferred refresh deferred maintained by user@
insert into test values (1, 1), (2, 1), (3, 1) with nc@
create or replace trigger test_aus
after update on test
referencing
new table as n
old table as o
for each statement
mode db2sql
begin atomic
if (exists (select 1 from n,o where n.id=o.id and n.a<>o.a)) then
refresh table test_mqt;
end if;
end@
-- trigger IS NOT fired after the following update
update test set a=1 with nc@
-- the following select returns 0
select cnt from test_mqt@
-- trigger IS fired after the following update
update test set a=2 with nc@
-- the following select returns 6
select cnt from test_mqt@
create or replace trigger test_aus
after update on test
referencing
new row as n
old row as o
for each row
mode db2sql
begin atomic
if n.a <> o.a then
update test_mqt set cnt = cnt + n.a - o.a;
end if;
end@
after update of a on test
for each row
create or replace trigger test_aus
after update on test
referencing
new table as n
old table as o
for each statement
mode db2sql
begin atomic
update test_mqt
set cnt = cnt + (select sum(n.a - o.a)
from N join O using(id)
where n.a <> o.a
);
end@
CREATE ENCODED VECTOR INDEX sales_fact_location_id_evi
ON sales_fact(sale_location_id ASC)
INCLUDE(SUM(sale_amount_measure))