pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dan Langille <dan@langille.org>
To: Jean-Luc Lachance <jllachan@nsd.ca>
Cc: Dan Langille <dan@langille.org>
Cc: pgsql-sql@postgresql.org
Subject: Re:
Date: Mon, 29 Sep 2003 10:03:19 -0400
Message-ID: <3F780367.30103.33E0CA71@localhost> (raw)
In-Reply-To: <3F783BD8.48101D85@nsd.ca>

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/




Message-ID: <3F780367.30103.33E0CA71@localhost>
Permalink:  ../3F780367.30103.33E0CA71@localhost/
Also on:    postgresql.org/message-id/3F780367.30103.33E0CA71@localhost

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dan@langille.org, jllachan@nsd.ca
  Subject: Re:
  In-Reply-To: <3F780367.30103.33E0CA71@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox