我有一个如下所示的批量插入功能set_interactions(arg_rows text)
:
with inserts as (
insert into interaction (
thing_id,
associate_id, created_time)
select t->>'thing_id', t->>'associate_id', now() from
json_array_elements(arg_rows::json) t
ON CONFLICT (thing_id, associate_id) DO NOTHING
RETURNING thing_id, associate_id
) select into insert_count count(*) from inserts;
-- Followed by an insert in an unrelated table that has two triggers, neither of which touch any of the tables here (also not by any of their triggers, etc.)
Run Code Online (Sandbox Code Playgroud)
(我这样包装它是因为我需要计算实际插入的数量,而没有“假行更新”技巧。)
该表interaction
有:
触发器执行以下操作:
DECLARE …
Run Code Online (Sandbox Code Playgroud) (这篇文章的后续内容:当我在子查询中 ORDER BY 时,为什么我的 PostgreSQL 表达式索引没有被使用?)
PostgreSQL 9.5。
我不能透露全部细节,但table
有 22 列和 5 个索引:
text
(btree)text
(btree)timestamp with time zone
(btree)tsvector
(杜松子酒)bigint
(btree)(从上一篇文章你知道我试图避免创建这个额外的列,只是使用表达式索引——将两integer
列加在一起——没有成功。bigint
这里的列可能只是“整数”,但我做了一个创建它时出错;添加列、填充它并重新编制索引花了大约一个小时,所以我希望这不相关,但要提及它以防万一。)
除了tsvector
.
以下查询都只需要 12ms 并且只使用一个Index Scan
:
SELECT pk FROM table ORDER BY pk DESC LIMIT 10
SELECT pk FROM table ORDER BY text_column DESC LIMIT 10
SELECT pk FROM table ORDER BY timestamp_column DESC LIMIT 10 …
postgresql performance index optimization postgresql-9.5 postgresql-performance
这些是我的设置:
根据文档,据我所知,这种设置组合以及statement_timeout
值 3600000应该意味着长达一小时的查询超时,并且在此之前,它们和任何其他超过 ~214ms 的内容都应该产生 EXPLAIN 输出在日志中。但他们不是。
shared_preload_libraries
当我检查时已经auto_explain
默认包含。canceling statement due to statement timeout
(仅在我设置后才开始发生statement_timeout
),但日志中没有任何内容(根本没有,更不用说在报告的时间附近)显示除 xlog 启动和停止之外的任何内容。还可能缺少什么?
postgresql ×3
amazon-rds ×1
aws ×1
deadlock ×1
index ×1
logging ×1
optimization ×1
performance ×1
plpgsql ×1
upsert ×1