From: Tom Lane <tgl@sss.pgh.pa.us>
To: josh@agliodbs.com
Cc: Stephan Szabo <sszabo@megazone.bigpanda.com>
Cc: pgsql-performance <pgsql-performance@postgresql.org>
Subject: Re: Forcing filter/join order?
Date: Thu, 19 Feb 2004 00:08:19 -0500
Message-ID: <28948.1077167299@sss.pgh.pa.us> (raw)
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>
Josh Berkus <josh@agliodbs.com> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, josh@agliodbs.com, sszabo@megazone.bigpanda.com
Subject: Re: Forcing filter/join order?
In-Reply-To: <28948.1077167299@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox