pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Martin Sarsale <martin@emepe3.net>
To: pgsql-performance@postgresql.org
Subject: seqscan instead of index scan
Date: Mon, 30 Aug 2004 14:46:37 -0300
Message-ID: <1093887997.1680.71.camel@kadaif> (raw)

Dear all:

Im having a weird problem here. I have a table w/ ~180.000 rows and I
want to select those where c > 0 or d > 0 (there only a few of those on
the table)
I indexed columns c and d (separately) but this query used the slow
seqscan instead of the index scan:

select * from t where c<>0 or d<>0;

After playing some time, I noticed that if I change the "or" for an
"and", pg used the fast index scan (but the query w/ 'and' was not what
I as looking for).

Then, I thought I could do the following:
Creating an index with the expression (c+d) and selecting the rows where
c+d > 0:
select * from t where c + d <> 0;

Again, this used a seqscan. Asking in #postgresql in freenode, somebody
told me to try to disable seqscan (set enable_seqscan false) and
suprisingly, Pg started using the index scan and it was -fast-.

Now: I've no idea why it chooses to use a seq scan instead of the index
scan (yes, I've just vacuum analyzed the table before running the
query).

Some more info:
c and d are both bigint. I've tried the queries casting the constant (0)
to bigint but nothing changed.

Im using debian's pg 7.4.1-2.


Thanks in advance

Attachments:

  signature.asc (application/pgp-signature, 188B) download

view thread (14+ messages)  latest in thread

Message-ID: <1093887997.1680.71.camel@kadaif>
Permalink:  ../1093887997.1680.71.camel@kadaif/
Also on:    postgresql.org/message-id/1093887997.1680.71.camel@kadaif

 · 

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-performance@postgresql.org
  Cc: martin@emepe3.net
  Subject: Re: seqscan instead of index scan
  In-Reply-To: <1093887997.1680.71.camel@kadaif>

* 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