Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 853676330A6 for ; Sun, 5 Apr 2009 20:56:09 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 17882-09 for ; Sun, 5 Apr 2009 20:56:07 -0300 (ADT) X-Greylist: delayed 00:06:39.981895 by SQLgrey-1.7.6 Received: from 26.mail-out.ovh.net (26.mail-out.ovh.net [91.121.27.225]) by mail.postgresql.org (Postfix) with SMTP id CEB7E632F36 for ; Sun, 5 Apr 2009 20:56:07 -0300 (ADT) Received: (qmail 20149 invoked by uid 503); 5 Apr 2009 23:49:47 -0000 Received: from 42.mail-out.ovh.net (213.251.189.42) by 26.mail-out.ovh.net with SMTP; 5 Apr 2009 23:49:47 -0000 Received: (qmail 11857 invoked by uid 503); 5 Apr 2009 23:49:26 -0000 Received: from b6.ovh.net (HELO mail416.ha.ovh.net) (213.186.33.56) by 42.mail-out.ovh.net with SMTP; 5 Apr 2009 23:49:26 -0000 Received: from b0.ovh.net (HELO queue-out) (213.186.33.50) by b0.ovh.net with SMTP; 5 Apr 2009 23:49:06 -0000 Received: from par69-8-88-161-102-87.fbx.proxad.net (HELO soyouz) (88.161.102.87) by ns0.ovh.net with SMTP; 5 Apr 2009 23:49:04 -0000 Date: Mon, 06 Apr 2009 01:54:26 +0200 To: "Rainer Mager" , pgsql-performance@postgresql.org Subject: Re: difficulties with time based queries From: PFC Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 References: <003001c9b645$e8a7cec0$b9f76c40$@com> Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: <003001c9b645$e8a7cec0$b9f76c40$@com> User-Agent: Opera Mail/9.62 (Linux) X-Ovh-Tracer-Id: 4859383998687872603 X-Ovh-Remote: 88.161.102.87 (par69-8-88-161-102-87.fbx.proxad.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Spam-Check: DONE|H 0.5/N 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: 200904/111 X-Sequence-Number: 33478 > When I try to do queries on this > table I always find them slower than what I need and what I believe > should be possible. > > -> Bitmap Index Scan on ad_log_date_all (cost=0.00..72750.51 > rows=2488252 width=0) (actual time=49776.332..49776.332 rows=2268490 > loops=1) > > Index Cond: ((date(start_time) < '2009-03-31'::date) AND > (date(start_time) >= '2009-03-30'::date)) > > Total runtime: 65279.352 ms Well, it is grabbing 2.268.490 rows, that's a lot of rows, so it is not going to be very fast like a few milliseconds. Your columns are small, ints, dates, not large text strings which would augment the total amount of data. So your timing looks pretty slow, it should be faster than this, maybe a few seconds. With this quantity of rows, you want to try to make the disk accesses as linear as possible. This means your table should be organized on disk by date, at least roughly. If your data comes from an import that was sorted on some other column, this may not be the case. What kind of bytes/s do you get from the drives ? => Can you post the result of "vmstat 1" during the entire execution of the query ? 2 phases should be visible in the vmstat output, the indexscan, and the bitmap heapscan. You could use CLUSTER on the table (it will take a long time), or simply create another table and INSERT INTO ... SELECT ORDER BY date. This will also take a long time, but faster than CLUSTER. Then you could recreate the indexes. Do you UPDATE or DELETE a lot from this table ? Is it vacuum'd enough ?