Home > Archive > PostgreSQL Discussion > April 2005 > Re: Performance difference between ANY and IN, also array









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Performance difference between ANY and IN, also array
Alban Hertroys

2005-04-27, 7:23 am

Bart Grantham wrote:
> Hello, all. I work for a Manhattan ISP and have developed an internal
> systems management/housekeeping app on php/postgres 7.4. I am trying to
> speed up some bits with stored procedures and have had great success,
> except I've now run into a bit of trouble. It comes down to this:
>
> # SELECT * FROM connections WHERE connectee_node_id IN ( 28543,28542 );
> -snip-
> Time: 1.410 ms


If you can divide your data set into ranges of adjacent values, it is
even faster to use series of BETWEEN clauses. Kind of depends on the
amount of processing you need to do to get those ranges. The values
being ordered beforehand helps a great deal.

For example, you could do WHERE value IN (1,2,3,4,6,7,8,9,10)
or you
could use WHERE value BETWEEN 1 AND 4 OR value BETWEEN 6 AND 10.

You'll also want to prevent having queries like WHERE value BETWEEN 2
AND 3. There IN (2,3) is probably the better alternative.

--
Alban Hertroys
MAG Productions

T: +31(0)53 4346874
F: +31(0)53 4346876
E: alban@magproductions
.nl
W: http://www.magproductions.nl

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql
.org so that your
message can get through to the mailing list cleanly

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com