Re: [PERFORM] Query composite index range in an efficient way

2009-02-17 Thread Havasvölgyi Ottó
Thanks, it's a very good idea! Otto 2009/2/17 Kevin Grittner > >>> Havasvölgyi Ottó 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,

Re: [PERFORM] Query composite index range in an efficient way

2009-02-17 Thread Kevin Grittner
>>> Havasvölgyi Ottó 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

Re: [PERFORM] Query composite index range in an efficient way

2009-02-17 Thread Tom Lane
Gregory Stark writes: > Havasvölgyi Ottó writes: >> I also tried Row constructors with a Between expression, but in this case >> Postgres handled the elements of the row independently, and this led to >> false query result. > What version of Postgres is this? row constructors were fixed a long t

Re: [PERFORM] Query composite index range in an efficient way

2009-02-17 Thread Gregory Stark
Havasvölgyi Ottó writes: > I also tried Row constructors with a Between expression, but in this case > Postgres handled the elements of the row independently, and this led to > false query result. What version of Postgres is this? row constructors were fixed a long time ago to not do that and t

Re: [PERFORM] Query composite index range in an efficient way

2009-02-17 Thread Matthew Wakeling
On Tue, 17 Feb 2009, Havasvölgyi Ottó wrote: I created a big enough table (131072 records, and it had also a 3rd field with about 120 character text data). But Postgres performs a SeqScan. Firstly, you should always post EXPLAIN ANALYSE results when asking about a planning problem. Secondly

[PERFORM] Query composite index range in an efficient way

2009-02-17 Thread Havasvölgyi Ottó
Hi, Let's say I have a table (tbl) with two columns: id1, id2. I have an index on (id1,id2) And I would like to query the (12;34) - (56;78) range (so it also may contain (12;58), (13;10), (40;80) etc.). With the index this can be done quite efficiently in theory, but I cannot find a way to make th