pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: scott.marlowe <scott.marlowe@ihs.com>
Cc: Sam Barnett-Cormack <s.barnett-cormack@lancaster.ac.uk>
Cc: PostgreSQL Administrators Mailing List <pgsql-admin@postgresql.org>
Subject: Re: Partial indexes (was: Re: Indexing a boolean)
Date: Fri, 22 Aug 2003 10:34:39 -0400
Message-ID: <10842.1061562879@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.LNX.4.33.0308220746520.16351-100000@css120.ihs.com>
References: <Pine.LNX.4.33.0308220746520.16351-100000@css120.ihs.com>

"scott.marlowe" <scott.marlowe@ihs.com> writes:
> Basically, for partial / functional indexes, the create index where clause 
> needs to exactly (or nearly so) match the select query's where clause:

Another consideration is that an index declaration like this:

	create index fooi on foo (flag) where flag;

is really rather redundant, since the entries will only be made for rows
where flag is true, and so storage of the column value in the index is
useless.  You may be able to get more mileage out of the index by making
the index on another column that you often test in conjunction with the
flag.  For example:

regression=# create table foo (flag bool, ts timestamp);
CREATE TABLE
regression=# create index fooi on foo(ts) where flag;
CREATE INDEX
regression=# explain select * from foo where ts > '2003-10-11' and flag;
                                   QUERY PLAN
--------------------------------------------------------------------------------
 Seq Scan on foo  (cost=0.00..22.50 rows=167 width=9)
   Filter: ((ts > '2003-10-11 00:00:00'::timestamp without time zone) AND flag)
(2 rows)

regression=# set enable_seqscan TO 0;
SET
regression=# explain select * from foo where ts > '2003-10-11' and flag;
                               QUERY PLAN
-------------------------------------------------------------------------
 Index Scan using fooi on foo  (cost=0.00..43.25 rows=167 width=9)
   Index Cond: (ts > '2003-10-11 00:00:00'::timestamp without time zone)
   Filter: flag
(3 rows)

(In a more realistic situation, the planner would probably have chosen
the indexscan without any prompting.)

			regards, tom lane



view thread (4+ messages)  latest in thread

Message-ID: <10842.1061562879@sss.pgh.pa.us>
Permalink:  ../10842.1061562879@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/10842.1061562879@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, scott.marlowe@ihs.com, s.barnett-cormack@lancaster.ac.uk
  Subject: Re: Partial indexes (was: Re: Indexing a boolean)
  In-Reply-To: <10842.1061562879@sss.pgh.pa.us>
  References: <Pine.LNX.4.33.0308220746520.16351-100000@css120.ihs.com> <10842.1061562879@sss.pgh.pa.us>

* 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