Re: Query composite index range in an efficient way

From: Havasvölgyi Ottó <havasvolgyi(dot)otto(at)gmail(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: Query composite index range in an efficient way
Date: 2009-02-17 18:55:50
Message-ID: 34608c0c0902171055v5f65ce8bv1ca681390f38e719@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Thanks, it's a very good idea!
Otto

2009/2/17 Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>

> >>> Havasvölgyi Ottó <havasvolgyi(dot)otto(at)gmail(dot)com> 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
>

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Robert Haas 2009-02-17 19:31:04 Re: Call of function inside trigger much slower than explicit function call
Previous Message Aaron Turner 2009-02-17 18:13:40 Re: TCP network cost