Skip site navigation (1) Skip section navigation (2)

Re: Very specialised query

From: Віталій Тимчишин <tivv00(at)gmail(dot)com>
To: Matthew Wakeling <matthew(at)flymine(dot)org>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Very specialised query
Date: 2009-03-30 16:14:30
Message-ID: (view raw or whole thread)
Lists: pgsql-performance

Look, what I did mean by "symmetric" is that you don't need to make second
part of query because you will get just same results simply by

case when n == 1 then id1 else id2 end,
case when n == 2 then id1 else id2 end

from (
SELECT AS id1, AS id2
   location l1,
   location l2
       l1.objectid = 228000093
   AND l2.objectid = 228000093
   AND <>
   AND l1.start < l2.end
   AND l1.end > l2.start
   AND l1.start < l2.start) a, (values (1),(2)) b(n)

(I may miss some border cases like when l1.start=l2.start and/or
l1.end=l2.end, but this can be fixed by adding "=" to query).

Look,  You can have 4 types of intersections:
a)  1s 2s 2e 1e - 2 inside 1
b)  2s 1s 1e 2e - 1 inside 2 (symmetric to (a), if you have 1,2 from (a) you
can generate 2,1 for (b))
c)  1s 2s 1e 2e - 1 to the left of 2
d)  2s 1s 2e 1e - 2 to the left of 1 (symmetric to (c), if you have 1,2 from
(c) you can generate 2,1 for (d))

The query above gives you results for (a) and (c) and you don't need  any
second part - simply add "symmetric" results.

Correct me if I miss something.

Best Regards, Vitalii Tymchyshyn

In response to


pgsql-performance by date

Next:From: Matthew WakelingDate: 2009-03-30 16:22:15
Subject: Re: Very specialised query
Previous:From: Matthew WakelingDate: 2009-03-30 15:59:05
Subject: Re: Very specialised query

Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group