在具有5,000行的小型表上,我得到:
SELECT category_id FROM widgets WHERE category_id = 1;
Index Only Scan using widgets_category_id on widgets (cost=0.28..5.20 rows=26 width=8) (actual time=0.083..0.160 rows=70 loops=1)
Index Cond: (category_id = 1)
Heap Fetches: 7
Planning time: 2.758 ms
Execution time: 0.213 ms
在具有1亿行的大型表上,我得到:
SELECT customer_id FROM orders WHERE customer_id = 1;
Index Only Scan using orders_customer_id on orders (cost=0.58..1372.32 rows=65243 width=8) (actual time=0.155..0.402 rows=158 loops=1)
Index Cond: (customer_id = 1)
Heap Fetches: 109
Planning time: 16.019 ms
Execution time: 0.493 ms
在不同的表上运行一堆不同的查询时,这似乎是一个一致的主题。
我正在使用10.4版,共享缓冲区为64GB(占总RAM的25%)。