Bug #580: Optimizer uses seq scan only

From: pgsql-bugs(at)postgresql(dot)org
To: pgsql-bugs(at)postgresql(dot)org
Subject: Bug #580: Optimizer uses seq scan only
Date: 2002-02-11 22:51:35
Message-ID: 200202112251.g1BMpZa65613@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Janko Richter (j(dot)richter(at)wallstreet-develop(dot)de) reports a bug with a severity of 2
The lower the number the more severe it is.

Short Description
Optimizer uses seq scan only

Long Description
Dear Postgresql team,

I've found an optimizer bug as follow:

At first I installed PG 7.2 from source followed by
initdb and create database. No changes in postgresql.conf are made.

After CREATE DATABASE I created a simple table :
CREATE TABLE test (
testid int8 not null default 0,
name varchar(255) ,
primary key (testid)
);
Now I inserted 500.000 records and I did VACUUM ANALYSE.

And now a simple query :
janko=# EXPLAIN SELECT * FROM test WHERE testid = 12345;
NOTICE: QUERY PLAN:

Seq Scan on stocks (cost=100000000.00..100009926.99 rows=1 width=23)

Why POSTGRESQL doesn't use index scan (500000 records!)?

And now as opposition :
CREATE TABLE test2 ( testid int8 primary key);
INSERT INTO test2 VALUES (12345);
VACUUM ANALYSE test2;
EXPLAIN SELECT * FROM test t1 INNER JOIN test2 t2 ON t1.testid=t2.testid;

The result:
NOTICE: QUERY PLAN:

Nested Loop (cost=0.00..7.70 rows=1 width=31)
-> Index Scan using test2_pkey on test2 t2 (cost=0.00..4.68 rows=1 width=8)
-> Index Scan using test_pkey on test t1 (cost=0.00..3.01 rows=1 width=23)

The "same" query but much faster !!

Bye : Janko

Sample Code

No file was uploaded with this report

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2002-02-11 23:21:56 Re: Bug #580: Optimizer uses seq scan only
Previous Message Tom Lane 2002-02-11 19:46:08 Re: Bug #578: pg_dumpall from 7.1.3 can not be imported in 7.2.0