X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 19B474758F1 for ; Sun, 11 May 2003 21:05:21 -0400 (EDT) Received: from mx-a.qnet.com (mx-a.qnet.com [209.221.198.11]) by postgresql.org (Postfix) with ESMTP id 5567647580B for ; Sun, 11 May 2003 21:05:16 -0400 (EDT) Received: from cello.qnet.com (root@cello.qnet.com [209.221.198.10]) by mx-a.qnet.com (8.12.9/8.12.9) with ESMTP id h4C15DBr081292; Sun, 11 May 2003 18:05:13 -0700 (PDT) Received: from cello.qnet.com (cello.qnet.com [209.221.198.10]) by cello.qnet.com (8.9.3/8.9.1) with ESMTP id SAA14320; Sun, 11 May 2003 18:05:06 -0700 (PDT) Date: Sun, 11 May 2003 18:05:06 -0700 (PDT) From: Chris Linstruth To: Mathieu Arnold Cc: Subject: Re: sub select performance In-Reply-To: <3465828.1052686426@sauron.in.mat.cc> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN Content-Transfer-Encoding: QUOTED-PRINTABLE X-Spam-Status: No, hits=-32.3 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, QUOTE_TWICE_1,REPLY_WITH_QUOTES,USER_AGENT_PINE autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200305/211 X-Sequence-Number: 13376 Wow. Now to dig into the docs to see what you did. Thanks a bunch. $ time psql radius < mailinglist.sql sessions | connecttime ----------+------------- 7 | 01:47:25 (1 row) 0.04 real 0.00 user 0.00 sys $ Out of almost a million records, too. --=20 Chris Linstruth On Sun, 11 May 2003, Mathieu Arnold wrote: > > > --Le 11/05/2003 09:48 -0700, Chris Linstruth =E9crivait : > > | > | But this can take 15-30 seconds: > | > | SELECT count(radacctid) AS sessions, > | sum(acctsessiontime) AS connecttime > | FROM radacct > | WHERE radacctid IN > | (SELECT DISTINCT ON (acctsessionid) radacctid FROM radacct > | WHERE username=3D'cjl' > | AND acctstoptime IS NOT NULL > | AND date_trunc('month', now())=3Ddate_trunc('month', > | acctstoptime)); > | > | There are probably many different ways to perform this query. My > | main problem is trying to overcome the fact that try as I might, > | I can't stop the occasional duplicate accounting record from being > | inserted so I have to weed them out, hence the "DISTINCT ON > | (acctsessionid)". > > try this : > SELECT count(radacctid) AS sessions, > sum(acctsessiontime) AS connecttime > FROM radacct > JOIN (SELECT DISTINCT ON (acctsessionid) radacctid FROM rada= cct > WHERE username=3D'cjl' > AND acctstoptime IS NOT NULL > AND date_trunc('month', now())=3Ddate_trunc('month', > acctstoptime)) AS subselect USING (radacctid); > >