From: Tom Lane <tgl@sss.pgh.pa.us>
To: worky.workerson@gmail.com
Cc: pgsql-performance@postgresql.org
Subject: Re: Self-join query and index usage
Date: Fri, 14 Jul 2006 15:19:18 -0400
Message-ID: <4260.1152904758@sss.pgh.pa.us> (raw)
In-Reply-To: <1152903413.210226.284600@75g2000cwc.googlegroups.com>
References: <1152903413.210226.284600@75g2000cwc.googlegroups.com>
worky.workerson@gmail.com writes:
> and the query that I would like to run is:
> SELECT e1.endnode, count(*), sum(e1.weight) AS weight1, sum(e2.weight)
> AS weight2
> FROM event e1, event e2
> WHERE e1.endnode = e2.startnode AND e1.starttime < e2.starttime AND
> e2.starttime < e1.endtime
> GROUP BY e1.endnode
> Assuming that I have indexes on all the columns, should this query be
> able to make use of the indexes on starttime and endtime?
This is just really poorly suited for btree indexes. What you're
looking for is an interval overlap test, which is something that can be
handled by rtree or gist indexes, but you'll need to change the form of
the query ...
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, worky.workerson@gmail.com
Subject: Re: Self-join query and index usage
In-Reply-To: <4260.1152904758@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