Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 93202632EAC for ; Thu, 15 Jul 2010 00:44:13 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 56193-07 for ; Thu, 15 Jul 2010 03:44:02 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qy0-f174.google.com (mail-qy0-f174.google.com [209.85.216.174]) by mail.postgresql.org (Postfix) with ESMTP id 552D7632B68 for ; Thu, 15 Jul 2010 00:44:02 -0300 (ADT) Received: by qyk35 with SMTP id 35so2671139qyk.19 for ; Wed, 14 Jul 2010 20:44:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :x-enigmail-version:content-type:content-transfer-encoding; bh=3c6vkrI3HEDkHoy8NTL15yN9ImZCyYMAhE9xHOWt6rU=; b=i7CJqQyFKx/MKB/C/e/3FKzlsf8wBo83RVKmkPSVTY51rmrdckfrCjyK8XO0fWFGR9 u/PqEVq9fKa5+Hp0CNjZtp/wg0FiipBS+ycdiFGBRujA8EsXHLDROWMCu8y2SRydx1tE ARi+m0MxMbhf278qDhJnK63bXbNjvMQkhCoBM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; b=QLYW428AFw/x8BECt8G8RZy6zpnX36wKrVNZQaGOhqpCVvA6eYQtDfReRW71IjJRIp 6U8M6iyh3F83R+qqqn9HEh8xFwUeJeIl8sKLJBUFacLjjkQHd+ichWxB3Tryq70fK8YL 4/n+DvzxCd8gz2t6wLWQQpJ01kEYxYjCV4Ugo= Received: by 10.224.96.79 with SMTP id g15mr10593169qan.198.1279165441413; Wed, 14 Jul 2010 20:44:01 -0700 (PDT) Received: from [192.168.1.100] (207-237-122-16.c3-0.wsd-ubr1.qens-wsd.ny.cable.rcn.com [207.237.122.16]) by mx.google.com with ESMTPS id j28sm2681119qck.23.2010.07.14.20.43.56 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 14 Jul 2010 20:43:59 -0700 (PDT) Message-ID: <4C3E83E7.4010102@gmail.com> Date: Wed, 14 Jul 2010 23:43:35 -0400 From: Lee Hachadoorian User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.10) Gecko/20100528 Thunderbird/3.0.5 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Question on COUNT performance References: In-Reply-To: X-Enigmail-Version: 1.0.1 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.224 tagged_above=-5 required=5 tests=BAYES_05=-0.5, HTML_MESSAGE=0.001, MIME_HTML_ONLY=0.723, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201007/72 X-Sequence-Number: 34385 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 therefore one SELECT) for each row in plan_events (since that's the way the calling function is written). If the goal is to count the number of plan_events a specific user has access rights to, I'm sure you can write a query that would accomplish that directly. It's beyond my knowledge whether it makes more sense to do this via these function calls.

--Lee


-- 
Lee Hachadoorian
PhD Student, Geography
Program in Earth & Environmental Sciences
CUNY Graduate Center