Re: optimize self-join query

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: optimize self-join query
Дата
Msg-id 9300.1319761604@sss.pgh.pa.us
обсуждение исходный текст
Ответ на optimize self-join query  (Ty Busby <tybusby@gmail.com>)
Список pgsql-sql
Ty Busby <tybusby@gmail.com> writes:
> I have a table that stores a very large starting number called epc_start_numeric and a quantity.  I've apparently
builtthe most inefficient query possible for doing the job I need: find out if any records overlap.  Imagine the
epc_start_numeric+ quantity representing a block of numbers.  I need to find out if any of these blocks overlap.
 

Yeah, overlap is a hard problem.  Basically, Postgres doesn't have any
way to do your query short of comparing each row to each other row,
so the cost goes up as O(N^2).

If you know more than you've let on about the properties of the
intervals, you might be able to improve things.  For instance
if the intervals fall into nonoverlapping buckets then you could
add a constraint that the buckets of the two sides are equal.
Postgres is a lot better with equality join constraints than it
is with range constraints, so it would be able to match up rows
and only do the O(N^2) work within each bucket.

In the long run we might have better answers --- Jeff Davis has been
working on range types for years now, and one of the long-range goals
of that is to have smarter support for this type of problem.  But for
now, it's going to be painful.
        regards, tom lane


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

Предыдущее
От: Brent Dombrowski
Дата:
Сообщение: Re: how to use explain analyze
Следующее
От: Jan Bakuwel
Дата:
Сообщение: Different order by behaviour depending on where clause?