Re: sub select performance

Поиск
Список
Период
Сортировка
Искать
От
Mathieu Arnold
Тема
Re: sub select performance
Дата
в 14:53:32
Msg-id
3465828.1052686426@sauron.in.mat.cc
Ответ на
sub select performance (Chris Linstruth)
Список
Дерево обсуждения
sub select performance Chris Linstruth <cjl@QNET.COM>
Re: sub select performance Bruno Wolff III <bruno@wolff.to>
Re: sub select performance Mathieu Arnold <mat@mat.cc>
Re: sub select performance Chris Linstruth <cjl@QNET.COM>


--Le 11/05/2003 09:48 -0700, Chris Linstruth écrivait :

|
| 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='cjl'
|           AND acctstoptime IS NOT NULL
|           AND date_trunc('month', now())=date_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 radacct                  WHERE username='cjl'                  AND acctstoptime IS NOT NULL                  AND date_trunc('month', now())=date_trunc('month',
acctstoptime)) AS subselect USING (radacctid);

-- 
Mathieu Arnold


В списке pgsql-sql по дате отправления
От: Bruno Wolff III
Дата:
Сообщение: Re: sub select performance
От: Adam Sherman
Дата:
Сообщение: Constraint Syntax Question
FAQ