示例
示例
EXPLAIN (ANALYZE, BUFFERS, TIMING)
SELECT o.id, o.total
FROM orders o
WHERE o.user_id = 100;
-- 输出示例:
-- Index Scan using idx_orders_user on orders o
-- (actual time=0.05..0.30 rows=12 loops=1)
-- Index Cond: (user_id = 100)
-- Buffers: shared hit=5 read=2
-- Planning Time: 0.3 ms
-- Execution Time: 0.5 ms写语句安全实测
写语句安全实测
BEGIN;
EXPLAIN (ANALYZE) UPDATE orders SET status = 'x' WHERE id = 1;
ROLLBACK; -- 实测后回滚| actual time | 首行..末行的实测耗时(毫秒) |
|---|---|
| rows=12 loops=1 | 每次循环平均行数;总行数为 rows × loops |
| Buffers | shared hit/read:命中内存与读磁盘的块数 |
| TIMING off | 关闭逐节点计时可减少测量开销,汇总时间仍保留 |
ANALYZE 会真正执行语句:写操作必须在事务里执行后回滚,且避开业务高峰。