Re: Indexes not used in 7.1RC4: Bug?

From: Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu>
To: Alvar Freude <alvar(at)agi(dot)de>
Cc: pgsql-hackers(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org
Subject: Re: Indexes not used in 7.1RC4: Bug?
Date: 2001-04-10 13:53:34
Message-ID: 3AD3105E.E4AC682@alumni.caltech.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

> I have the following table, containing about 570000 Rows, but some
> indexes are not used, on 7.1RC4, freshly vacuumed (analyse). It was the
> same at least in 7.1RC1
> CREATE TABLE access_log(
> access_time timestamp NOT NULL DEFAULT NOW(),
> method_num int2 NOT NULL,
> url_id int4 NOT NULL REFERENCES urls(id),
> );
> CREATE INDEX method_idx ON access_log(method_num);
> CREATE INDEX url_idx ON access_log(url_id);
> url_idx seems OK:
> But the others not:
> logger=# EXPLAIN SELECT * FROM access_log WHERE method_num = 0;
> Seq Scan on access_log (cost=0.00..16443.71 rows=559371 width=89)

The parser does not know that your int4 constant "0" can be represented
as an int2. Try

SELECT * FROM access_log WHERE method_num = int2 '0';

(note the type coersion on the constant; there are other ways of
specifying the same thing).

For the other cases, PostgreSQL is estimating the query cost to be lower
with a sequential scan. For the "SELECT 1" subselect case, it may be
that the optimizer does not cheat and determine that there will be only
one row returned, or that the query can be reformulated to use a simple
constant.

HTH

- Thomas

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Cefull Lo 2001-04-10 14:03:38 newbie question - INSERT
Previous Message Brett W. McCoy 2001-04-10 13:11:03 Re: perl dbi:pg

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2001-04-10 14:37:05 Re: Re: "--tuning" compile and runtime option (?)
Previous Message Alessio Bragadini 2001-04-10 13:32:52 Re: AW: Truncation of char, varchar types