Re: Planner not using UNIQUEness of index properly

From: "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>
To: "John Burger" <john(at)mitre(dot)org>
Cc: "PostgreSQL General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Planner not using UNIQUEness of index properly
Date: 2007-12-10 16:13:37
Message-ID: dcc563d10712100813p1e685ed5q1d48c6115a1f8d43@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Dec 10, 2007 9:32 AM, John Burger <john(at)mitre(dot)org> wrote:
> I have a unique function index on one of my tables:
>
> create table allWords (
> wordID serial PRIMARY KEY,
> word text NOT NULL
> );
> create unique index ix_allWords_lower on allWords (lower(word));
>
> To my surprise, the planner does not seem to realize that only one
> row can result from using this index:

that's certainly not what I'm seeing in pgsql 8.2.5 here.

I'm guessing it has to do with being stuck on 7.4. I found a LOT of
cases where 8.2.5 handles index conditions smarter than 7.4 did. For
instance this:

select * from table where timestampfield between now() - interval '1
day' and now()

will always generate a seq scan in 7.4 regardless of indexes. In 8.1
and 8.2 pgsql knows how to use an index.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-12-10 16:22:18 Re: Simpler dump?
Previous Message Tom Lane 2007-12-10 16:11:37 Re: Planner not using UNIQUEness of index properly