Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 6DBEB2E335B for ; Mon, 11 Feb 2008 14:08:46 -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 87777-02 for ; Mon, 11 Feb 2008 14:08:40 -0400 (AST) Received: from mail.ptt.uni-duisburg.de (trottoir.ptt.uni-duisburg.de [134.91.151.36]) by postgresql.org (Postfix) with ESMTP id 47B0F2E00AC for ; Mon, 11 Feb 2008 14:08:40 -0400 (AST) Received: (qmail 80549 invoked by uid 0); 11 Feb 2008 18:09:00 -0000 Received: from 134.91.151.30 by trottoir.ptt.uni-duisburg.de (envelope-from , uid 89) with qmail-scanner-1.25 (sweep: 2.44.1/4.16.0. /636764. spamassassin: 3.2.1. Clear:RC:1(134.91.151.30):. Processed in 3.782459 secs); 11 Feb 2008 18:09:00 -0000 X-Qmail-Scanner-Mail-From: zaksek@ptt.uni-due.de via trottoir.ptt.uni-duisburg.de X-Qmail-Scanner: 1.25 (Clear:RC:1(134.91.151.30):. Processed in 3.782459 secs) Received: from unknown (HELO finkenstrasse.ptt.uni-duisburg.de) (zaksek@ptt.uni-due.de@134.91.151.30) by mail.ptt.uni-duisburg.de with ESMTPA; 11 Feb 2008 18:08:56 -0000 Message-ID: <47B08F19.8000500@ptt.uni-due.de> Date: Mon, 11 Feb 2008 19:08:25 +0100 From: Thomas Zaksek User-Agent: Thunderbird 2.0.0.9 (X11/20071115) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Join Query Perfomance Issue Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200802/100 X-Sequence-Number: 28642 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) -> Index Scan using messungen_v_dat_2007_11_12_messpunkt_minute_tag_idx on messungen_v_dat_2007_11_12 m (cost=0.00..5063.38 rows=3009 width=4) (actual time=0.131..9.262 rows=2189 loops=1) Index Cond: ((ganglinientyp = 'M'::bpchar) AND (381 = minute_tag)) -> Index Scan using messpunkt_nr_idx on messpunkt p (cost=0.00..8.50 rows=1 width=12) (actual time=0.019..0.023 rows=1 loops=2189) Index Cond: (p.nr = m.messpunkt) -> Index Scan using de_nw_nr_idx on de_mw w (cost=0.00..6.53 rows=1 width=10) (actual time=0.019..0.023 rows=1 loops=2189) Index Cond: (p.mw_nr = w.nr) Total runtime: 329.134 ms (9 rows) Doesnt looks too bad to me, but i'm not that deep into sql query optimization. However, these type of query is used in a function to access a normalized, partitioned database, so better performance in this queries would speed up the whole database system big times. Any suggestions here would be great. I allready tested some things, using inner join, rearranging the order of the tables, but but only minor changes in the runtime, the version above seemed to get us the best performance. / /