pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone.bigpanda.com>
To: Tomas Skäre <tomas@nocrew.org>
Cc: pgsql-general@postgresql.org
Cc: pgsql-performance@postgresql.org
Subject: Re: Query is not using index when it should
Date: Fri, 10 Dec 2004 18:28:38 -0800 (PST)
Message-ID: <20041210182453.G92467@megazone.bigpanda.com> (raw)
In-Reply-To: <80oeh2tm7x.fsf@junk.nocrew.org>
References: <80oeh2tm7x.fsf@junk.nocrew.org>

On Fri, 10 Dec 2004, Tomas [iso-8859-1] Skäre wrote:

> I have a table that looks like this:
>
>          Table "public.cjm_object"
>   Column   |       Type        | Modifiers
> -----------+-------------------+-----------
>  timestamp | bigint            | not null
>  jobid     | bigint            | not null
>  objectid  | bigint            | not null
>  class     | integer           | not null
>  field     | character varying | not null

In 7.4.x and earlier, you need to cast the value you're comparing to into
a bigint in order to make sure the indexes are used (in your timestamp
case it appears to work because the value doesn't fit in a plain integer).
8.0 should handle this better.

> But when doing a search with objectid, class and field, it doesn't use
> the idx_cjm_object1 index.
> db=# explain analyze select * from cjm_object where objectid=4534 and class=12 and field='paroid';

Using one of
 objectid=4534::bigint
 objectid='4534'
 objectid=CAST(4534 as bigint)
rather than objectid=4534 should make this indexable in 7.4.x.



view thread (7+ messages)  latest in thread

Message-ID: <20041210182453.G92467@megazone.bigpanda.com>
Permalink:  ../20041210182453.G92467@megazone.bigpanda.com/
Also on:    postgresql.org/message-id/20041210182453.G92467@megazone.bigpanda.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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sszabo@megazone.bigpanda.com, tomas@nocrew.org, pgsql-general@postgresql.org, pgsql-performance@postgresql.org
  Subject: Re: Query is not using index when it should
  In-Reply-To: <20041210182453.G92467@megazone.bigpanda.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