Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 118AD64FF05 for ; Thu, 7 Aug 2008 09:36:24 -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 57183-05 for ; Thu, 7 Aug 2008 09:36:16 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from pih-relay05.plus.net (pih-relay05.plus.net [212.159.14.132]) by postgresql.org (Postfix) with ESMTP id 2C4DE64FCF4 for ; Thu, 7 Aug 2008 09:36:21 -0300 (ADT) Received: from [84.51.143.99] (helo=server3.office.archonet.com) by pih-relay05.plus.net with esmtp (Exim) id 1KR4j4-0008Rm-AZ; Thu, 07 Aug 2008 13:36:18 +0100 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id D788B274053; Thu, 7 Aug 2008 13:36:17 +0100 (BST) Message-ID: <489AEC42.5080007@archonet.com> Date: Thu, 07 Aug 2008 13:36:18 +0100 From: Richard Huxton User-Agent: Thunderbird 2.0.0.16 (X11/20080707) MIME-Version: 1.0 To: Giorgio Valoti CC: pgsql-performance@postgresql.org Subject: Re: Query Plan choice with timestamps References: <321506D5-4400-470C-909E-C7700D49A540@mac.com> <489AB3EB.8040903@archonet.com> <15821866-9564-40E8-BC12-52ADD6D6EEA5@mac.com> In-Reply-To: <15821866-9564-40E8-BC12-52ADD6D6EEA5@mac.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: quoted-printable X-Plusnet-Relay: 6777761ff3e3da690a1a4ecabf901188 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/38 X-Sequence-Number: 30919 Giorgio Valoti wrote: >=20 > On 07/ago/08, at 10:35, Richard Huxton wrote: >=20 >> Giorgio Valoti wrote: >>> Hi, I have a timestamptz field that I want to use with a query, but I= =20 >>> don=92t need the full timestamp resolution, so I=92ve created a=20 >>> day_trunc(timestamptz) immutable function which I=92ll use with the=20 >>> query and with a new index: >>> logs=3D> create index test_idx on blackbox (day_trunc(ts)); >>> However, the query plan doesn=92t use the index: >> >> Does it use it ever? e.g. with >> SELECT * FROM blackbox WHERE day_trunk(ts) =3D '...' >=20 > It=92s used: [snip] OK - so the index is working. If you disable seq-scans before running the query, does it use it then? SET enable_seqscan =3D off; > logs=3D>explain select count(*) from blackbox group by day_trunc(ts) o= rder > by day_trunc(ts); > QUERY PLAN >=20 -------------------------------------------------------------------------= -----------------=20 > > GroupAggregate (cost=3D98431.58..119773.92 rows=3D74226 width=3D8) In particular: 1. Is the estimated cost more or less than 119773.92? 2. How does that match the actual time taken? --=20 Richard Huxton Archonet Ltd