Re: [SQL] Question on COUNT performance

2010-07-15 Thread REISS Thomas DSIC BIP
emove them and keep the query. So the function becomes a simple SQL function. Hope this helps :-) Regards Jean-Michel Souchard and Thomas Reiss Message original Sujet : Re: [SQL] Question on COUNT performance De : Anders Østergaard Jensen Pour : pgsql-sql@postgresql.org Date

Re: [SQL] Question on COUNT performance

2010-07-14 Thread Lee Hachadoorian
It appears that the acl functions use more SELECTs than necessary. For f_customer_acl(uid integer, cid integer), I might use: PERFORM 1 FROM customers JOIN users USING (org_id) WHERE customer_id = cid and user_id = uid; RETURN FOUND; This still requires one call to f_customer_acl() (and there

Re: [SQL] Question on COUNT performance

2010-07-14 Thread Anders Østergaard Jensen
Hi all, Thank you so much for your kind replies. It has all been a great help. I tried the SELECT COUNT(1) but that didn't yield any improvement, sorry. Doing the index on f_plan_event_acl( ... ) wont work, as the parameters are frequently shifted (the second parameter denotes the id of a user i

Re: [SQL] Question on COUNT performance

2010-07-14 Thread Anders Østergaard Jensen
Hi all, Thank you so much for your kind replies. It has all been a great help. I tried the SELECT COUNT(1) but that didn't yield any improvement, sorry. Doing the index on f_plan_event_acl( ... ) wont work, as the parameters are frequently shifted (the second parameter denotes the id of a user i

Re: [SQL] Question on COUNT performance

2010-07-14 Thread Lee Hachadoorian
In retrospect, it's a big assumption whether f_project_acl() or f_customer_acl() always return TRUE. If they can return FALSE, you probably want to replace the statements inside the FOR..LOOP with >IF plan_record.project_id IS NOT NULL THEN >IF f_project_ac

Re: [SQL] Question on COUNT performance

2010-07-14 Thread Lee Hachadoorian
The first statement of the function > : select into user * > from users where id = uid; appears to be a useless drag, as I don't see the user record referred to anywhere else in the function. There appears to be other unnecessary statements. For

Re: [SQL] Question on COUNT performance

2010-07-14 Thread Reinoud van Leeuwen
On Wed, Jul 14, 2010 at 07:30:39AM -0600, Joshua Tolley wrote: > > Have you tried 'select count (1)..."? > > If this helps at all, it's unlikely to help much. I remember having seen > discussion somewhere that there's an optimization such that count(*) and > count(1) do the same thing anyway, but

Re: [SQL] Question on COUNT performance

2010-07-14 Thread Joshua Tolley
On Wed, Jul 14, 2010 at 02:30:29PM +0200, Reinoud van Leeuwen wrote: > On Wed, Jul 14, 2010 at 09:58:10PM +1000, Anders ??stergaard Jensen wrote: > > SELECT count(*) AS count_all FROM "plan_events" WHERE (f_plan_event_acl(17, > > plan_events.id)) > > > >

Re: [SQL] Question on COUNT performance

2010-07-14 Thread Reinoud van Leeuwen
On Wed, Jul 14, 2010 at 09:58:10PM +1000, Anders ??stergaard Jensen wrote: > Hello mailing list, > > I have a performance problem with my postgres 8.4.4 database. The query is > the following: > > SELECT count(*) AS count_all FROM "plan_events" WHERE (f_plan_event_acl(17, > plan_events.id)) > >

[SQL] Question on COUNT performance

2010-07-14 Thread Anders Østergaard Jensen
Hello mailing list, I have a performance problem with my postgres 8.4.4 database. The query is the following: SELECT count(*) AS count_all FROM "plan_events" WHERE (f_plan_event_acl(17, plan_events.id)) QUERY PLAN --