In response to Kaloyan Iliev Iliev : > Hi, > Can anyone suggest why this query so slow. > -> Index Scan using > ms_commands_history_ms_device_id_idx on ms_commands_history ch > (cost=0.00..4.33 rows=1 width=8) (actual time=0.163..25254.004 rows=9807 > loops=1) Estimated rows: 1, actual rows: 9807, that's a BIG difference and, maybe, your problem. Btw.: your explain is hard to read (line-wrapping). It's better to attach the explain as an own file... Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99 -- Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance