Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id C84D32E3252 for ; Mon, 11 Feb 2008 17:37:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 87144-06 for ; Mon, 11 Feb 2008 17:37:37 -0400 (AST) Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.238]) by postgresql.org (Postfix) with ESMTP id DD2A32E324B for ; Mon, 11 Feb 2008 17:37:36 -0400 (AST) Received: by wr-out-0506.google.com with SMTP id 71so4716462wri.5 for ; Mon, 11 Feb 2008 13:37:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=yVBTCEEXSKAcdmprqjur4loFwxriKY326NMMoNqryxw=; b=ZWYD0Z842quMtOJdyupeSr423GlqQRzPkily3zxJ0Z5awYbaZW2DvGV/eiq98u4l0xXt+z1vam3gqtHB3V1ZOfKhPT8efYeNnEUz7fKyD20S5UJH3HsVUUEN5UVN/5JdyzIkO51fVhgqZRtd9KectlD6TUj6UrD5139UAIuAOmw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=myfNQO1if0gNHB/yFKyumvhpuwC3saFdoWS4W8URcXVMigJnbHvJ7+M7NkwDVQEKenDxLjqb9ch880G1m4PVBq7/P7UIlcrlruFaPwX1/qETY1jUyQd4YAP4igxAarSwXOnh/d0USkk1wNRlL1MlX+vzYjf7u1wdh5TmB+m+X70= Received: by 10.114.194.1 with SMTP id r1mr563380waf.40.1202765854337; Mon, 11 Feb 2008 13:37:34 -0800 (PST) Received: by 10.114.131.4 with HTTP; Mon, 11 Feb 2008 13:37:34 -0800 (PST) Message-ID: Date: Mon, 11 Feb 2008 15:37:34 -0600 From: "Scott Marlowe" To: "Thomas Zaksek" Subject: Re: Join Query Perfomance Issue Cc: pgsql-performance@postgresql.org In-Reply-To: <47B08F19.8000500@ptt.uni-due.de> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <47B08F19.8000500@ptt.uni-due.de> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/104 X-Sequence-Number: 28646 On Feb 11, 2008 12:08 PM, Thomas Zaksek wrote: > I have serious performance problems with the following type of queries: > / > /explain analyse SELECT '12.11.2007 18:04:00 UTC' AS zeit, > 'M' AS datatyp, > p.zs_nr AS zs_de, > j_ges, > de_mw_abh_j_lkw(mw_abh) AS j_lkw, > de_mw_abh_v_pkw(mw_abh) AS v_pkw, > de_mw_abh_v_lkw(mw_abh) AS v_lkw, > de_mw_abh_p_bel(mw_abh) AS p_bel > FROM messpunkt p, messungen_v_dat_2007_11_12 m, de_mw w > WHERE m.ganglinientyp = 'M' > AND 381 = m.minute_tag > AND (p.nr, p.mw_nr) = (m.messpunkt, w.nr); > > Explain analze returns > > Nested Loop (cost=0.00..50389.39 rows=3009 width=10) (actual > time=0.503..320.872 rows=2189 loops=1) > -> Nested Loop (cost=0.00..30668.61 rows=3009 width=8) (actual > time=0.254..94.116 rows=2189 loops=1) This nested loop is using us most of your time. Try increasing work_mem and see if it chooses a better join plan, and / or turn off nested loops for a moment and see if that helps. set enable_nestloop = off Note that set enable_xxx = off Is kind of a hammer to the forebrain setting. It's not subtle, and the planner can't work around it. So use them with caution. That said, I had one reporting query that simply wouldn't run fast without turning off nested loops for that one. But don't turn off nested queries universally, they are still a good choice for smaller amounts of data.