Re: [PERFORM] Query much slower when run from postgres function

2009-03-16 Thread Віталій Тимчишин
2009/3/14 decibel > On Mar 10, 2009, at 12:20 PM, Tom Lane wrote: > >> f...@redhat.com (Frank Ch. Eigler) writes: >> >>> For a prepared statement, could the planner produce *several* plans, >>> if it guesses great sensitivity to the parameter values? Then it >>> could choose amongst them at run

Re: [PERFORM] Query much slower when run from postgres function

2009-03-14 Thread decibel
On Mar 10, 2009, at 12:20 PM, Tom Lane wrote: f...@redhat.com (Frank Ch. Eigler) writes: For a prepared statement, could the planner produce *several* plans, if it guesses great sensitivity to the parameter values? Then it could choose amongst them at run time. We've discussed that in the pas

Re: [PERFORM] Query much slower when run from postgres function

2009-03-14 Thread decibel
On Mar 9, 2009, at 8:36 AM, Mario Splivalo wrote: Now, as I was explained on pg-jdbc mailinglist, that 'SET enable_seqscan TO false' affects all queries on that persistent connection from tomcat, and It's not good solution. So I wanted to post here to ask what other options do I have. FWI

Re: [PERFORM] Query much slower when run from postgres function

2009-03-10 Thread Tom Lane
f...@redhat.com (Frank Ch. Eigler) writes: > For a prepared statement, could the planner produce *several* plans, > if it guesses great sensitivity to the parameter values? Then it > could choose amongst them at run time. We've discussed that in the past. "Choose at runtime" is a bit more easily

Re: [PERFORM] Query much slower when run from postgres function

2009-03-10 Thread Frank Ch. Eigler
Tom Lane writes: > Mario Splivalo writes: >> Now I'm confused, why is 'sql' function much slower than 'direct' SELECT? > > Usually the reason for this is that the planner chooses a different plan > when it has knowledge of the particular value you are searching for than > when it does not. I su

Re: [PERFORM] Query much slower when run from postgres function

2009-03-09 Thread Tom Lane
Mario Splivalo writes: > So, it is the same. When I do EXPLAIN ANALYZE EXECUTE I get completely > different execution plan: > ... > -> Bitmap Heap Scan on messages > (cost=287.98..21192.42 rows=12848 width=4) (actual time=0.049..0.169 > rows=62 loops=1) >

Re: [PERFORM] Query much slower when run from postgres function

2009-03-09 Thread Mario Splivalo
Tom Lane wrote: > Mario Splivalo writes: >> Is this difference normal? > > It's hard to tell, because you aren't comparing apples to apples. > Try a prepared statement, like [...cut...] > which should produce results similar to the function. You could > then use "explain analyze execute" to prob

Re: [PERFORM] Query much slower when run from postgres function

2009-03-09 Thread Tom Lane
Mario Splivalo writes: > Is this difference normal? It's hard to tell, because you aren't comparing apples to apples. Try a prepared statement, like prepare foo(int) as SELECT COUNT(*)::int4 FROM _v1 WHERE service_id = $1 ; execute foo(504); which should produce results

Re: [PERFORM] Query much slower when run from postgres function

2009-03-09 Thread Mario Splivalo
Guillaume Cottenceau wrote: >>> Now I'm confused, why is 'sql' function much slower than 'direct' SELECT? >> Usually the reason for this is that the planner chooses a different plan >> when it has knowledge of the particular value you are searching for than >> when it does not. > > Yes, and since

Re: [PERFORM] Query much slower when run from postgres function

2009-03-09 Thread Mario Splivalo
Tom Lane wrote: > Mario Splivalo writes: >> Now I'm confused, why is 'sql' function much slower than 'direct' SELECT? > > Usually the reason for this is that the planner chooses a different plan > when it has knowledge of the particular value you are searching for than > when it does not. I supp

Re: [PERFORM] Query much slower when run from postgres function

2009-03-09 Thread Guillaume Cottenceau
Tom Lane writes: > Mario Splivalo writes: >> Now I'm confused, why is 'sql' function much slower than 'direct' SELECT? > > Usually the reason for this is that the planner chooses a different plan > when it has knowledge of the particular value you are searching for than > when it does not. Yes,

Re: [PERFORM] Query much slower when run from postgres function

2009-03-09 Thread Tom Lane
Mario Splivalo writes: > Now I'm confused, why is 'sql' function much slower than 'direct' SELECT? Usually the reason for this is that the planner chooses a different plan when it has knowledge of the particular value you are searching for than when it does not. I suppose 'service_id' has a very