From: | "Dan Langille" <dan(at)langille(dot)org> |
---|---|
To: | Jean-Luc Lachance <jllachan(at)nsd(dot)ca> |
Cc: | Dan Langille <dan(at)langille(dot)org>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: |
Date: | 2003-09-29 14:03:19 |
Message-ID: | 3F780367.30103.33E0CA71@localhost |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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.75 rows=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/
From | Date | Subject | |
---|---|---|---|
Next Message | Jean-Luc Lachance | 2003-09-29 14:04:08 | Re: |
Previous Message | Dan Langille | 2003-09-29 13:17:28 | Re: now() in loop statement |