optimizing "between" queries - Mailing list pgsql-general

From Kyle
Subject optimizing "between" queries
Date
Msg-id 14956.38621.306933.780332@ip146.usw5.rb1.bel.nwlink.com
Whole thread Raw
Responses Re: optimizing "between" queries  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
I have a table where I need to select elements that are between
certain values.  The typical query would be like:

  select foo from bar where
       element1 between ? and ? and  -- using some val_1a and val_1b
       element2 between ? and ? and  -- using some val_2a and val_2b
       ...
       element30 between ? and ?;

ie- we've got 30 elements here.  The runtime is acceptable now with
10k rows in the table (about 0.04 seconds).  However, the table size
will grow to the milions in the near future.

The data for element1..30 are int2's and columns element1..element30
have been ordered by how well they discriminate.  Can I use "cluster"
on more than one column with indexes per column to improve the search
time?  How else might I be able to tweak this?

thanks,
Kyle



pgsql-general by date:

Previous
From: Héctor Balanzar
Date:
Subject: Changing pgsql error messages...
Next
From: Stephan Szabo
Date:
Subject: Re: Arrays advanced usage