暂无图片
postgresql 触发器会减慢插入速度吗?
我来答
分享
Tom
2021-09-13
postgresql 触发器会减慢插入速度吗?

我正在构建一个触发器来跟踪进入我的 postgresql/timescaleDB 表中的每个符号的最新时间戳。
表创建定义如下所示:

create table symbol_cache (
  symbol text not null primary key,
  timestamp timestamptz not null
)

create or replace function refresh_symbol_cache() returns trigger
    language plpgsql
as $$
BEGIN
    INSERT INTO symbol_cache (symbol, timestamp)
    VALUES (
               NEW.symbol,
               NEW.timestamp
           )
    ON CONFLICT (symbol)
        DO UPDATE SET
                      symbol = NEW.symbol,
                      timestamp = GREATEST(old.timestamp, new.timestamp);
    RETURN NEW;
END;
$$;


create trigger update_symbol_cache
    after insert or update
    on db_009a005a_df_downloaded_grand
    for each row
execute procedure refresh_symbol_cache();




我来答
添加附件
收藏
分享
问题补充
1条回答
默认
最新
薛晓刚

任何针对表DML的触发器都影响 。我以前在oracle上见过一次,去掉触发器以后快了1000倍。

暂无图片 评论
暂无图片 有用 0
暂无图片
Tom
题主
2021-09-13
原来如此
回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
暂无图片墨值悬赏