OK I'm bumping this one last time in the hopes that someone has an idea what to do to fix it. Query plan: http://explain.depesz.com/s/kJ54 This query takes 180 seconds. It loops 17391 times across the lower index using entries from the upper index. That seems buggy to me. While the exact estimates are off, the fact that it estimates 10,433 rows in the above index scan means that it's expecting to do that many loops on the bottom index scan. This is one of those queries where adding an offset 0 to the inner select reduces run time from 180s to 0.2s. And I can't imagine a plan that thinks running 10k loops on an index scan is a good idea. -- Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance