Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 9C9429FB802 for ; Mon, 19 Mar 2007 15:19:34 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 52139-08 for ; Mon, 19 Mar 2007 15:19:21 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from zebedee.cranntara.net (zebedee.cranntara.net [91.186.7.79]) by postgresql.org (Postfix) with ESMTP id 1AC349FB720 for ; Mon, 19 Mar 2007 15:19:22 -0300 (ADT) Received: from [62.69.36.78] (helo=bolek.coachhouse) by zebedee.cranntara.net with esmtpsa (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.62) (envelope-from ) id 1HTMRy-0002u7-78; Mon, 19 Mar 2007 18:19:20 +0000 Received: from [192.168.0.32] (helo=[192.168.0.32]) by bolek.coachhouse with esmtp (Exim 4.50) id 1HTKRm-0003b2-7q; Mon, 19 Mar 2007 16:10:58 +0000 Message-ID: <45FEB611.8070606@numerixtechnology.de> Date: Mon, 19 Mar 2007 16:10:57 +0000 From: T E Schmitz Reply-To: mailreg@numerixtechnology.de User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: mailreg@numerixtechnology.de CC: pgsql-sql@postgresql.org Subject: Re: triple self-join crawling References: <45FD9840.4040305@numerixtechnology.de> <45FE4848.5040407@numerixtechnology.de> In-Reply-To: <45FE4848.5040407@numerixtechnology.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/251 X-Sequence-Number: 27889 T E Schmitz wrote: > T E Schmitz wrote: > > Things improved hugely when I changed the JOIN clauses: see explain analyze below - can this be improved further? > > LEFT OUTER JOIN history AS past_month ON (past_month.stock = > history.stock AND past_month.day >= (history.day - 30) AND > past_month.day < history.day) > LEFT OUTER JOIN history AS past_week ON (past_week.stock = > past_month.stock AND past_week.day =past_month.day AND past_week.day >= > (history.day - 7)) QUERY PLAN GroupAggregate (cost=1370368.19..1435888.88 rows=5801 width=56) (actual time=11945.030..13163.156 rows=5801 loops=1) -> Sort (cost=1370368.19..1379715.86 rows=3739067 width=56) (actual time=11944.753..12462.623 rows=120117 loops=1) Sort Key: history.stock, history."day", history.high, history.low -> Hash Left Join (cost=160.02..391554.63 rows=3739067 width=56) (actual time=52.746..3778.409 rows=120117 loops=1) Hash Cond: ((("outer".stock)::text = ("inner".stock)::text) AND ("outer"."day" = "inner"."day")) Join Filter: ("inner"."day" >= ("outer"."day" - 7)) -> Nested Loop Left Join (cost=0.00..204441.26 rows=3739067 width=57) (actual time=0.077..2313.375 rows=120117 loops=1) Join Filter: (("inner".stock)::text = ("outer".stock)::text) -> Seq Scan on history (cost=0.00..131.01 rows=5801 width=34) (actual time=0.016..34.845 rows=5801 loops=1) -> Index Scan using idx_history_day on history past_month (cost=0.00..22.32 rows=645 width=23) (actual time=0.020..0.185 rows=21 loops=5801) Index Cond: ((past_month."day" >= ("outer"."day" - 30)) AND (past_month."day" < "outer"."day")) -> Hash (cost=131.01..131.01 rows=5801 width=23) (actual time=52.608..52.608 rows=5801 loops=1) -> Seq Scan on history past_week (cost=0.00..131.01 rows=5801 width=23) (actual time=0.010..25.110 rows=5801 loops=1) Total runtime: 13187.729 ms -- Regards, Tarlika Elisabeth Schmitz