X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2215211F660B for ; Thu, 13 Apr 2006 09:34:28 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: 0.12 X-Spam-Level: X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id l6-xhdRqgrZm for ; Thu, 13 Apr 2006 09:34:17 -0300 (ADT) X-Greylist: delayed 00:28:43.068191 by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 22C5C11F6613 for ; Thu, 13 Apr 2006 09:34:20 -0300 (ADT) Received: from fon.nation-net.com (fon.nation-net.com [194.24.251.1]) by svr4.postgresql.org (Postfix) with ESMTP id 69B855AF1B2 for ; Thu, 13 Apr 2006 12:05:36 +0000 (GMT) Received: from fon.nation-net.com (localhost [127.0.0.1]) by fon.nation-net.com (Postfix) with ESMTP id F10D5136FBC for ; Thu, 13 Apr 2006 13:05:31 +0100 (BST) Received: from [194.24.251.10] (bum.net [194.24.251.10]) by fon.nation-net.com (Postfix) with ESMTP id E1C52136FBA for ; Thu, 13 Apr 2006 13:05:31 +0100 (BST) Message-ID: <443E3DF5.4020207@laterooms.com> Date: Thu, 13 Apr 2006 13:03:01 +0100 From: Gavin Hamill User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051013) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Slow query - possible bug? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AV-Checked: ClamAV using ClamSMTP X-Archive-Number: 200604/295 X-Sequence-Number: 18379 laterooms=# explain analyze select allocation0_."ID" as y1_, allocation0_."RoomID" as y2_, allocation0_."StatusID" as y4_, allocation0_."Price" as y3_, allocation0_."Number" as y5_, allocation0_."Date" as y6_ from "Allocation" allocation0_ where (allocation0_."Date" between '2006-06-09 00:00:00.000000' and '2006-06-09 00:00:00.000000')and(allocation0_."RoomID" in(4300591)); QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------ Index Scan using ix_date on "Allocation" allocation0_ (cost=0.00..4.77 rows=1 width=34) (actual time=1411.325..1689.860 rows=1 loops=1) Index Cond: (("Date" >= '2006-06-09'::date) AND ("Date" <= '2006-06-09'::date)) Filter: ("RoomID" = 4300591) Total runtime: 1689.917 ms (4 rows) Yep, the two dates are identical - yep I would change the client software to do where "Date" = '2006-06-09 00:00:00.000000' if I could... However, it's clear to see why this simple query is taking so long - the plan is selecting /all/ dates after 2006-06-09 and /all/ dates before then, and only returning the union of the two - a large waste of effort, surely? VACUUM ANALYZE hasn't improved matters... the schema for the table is "ID" int8 NOT NULL DEFAULT nextval(('public."allocation_id_seq"'::text)::regclass), "RoomID" int4, "Price" numeric(10,2), "StatusID" int4, "Number" int4, "Date" date, and there are indexes kept for 'RoomID' and 'Date' in this 4.3-million row table. Is this a bug or a hidden feature in pg 8.1.3 ? :) Cheers, Gavin.