Я использую PostgreSQL DB для своей производственной базы данных, и недавно я изменил размер дискового тома моего производственного сервера.
И я заметил, что запрос к определенной таблице (~ 10K записей) чрезвычайно медленный,
EXPLAIN (analyze, buffers, timing) SELECT count(id) FROM markets_sales WHERE volume>0;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------
Aggregate (cost=1844791.17..1844791.18 rows=1 width=4) (actual time=79842.776..79842.777 rows=1 loops=1)
Buffers: shared hit=2329 read=1842313
-> Seq Scan on markets_sales (cost=0.00..1844782.68 rows=3399 width=4) (actual time=8139.929..79842.043 rows=6731 loops=1)
Filter: (volume > '0'::double precision)
Rows Removed by Filter: 4523
Buffers: shared hit=2329 read=1842313
Planning time: 0.110 ms
Execution time: 79842.809 ms
Но аналогичный запрос для другой таблицы (~ 2K записей) идеален.
EXPLAIN ANALYZE SELECT count(id) FROM markets_volume WHERE percent>0;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
Aggregate (cost=1368.87..1368.88 rows=1 width=4) (actual time=1.866..1.866 rows=1 loops=1)
-> Seq Scan on markets_volume (cost=0.00..1365.59 rows=1312 width=4) (actual time=0.023..1.751 rows=1313 loops=1)
Filter: (h24_change > '0'::double precision)
Rows Removed by Filter: 1614
Planning time: 0.093 ms
Execution time: 1.903 ms
(6 rows)