pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Steven Lembark <lembark@wrkhors.com>
To: pgsql-general@postgresql.org
Cc: lembark@wrkhors.com
Subject: Re: Select "todays" timestamps in an index friendly way
Date: Mon, 29 Oct 2018 07:58:41 -0500
Message-ID: <20181029075841.3db03113.lembark@wrkhors.com> (raw)
In-Reply-To: <20181023093801.GA21523@lutz-pc.ecm4u.intra>
References: <20181023093801.GA21523@lutz-pc.ecm4u.intra>


>     create temporary table t (
>       id SERIAL primary key,
>       ts timestamp not null default now()
>     );

* add date( ts ) as a field and index date = now()::date.

* Depending on the amount of data in your table the date
  may not be seletive enough to be worth using, at which 
  point the index may be present and ignored. Only way to
  be sure is analyze it.

* Might be worth looking at a partial index using >= 00:00:00 
  and < 24:00:00 (PG grocks the 2400 notation for "midnight at 
  the end of today) or

    where ts && tsrange( ... 00:00:00, ... 24:00:00, '[)] )

  Nice thing about the partial index is that you can create it
  on all of the non-ts fields for fast lookup by whatever and 
  only index the portion for today. 

* Think about using a materialized view rather than a temp
  table. May prove simpler to query.


-- 
Steven Lembark                                     3920 10th Ave South
Workhorse Computing                               Birmingham, AL 35222
lembark@wrkhors.com                                    +1 888 359 3508




view thread (13+ messages)

Message-ID: <20181029075841.3db03113.lembark@wrkhors.com>
Permalink:  ../20181029075841.3db03113.lembark@wrkhors.com/
Also on:    postgresql.org/message-id/20181029075841.3db03113.lembark@wrkhors.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: lembark@wrkhors.com
  Subject: Re: Select "todays" timestamps in an index friendly way
  In-Reply-To: <20181029075841.3db03113.lembark@wrkhors.com>
  References: <20181023093801.GA21523@lutz-pc.ecm4u.intra> <20181029075841.3db03113.lembark@wrkhors.com>

* 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