Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id CEE8365018A for ; Thu, 7 Aug 2008 12:51:23 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 40666-03-2 for ; Thu, 7 Aug 2008 12:51:18 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 25B4A65031F for ; Thu, 7 Aug 2008 12:51:01 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m77Foxuk012708; Thu, 7 Aug 2008 11:50:59 -0400 (EDT) To: Giorgio Valoti cc: pgsql-performance@postgresql.org Subject: Re: Query Plan choice with timestamps In-reply-to: <321506D5-4400-470C-909E-C7700D49A540@mac.com> References: <321506D5-4400-470C-909E-C7700D49A540@mac.com> Comments: In-reply-to Giorgio Valoti message dated "Thu, 07 Aug 2008 09:50:04 +0200" Date: Thu, 07 Aug 2008 11:50:59 -0400 Message-ID: <12707.1218124259@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200808/46 X-Sequence-Number: 30927 Giorgio Valoti writes: > GroupAggregate (cost=98431.58..119773.92 rows=74226 width=8) > -> Sort (cost=98431.58..99050.92 rows=247736 width=8) > Sort Key: (day_trunc(ts)) > -> Seq Scan on blackbox (cost=0.00..72848.36 rows=247736 width=8) > GroupAggregate (cost=0.00..19109.66 rows=74226 width=8) > -> Index Scan using test_2_idx on blackbox (cost=0.00..16943.16 rows=247736 width=8) These numbers seem pretty bogus: there is hardly any scenario in which a full-table indexscan should be costed as significantly cheaper than a seqscan. Have you put in silly values for random_page_cost? If you haven't mucked with the cost parameters, the only way I can think of to get this result is to have an enormously bloated table that's mostly empty. Maybe you need to review your vacuuming procedures. regards, tom lane