pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mendola Gaetano <mendola@bigfoot.com>
To: pgsql-admin@postgresql.org
Cc: Dani Oderbolz <oderbolz@ecologic.de>
Subject: Re: Partition DB Tables by month
Date: Wed, 30 Jul 2003 17:00:54 +0200
Message-ID: <002401c356ab$6007b4e0$32add6c2@mm.eutelsat.org> (raw)
References: <3F25BC0B.3050000@ragingnet.com>
	<3F265EC3.5010603@ecologic.de>
	<20030729124246.GA15298@ontko.com>
	<3F267F15.9060705@ecologic.de>
	<00b701c3562c$a9aa83e0$10d4a8c0@mm.eutelsat.org>
	<3F279736.6010500@ecologic.de>

"Dani Oderbolz" <oderbolz@ecologic.de> wrote:
> Mendola Gaetano wrote:
>
> >you can easilly accomplish this using a partial index.
> >
> >
> Would that really work with a view?
> Can you post a syntax example for this?

CREATE TABLE foo (
field_a
field_b
......
fast_search  BOOLEAN NOT NULL DEFAULT 1,
time_stamp TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX idx_fast_search ON foo ( fast_search ) where fast_search = 't';

for each field to index:
CREATE INDEX idx_field_a ON foo ( field_a ) where fast_search = 't';
CREATE INDEX idx_field_b ON foo ( field_b ) where fast_search = 't';


at the beginning of each month you can now do:

UPDATE foo SET fast_search = 'f'
WHERE time_stamp < now() AND
fast_search = 't';


Your improved query for the last month:

SELECT *
FROM foo
WHERE fast_search = 't' AND
    <field_a> = XXXXX AND
   <field_b> = YYYYYY;


I hope this help


Regards
Gaetano
























view thread (7+ messages)  latest in thread

Message-ID: <002401c356ab$6007b4e0$32add6c2@mm.eutelsat.org>
Permalink:  ../002401c356ab$6007b4e0$32add6c2@mm.eutelsat.org/
Also on:    postgresql.org/message-id/002401c356ab$6007b4e0$32add6c2@mm.eutelsat.org

 · 

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-admin@postgresql.org
  Cc: mendola@bigfoot.com, oderbolz@ecologic.de
  Subject: Re: Partition DB Tables by month
  In-Reply-To: <002401c356ab$6007b4e0$32add6c2@mm.eutelsat.org>
  References: <3F25BC0B.3050000@ragingnet.com> <3F265EC3.5010603@ecologic.de> <20030729124246.GA15298@ontko.com> <3F267F15.9060705@ecologic.de> <00b701c3562c$a9aa83e0$10d4a8c0@mm.eutelsat.org> <3F279736.6010500@ecologic.de> <002401c356ab$6007b4e0$32add6c2@mm.eutelsat.org>

* 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