我的 postgresql 触发器会减慢我的插入速度吗

Would my postgresql trigger slows down my insert

我正在建立一个触发器来跟踪每个符号的最新时间戳进入我的 table for postgresql/timescaleDB。

table 创建定义如下所示

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();

基本上,我想问问我添加了这样的触发器后,我插入db_009a005a_df_downloaded_grand的速度会不会明显变慢?

是的,触发器会显着降低数据修改速度。天下没有免费的午餐。