Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 5E5C62E00C0 for ; Wed, 13 Feb 2008 07:45:26 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 46533-10 for ; Wed, 13 Feb 2008 07:45:14 -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 2D1142E0064 for ; Wed, 13 Feb 2008 07:45:20 -0400 (AST) Received: (qmail 47105 invoked by uid 0); 13 Feb 2008 11:45:39 -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 4.080652 secs); 13 Feb 2008 11:45:39 -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 4.080652 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; 13 Feb 2008 11:45:35 -0000 Message-ID: <47B2D840.6060802@ptt.uni-due.de> Date: Wed, 13 Feb 2008 12:45:04 +0100 From: Thomas Zaksek User-Agent: Thunderbird 2.0.0.9 (X11/20071115) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Join Query Perfomance Issue References: <47B08F19.8000500@ptt.uni-due.de> <4544e0330802121234l33be13a9g5dec39ef032f6268@mail.gmail.com> In-Reply-To: <4544e0330802121234l33be13a9g5dec39ef032f6268@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; 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/131 X-Sequence-Number: 28673 We have tried some recoding now, using a materialized view we could reduce the query to a join over too tables without any functions inside the query, for example: explain analyse SELECT '12.11.2007 18:04:00 UTC' AS zeit, 'M' AS ganglinientyp, zs_de, j_ges, j_lkw, v_pkw, v_lkw, p_bel FROM messungen_v_dat_2007_11_12 m LEFT JOIN messwerte_mv w on w.nr = m.messpunkt WHERE m.ganglinientyp = 'M' AND 992 = m.minute_tag; Nested Loop Left Join (cost=0.00..32604.48 rows=3204 width=14) (actual time=11.991..2223.227 rows=2950 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..5371.09 rows=3204 width=4) (actual time=0.152..12.385 rows=2950 loops=1) Index Cond: ((ganglinientyp = 'M'::bpchar) AND (992 = minute_tag)) -> Index Scan using messwerte_mv_nr_idx on messwerte_mv w (cost=0.00..8.49 rows=1 width=18) (actual time=0.730..0.734 rows=1 loops=2950) Index Cond: (w.nr = m.messpunkt) Total runtime: 2234.143 ms (6 rows) To me this plan looks very clean and nearly optimal, BUT ~2seconds for the nested loop can't be that good, isn't it? The behavior of this query and the database is quite a mystery for me, yesterday i had it running in about 100ms, today i started testing with the same query and 2000-3000ms :( Could this be some kind of a postgresql server/configuration problem? This queries are very perfomance dependend, they are called a lot of times in a comlex physical real time simulation of traffic systems. 200ms would be ok here, but >1sec is perhaps not functional. The old version just used one big (partitioned) table without any joins, performing this query in 10-300ms, depended on the server load.