Re: Self-join query and index usage

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Self-join query and index usage
Дата
Msg-id 4260.1152904758@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Self-join query and index usage  (worky.workerson@gmail.com)
Список pgsql-performance
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

В списке pgsql-performance по дате отправления:

Предыдущее
От: worky.workerson@gmail.com
Дата:
Сообщение: Self-join query and index usage
Следующее
От: Gabriele Turchi
Дата:
Сообщение: Big differences in plans between 8.0 and 8.1