Optimizer picks an ineffient plan - Mailing list pgsql-general

From Bupp Phillips
Subject Optimizer picks an ineffient plan
Date
Msg-id bj0v98$1f1q$1@news.hub.org
Whole thread Raw
Responses Re: Optimizer picks an ineffient plan
List pgsql-general
I have a customer table that has the field CUSTOMER_ID as the primary key
(cust_pkkey), the table has 102,834 records in it.


The following select statement works fine:

select * from customer order by customer_id;
QUERY PLAN:
Index Scan using cust_pkkey on customer  (cost=0.00..5175.17 rows=102834
width=724)
Total runtime: 5999.47 msec

but...

select * from customer order by customer_id, first_name;
QUERY PLAN:
Sort(cost=142028.25..142028.25 rows=102834 width=724)
 -> Seq Scan on customer (cost=0.00..4617.34 rows=102834 width=724)
Total runtime: 19999.81 msec


It seems that the optimizer should be able to detect (in this instance at
least) that the first order by field is a primary key and should not
consider the other fields because it's pointless... the resultset will be in
<primary key> order.

NOTE:  I'm testing this on Postgresql 7.2 for Windows, so this my have
already been dealt with.


Thanks and keep up the great work!!



pgsql-general by date:

Previous
From: "Kuldeep Tanna"
Date:
Subject: Crosstab function Problem
Next
From: Alessandro GARDICH
Date:
Subject: automatic update