Einars <einars@xxxxxxxxx> writes: > When displaying information about information about an user in our > site, I noticed an unreasonable slowdown. The culprit turned out to be > a trivial select, which determines the number of comments left by an > user: I don't see anything even slightly wrong here. Your first example pulls 15888 rows from the table in 13134 ms. Your second example pulls 3 rows from the table in 0.121 ms --- which I rather imagine is because those three rows are already in cache; it would take a lot longer if it actually had to go to disk several times. The planner's rowcount estimates are on target and it appears to be choosing appropriate plans in each case. It just takes longer to process 5000 times as many rows ... regards, tom lane