Re: - Mailing list pgsql-sql

From Dan Langille
Subject Re:
Date
Msg-id 3F780367.30103.33E0CA71@localhost
Whole thread Raw
In response to Re:  (Jean-Luc Lachance <jllachan@nsd.ca>)
List pgsql-sql
On 29 Sep 2003 at 10:04, Jean-Luc Lachance wrote:

> Wouldn't:
> 
> insert into r 
> select count(*) 
> from users 
> where date( lastlogin) > current_date - MaxDays * interval '' 1 day''
> group by date( lastlogin);
> 
> be more efficient?


Yes it would, by a factor of 5.

freshports=# explain analyse select * from LoginCounts(3);                                                   QUERY
PLAN
----------------------------------------------------------------------
--------------------------------------------Function Scan on logincounts  (cost=0.00..12.50 rows=1000 width=8) 
(actual time=1141.04..1141.06 rows=3 loops=1)Total runtime: 1141.13 msec
(2 rows)

freshports=# explain analyse select count(*)
freshports-# from users
freshports-# where date( lastlogin) > current_date - 3 * interval ' 1 
day'
freshports-# group by date( lastlogin);                                                       QUERY PLAN
----------------------------------------------------------------------
-----------------------------------------------------Aggregate  (cost=539.78..552.75 rows=173 width=8) (actual 
time=197.54..198.97 rows=3 loops=1)  ->  Group  (cost=539.78..548.42 rows=1730 width=8) (actual 
time=196.97..198.43 rows=110 loops=1)        ->  Sort  (cost=539.78..544.10 rows=1730 width=8) (actual 
time=196.95..197.39 rows=110 loops=1)              Sort Key: date(lastlogin)              ->  Seq Scan on users
(cost=0.00..446.75rows=1730 
 
width=8) (actual time=0.87..195.38 rows=110 loops=1)                    Filter: ((date(lastlogin))::timestamp without 
time zone > (('now'::text)::date - '3 days'::interval))Total runtime: 199.33 msec
(7 rows)

freshports=#

Thank you.
-- 
Dan Langille : http://www.langille.org/



pgsql-sql by date:

Previous
From: Jean-Luc Lachance
Date:
Subject: Re:
Next
From: Harald Fuchs
Date:
Subject: Re: Result set granularity..