Jaime,
> Why is this query using a seq scan rather than a index scan?
Because it thinks a seq scan will be faster.
> i notice
> the diff between the estimated rows and actual rows (almost 2000).
Yes, ANALYZE, and possibly increasing the column stats, should help that.
> Can this affect the query plan? i think this is a problem of
> statistics, am i right? if so, what can be done?
Well, if the estimate was accurate, PG would be even *more* likely to use a
seq scan (more rows).
I think maybe you should establish whether a seq scan actually *is* faster?
Perhaps do SET enable_seqscan = false and then re-run the query a few times?
--
Josh Berkus
Aglio Database Solutions
San Francisco