Re: Query composite index range in an efficient way

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>>> Havasvölgyi Ottó <havasvolgyi.otto@xxxxxxxxx> wrote: 
 
> WHERE (id1>12 or id1=12 and id2>=34)
>   and (id1<56 or id1=56 and id2<=78)
 
As others have pointed out, if you are using 8.2 or later, you should
write this as:
 
WHERE (id1, id2) >= (12, 34) and (id1, id2) <= (56, 78)
 
On earlier versions you might want to try the logically equivalent:
 
WHERE (id1 >= 12 and (id1 > 12 or id2 >= 34))
  and (id1 <= 56 and (id1 < 56 or id2 <= 78))
 
-Kevin

-- 
Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance

[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux