问题描述
有一张桌子
create table container_operations
(
id uuid not null primary key,plant_id uuid not null,container_id uuid not null,contragent_id uuid,quantity integer not null,created_at timestamp not null
)
有一个包含滚动总计的物化视图,其中包含带有债务的容器操作投影,并且仍与每个操作相对应
create materialized view rolling_container_operations as (
select
id,plant_id,container_id,contragent_id,quantity,created_at,sum(-quantity) over (
partition by plant_id,contragent_id
order by created_at rows between unbounded preceding and current row
) contragent_debt_quantity,sum(quantity) over (
partition by plant_id,container_id
order by created_at rows between unbounded preceding and current row
) container_remaining_quantity,contragent_id
order by created_at rows between unbounded preceding and current row
) contragent_container_debt_quantity
from container_operations
)
refresh materialized view concurrently
存在大量操作的问题。
我想创建2个实例化视图以区分刷新频率。一个用于旧数据,一个用于去年。然后创建一个视图,它将对实例化视图执行union all
。但是我不能这样做。
我该怎么做才能减少刷新时间?也许我朝错误的方向前进?
侧问:如果当天的container_operations表中没有容器操作,我该如何搜索某天的剩余物和债务?我应该将k-nearest方法与gist索引和sql一样使用
select ...
from ...
left join lateral (
select ...
from ...
order by ... <-> ...
limit 1
) on true
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)