X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D80FF32ABEE for ; Tue, 19 Oct 2004 20:49:55 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 24565-03 for ; Tue, 19 Oct 2004 19:49:45 +0000 (GMT) Received: from mail.autorevenue.com (ip-208.178.167.106.gblx.net [208.178.167.106]) by svr1.postgresql.org (Postfix) with ESMTP id 60A2232AA22 for ; Tue, 19 Oct 2004 20:49:43 +0100 (BST) Received: from jeremydunn ([192.168.1.79]) (authenticated) by mail.autorevenue.com (8.11.6/8.11.6) with ESMTP id i9JJnaU12950; Tue, 19 Oct 2004 15:49:36 -0400 Reply-To: From: "Jeremy Dunn" To: , "Postgresql Performance" Subject: Re: Speeding up this function Date: Tue, 19 Oct 2004 15:49:45 -0400 Organization: AutoRevenue Message-ID: <008e01c4b614$c86aa550$4f01a8c0@jeremydunn> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 In-Reply-To: <27c475ec04101912351c451e8@mail.gmail.com> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Importance: Normal X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/284 X-Sequence-Number: 8760 > -----Original Message----- > From: pgsql-performance-owner@postgresql.org > [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of > Matt Nuzum > Sent: Tuesday, October 19, 2004 3:35 PM > To: pgsql-performance > Subject: [PERFORM] Speeding up this function > > > All it does is try to "link" pageviews together into a session. > here's the function: > create or replace function usage_normalize_session > (varchar(12), inet, timestamptz) returns integer as ' DECLARE > -- $1 = Account ID, $2 = IP Address, $3 = Time > RecordSet record; > BEGIN > SELECT INTO RecordSet DISTINCT sessionid FROM usage_access ua > WHERE ua.accountid = $1 > AND ua.client = $2 > AND ua.atime <= ($3 - ''20 > min''::interval)::timestamptz; > > if found > then return RecordSet.sessionid; > end if; > > return nextval(''usage_session_ids''); > END;' > language plpgsql; > This is probably a stupid question, but why are you trying to create sessions after the fact? Since it appears that users of your site must login, why not just assign a sessionID to them at login time, and keep it in the URL for the duration of the session? Then it would be easy to track where they've been. - Jeremy