Joseph Shraibman <jks@selectacast.net> writes:
> => explain select * from usertable where podkey = 20;
> Index Scan using usertable_podkey_key on usertable
> (cost=0.00..16019.99 rows=5923 width=625)
> => select count(*) from usertable where podkey = 20;
> count
> -------
> 3
> (1 row)
Well, there's our problem :-(
I would suggest bumping up the statistics target for usertable.podkey
(see ALTER TABLE SET STATISTICS). Since it's only an int4 column you
could make the target 100 (instead of the default 10) without much
cost. That should give substantially finer-grain detail and hopefully
bring this estimate down out of the stratosphere. Re-analyze the table
and see what it gets you.
regards, tom lane