X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 1C203D1E15D for ; Thu, 19 Feb 2004 05:08:20 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 24785-03 for ; Thu, 19 Feb 2004 01:08:24 -0400 (AST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 0F0EDD1E141 for ; Thu, 19 Feb 2004 01:08:18 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i1J58K4E028949; Thu, 19 Feb 2004 00:08:20 -0500 (EST) To: josh@agliodbs.com Cc: Stephan Szabo , pgsql-performance Subject: Re: Forcing filter/join order? In-reply-to: <200402182049.49111.josh@agliodbs.com> References: <200402181610.31978.josh@agliodbs.com> <200402181718.22687.josh@agliodbs.com> <28696.1077164770@sss.pgh.pa.us> <200402182049.49111.josh@agliodbs.com> Comments: In-reply-to Josh Berkus message dated "Wed, 18 Feb 2004 20:49:49 -0800" Date: Thu, 19 Feb 2004 00:08:19 -0500 Message-ID: <28948.1077167299@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/220 X-Sequence-Number: 5744 Josh Berkus writes: > Knowing that events are never more than one month long for this > application, I can do: > "WHERE event.event_date >= (begin_date - '1 month) AND event.event_date <= > end_date" > ... which works because I have a child table which has event information by > day: Uh, why do you need the child table? Seems like the correct incantation given an assumption about maximum duration is event_date <= 'end-date' AND (event_date + duration) >= 'start-date' AND event_date >= 'start-date' - 'max-duration' The last clause is redundant with the one involving the duration field, but it provides a lower bound for the index scan on event_date. The only index you really need here is one on event_date, but possibly one on (event_date, (event_date + duration)) would be marginally faster. regards, tom lane