Thanks Craig. Yes I already tried it but it didn't work. I don't see any solution other than fixing this bug. Take a look http://www.postgresql.org/search/?m=1&q=LIMIT&l=8&d=365&s=r. There are too many bug reports about LIMIT slowing down queries. Let's hope it will be fixed someday :)
Date: Fri, 16 Nov 2012 08:32:24 -0800 Subject: Re: PostgreSQL strange query plan for my query From: cjames@xxxxxxxxxxxxxx To: dato0011@xxxxxxxxxxx CC: pgsql-performance@xxxxxxxxxxxxxx On Fri, Nov 16, 2012 at 3:40 AM, David Popiashvili <dato0011@xxxxxxxxxxx> wrote:
You probably checked this already, but just in case you didn't ... did you do an "analyze" on the small table? I've been hit by this before ... it's natural to think that Postgres would always check a very small table first no matter what the statistics are. But it's not true. If you analyze the small table, even if it only has one or two rows in it, it will often radically change the plan that Postgres chooses. Craig James |