Re: pass in array to function for use by where clause? how optimize? - Mailing list pgsql-sql

From Tom Lane
Subject Re: pass in array to function for use by where clause? how optimize?
Date
Msg-id 6181.1302711333@sss.pgh.pa.us
Whole thread Raw
In response to Re: pass in array to function for use by where clause? how optimize?  (Rob Sargent <robjsargent@gmail.com>)
Responses Re: pass in array to function for use by where clause? how optimize?  (Anish Kejariwal <anishkej@gmail.com>)
List pgsql-sql
Rob Sargent <robjsargent@gmail.com> writes:
> On 04/13/2011 09:09 AM, Tom Lane wrote:
>> Anish Kejariwal<anishkej@gmail.com>  writes:
>>> (select store_id, avg(sales) sales
>>> from store
>>> where group_id in(select $1[i] from generate_subscripts($1, 1) g(i))

>> Seems like a pretty brute-force way to deal with the array.  Try
>> where group_id = any($1)
>> Not sure if it'll be a great deal faster, but it's at least easier to
>> write.

> Would adding a subservient function which actually uses the value of the 
> iteration (group_id) as a single parameter be of any use?

Well, it'd be unlikely to solve the OP's actual complaint, which was
performance.  Hiding the semantics from the planner via a function
(which generally looks like a black box to the planner) is even worse
than hiding the semantics in a sub-SELECT, which I think is probably
the root cause of the performance issue here.
        regards, tom lane


pgsql-sql by date:

Previous
From: Rob Sargent
Date:
Subject: Re: pass in array to function for use by where clause? how optimize?
Next
From: Charlie
Date:
Subject: Re: [SQL] unnesting of array of different size explodes memory