小编mir*_*e2k的帖子

通过 PK 获取特定单行 id 的查询时间非常慢

EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS)  
SELECT * 
FROM contract  
WHERE contract.id = 33129;
Run Code Online (Sandbox Code Playgroud)
EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS)  
SELECT * 
FROM contract  
WHERE contract.id = 33129;
Run Code Online (Sandbox Code Playgroud)
EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS)  
SELECT * 
FROM contract  
WHERE contract.id = 33128;
Run Code Online (Sandbox Code Playgroud)
Index Scan using contract_pkey on public.contract  (cost=0.29..8.31 rows=1 width=305) (actual time=0.121..30.386 rows=1 loops=1)
  Output: id, network, address, platform_id, sync_marker, props, sync_marker_alt, interface, ingested_at, data
  Index Cond: (contract.id = 33129)
  Buffers: shared hit=325
Planning Time: 0.098 ms
Execution Time: 30.412 ms
Run Code Online (Sandbox Code Playgroud)

请注意查询时间的巨大差异。分析输出中的唯一提示似乎是共享命中。 …

postgresql performance query-performance

8
推荐指数
1
解决办法
1006
查看次数