Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 863541338105 for ; Thu, 16 Sep 2010 05:31:37 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 91206-05 for ; Thu, 16 Sep 2010 08:31:30 +0000 (UTC) X-Greylist: delayed 00:07:38.949033 by SQLgrey-1.7.6 Received: from smtp21.orange.fr (smtp21.orange.fr [80.12.242.47]) by mail.postgresql.org (Postfix) with ESMTP id 4AF6A1338104 for ; Thu, 16 Sep 2010 05:31:30 -0300 (ADT) Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2108.orange.fr (SMTP Server) with ESMTP id EA9921C0050F for ; Thu, 16 Sep 2010 10:23:49 +0200 (CEST) Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2108.orange.fr (SMTP Server) with ESMTP id DB3671C0033A for ; Thu, 16 Sep 2010 10:23:49 +0200 (CEST) Received: from axege.com (LNeuilly-152-22-23-133.w193-251.abo.wanadoo.fr [193.251.23.133]) by mwinf2108.orange.fr (SMTP Server) with ESMTP id AF32A1C0050F for ; Thu, 16 Sep 2010 10:23:49 +0200 (CEST) X-ME-UUID: 20100916082349717.AF32A1C0050F@mwinf2108.orange.fr Received: from localhost (localhost [127.0.0.1]) by axege.com (Postfix) with ESMTP id 4B75D4FEF9 for ; Thu, 16 Sep 2010 10:23:49 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at myhostname="axege.com." Received: from axege.com ([127.0.0.1]) by localhost (axege.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PYFwwjqO-x3z for ; Thu, 16 Sep 2010 10:23:48 +0200 (CEST) Received: from [10.0.0.69] (unknown [10.0.0.69]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by axege.com (Postfix) with ESMTPSA id C95A24FDA6 for ; Thu, 16 Sep 2010 10:23:48 +0200 (CEST) Subject: Is disableing nested_loops a bad idea ? From: Franck Routier To: pgsql-performance@postgresql.org Content-Type: text/plain; charset="UTF-8" Organization: =?ISO-8859-1?Q?Ax=E8ge?= sarl Date: Thu, 16 Sep 2010 10:23:47 +0200 Message-ID: <1284625427.2527.13.camel@franck-laptop> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.001 tagged_above=-10 required=5 tests=BAYES_20=-0.001, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201009/99 X-Sequence-Number: 40302 Hi, I am confronted with a use case where my database mainly does big aggregate select (ROLAP), a bunch of batch jobs, and quite few OLTP. I come into cases where the planner under-estimates the number of rows in some relations, chooses to go for nested loops, and takes forever to complete the request. (Notice as the side note that Oracle (10g or 11g) is not any better on this workload and will sometime go crazy and choose a plan that takes hours...) I've played with statistics, vacuum and so on, but at the end the planner is not accurate enough when evaluating the number of rows in some complex queries. Disableing nested loops most of the time solves the performance issues in my tests... generally going from 30 sec. down to 1 sec. So my question is : would it be a very bad idea to disable nested loops in production ? The way I see it is that it could be a little bit less optimal to use merge join or hash join when joining on a few rows, but this is peanuts compared to how bad it is to use nested loops when the number of rows happens to be much higher than what the planner thinks. Is this stupid, ie are there cases when merge join or hash join are much slower than nested loops on a few rows ? Thanks in advance, Franck