pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
NOW vs CURRENT_DATE
3+ messages / 3 participants
[nested] [flat]

* NOW vs CURRENT_DATE
@ 2008-08-24 20:01  dforum <dforums@vieonet.com>
  0 siblings, 2 replies; 3+ messages in thread

From: dforum @ 2008-08-24 20:01 UTC (permalink / raw)
  To: pgsql-performance

Hello every body,

I just discover a big not only big huge difference between NOW() and 
CURRENT_DATE.

Did you already know about it and do you know why ?

DELETE FROM blacklist where bl_date < (NOW() - interval '2 DAY');
on 6 000 000 of records
699 ms

DELETE FROM blacklist where bl_date < (CURRENT_DATE - interval '2 DAY');
on 6 000 000 of records

0.065 ms

tx

david



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: NOW vs CURRENT_DATE
@ 2008-08-24 21:22  Peter Schuller <peter.schuller@infidyne.com>
  parent: dforum <dforums@vieonet.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Peter Schuller @ 2008-08-24 21:22 UTC (permalink / raw)
  To: dforum <dforums@vieonet.com>; +Cc: pgsql-performance

> I just discover a big not only big huge difference between NOW() and 
> CURRENT_DATE.
> 
> Did you already know about it and do you know why ?
> 
> DELETE FROM blacklist where bl_date < (NOW() - interval '2 DAY');
> on 6 000 000 of records
> 699 ms
> 
> DELETE FROM blacklist where bl_date < (CURRENT_DATE - interval '2 DAY');
> on 6 000 000 of records

Is this a one-off run after each other (e.g. with a ROLLBACK in
between)? If so I suspect the difference is due to caching and if you
re-run the NOW() version it would also be fast.

Also, NOW() is equivalent to CURRENT_TIMESTAMP() rather than
CURRENT_DATE(). Perhaps the date vs. timestamp has some implication of
how they query is planned.

-- 
/ Peter Schuller

PGP userID: 0xE9758B7D or 'Peter Schuller <peter.schuller@infidyne.com>'
Key retrieval: Send an E-Mail to getpgpkey@scode.org
E-Mail: peter.schuller@infidyne.com Web: http://www.scode.org

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: NOW vs CURRENT_DATE
@ 2008-08-25 06:01  Tino Wildenhain <tino@wildenhain.de>
  parent: dforum <dforums@vieonet.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Tino Wildenhain @ 2008-08-25 06:01 UTC (permalink / raw)
  To: dforum <dforums@vieonet.com>; +Cc: pgsql-performance

Hi,

dforum wrote:
> Hello every body,
> 
> I just discover a big not only big huge difference between NOW() and 
> CURRENT_DATE.
> 
> Did you already know about it and do you know why ?
> 
> DELETE FROM blacklist where bl_date < (NOW() - interval '2 DAY');
> on 6 000 000 of records
> 699 ms
> 
> DELETE FROM blacklist where bl_date < (CURRENT_DATE - interval '2 DAY');
> on 6 000 000 of records

Try that with a timestamp - column and use now() and current_timestamp
with a long running query and then compare min(column) max(column) in
both cases :-)

Regards
Tino

Attachments:

  smime.p7s (application/x-pkcs7-signature, 3.2K) download

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2008-08-25 06:01 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-08-24 20:01 NOW vs CURRENT_DATE dforum <dforums@vieonet.com>
2008-08-24 21:22 ` Peter Schuller <peter.schuller@infidyne.com>
2008-08-25 06:01 ` Tino Wildenhain <tino@wildenhain.de>

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