Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 2DDC064FE53 for ; Tue, 18 Nov 2008 20:49:12 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 11862-03 for ; Tue, 18 Nov 2008 20:49:09 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.gransy.com (unknown [82.208.29.208]) by mail.postgresql.org (Postfix) with ESMTP id A5D4864FD43 for ; Tue, 18 Nov 2008 20:49:09 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by mail.gransy.com (Postfix) with ESMTP id 8AC247AC2CB for ; Wed, 19 Nov 2008 01:49:07 +0100 (CET) Received: from mail.gransy.com ([127.0.0.1]) by localhost (nathalia.gransy.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4oImBbPprQz5 for ; Wed, 19 Nov 2008 01:49:07 +0100 (CET) Received: from [192.168.1.1] (ip-89-102-139-23.karneval.cz [89.102.139.23]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.gransy.com (Postfix) with ESMTP id 679197AC2B1 for ; Wed, 19 Nov 2008 01:49:07 +0100 (CET) Message-ID: <49236288.3000006@fuzzy.cz> Date: Wed, 19 Nov 2008 01:49:12 +0100 From: Tomas Vondra User-Agent: Thunderbird 2.0.0.9 (X11/20080213) MIME-Version: 1.0 CC: pgsql-performance@postgresql.org Subject: Re: Performance and IN clauses References: <64433.89.102.139.23.1227026325.squirrel@sq.gransy.com> <1227050965.30763.7754.camel@localhost> In-Reply-To: <1227050965.30763.7754.camel@localhost> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.681 tagged_above=0 required=5 tests=MISSING_HEADERS=1.581, RDNS_NONE=0.1 X-Spam-Level: * X-Archive-Number: 200811/159 X-Sequence-Number: 31890 > I know that it's much faster (for us) to run many smaller queries than > one large query, and I think that it's primarily because of your reason > a. Most of our problems come from Pg misunderstanding the results of a > join and making a bad plan decision. Batching dramatically reduces the > liklihood of this. > > -Mark Show us the plan (output of EXPLAIN ANALYZE), along with detailed info about the table (number of rows / pages) and environment (amount of RAM, etc.). Without these information it's impossible to tell which of the choices is right. In my experience the planner is a very good piece of software, but if you feed him with bad information about the environment / data in the beginning, you can hardly expect good plans. Occasionally I provide consultancy to developers having problems with PostgreSQL, and while most of the time (say 70% of the time) the problems are caused by mistakes in SQL or incorrect design of the system, problems with proper settings of the PostgreSQL are quite often. I really don't know if you use the default values or if you have tuned the settings (and how), but it's hard to tell from your original post. For example if you don't set the work_mem according to your settings, this may result in on-disk sorting even if you have plenty of free memory. Or if you have fast drives, the default cost settings may produce bad plans (index scan may seem too expensive), etc. And of course you may have data with complicated statistical properties, and the default level of details may not be sufficient (try increase it with SET STATISTICS for the column). Anyway - there may be glitch / corner case in the planner of course, but it's hard to tell without the EXPLAIN ANALYZE output. regards Tomas