通常在一段时间内第一次会花费很多时间。在那之后,将花费相似的时间。
表大小:6.4M
explain analyze
SELECT count(*) as "count", "bookId"
FROM "libraries"
WHERE "bookId" IN ('1', '2', '3', '4', '5')
GROUP BY "bookId";
GroupAggregate (cost=0.56..17520.53 rows=4308 width=33) (actual time=438.948..2258.747 rows=9 loops=1)
Group Key: "bookId"
-> Index Only Scan using "libraries_bookId" on libraries (cost=0.56..17445.19 rows=6452 width=25) (actual time=0.798..2249.024 rows=32306 loops=1)
Index Cond: ("bookId" = ANY ('{1, 2, 3, 4, 5}'::text[]))
Heap Fetches: 32306
Planning time: 0.254 ms
Execution time: 2258.813 ms