Strange query plan - Mailing list pgsql-general

From Dmitry Teslenko
Subject Strange query plan
Date
Msg-id 91325fec0808140357k5bafdca5w246d38de1849fb2f@mail.gmail.com
Whole thread Raw
Responses Re: Strange query plan  (Peter Eisentraut <peter_e@gmx.net>)
Re: Strange query plan  (Martin Gainty <mgainty@hotmail.com>)
Re: Strange query plan  ("Igor Neyman" <ineyman@perceptron.com>)
List pgsql-general
Hello!

I have following table:

CREATE TABLE table1 (
    field1 INTEGER NOT NULL,
    field2 INTEGER NOT NULL,
    field3 CHARACTER(30),
    ... some more numeric fields)

I have also those indexes:

CREATE UNIQUE INDEX idx1 ON table1 USING btree (field3, field2, field1)
CREATE INDEX idx2 ON table1 USING btree (field1, field3)

Then I query this table with something like this:

SELECT SUM(...) FROM table1 WHERE field3 = 'ABC' AND field1 <> 1
    GROUP BY field2

And planner picks up a sequential scan of a table. Why does he?

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

pgsql-general by date:

Previous
From: Clemens Schwaighofer
Date:
Subject: Postgres 8.3 is not using indexes
Next
From: Peter Eisentraut
Date:
Subject: Re: Postgres 8.3 is not using indexes