Bad query optimisation - Mailing list pgsql-hackers

From Greg Stark
Subject Bad query optimisation
Date
Msg-id 87znrqwu79.fsf@stark.dyndns.tv
Whole thread Raw
List pgsql-hackers
This is weird, it seems like min and max aren't being optimised symmetrically.
It seems like both of these should result in similar plans and run equally
fast. Instead the first is actually really slow and the second is perfectly
quick.



foo=# explain select max(postalcode) from postalcodes where postalcode < 'K0C1N2';

Aggregate  (cost=123.59..123.59 rows=1 width=10) ->  Index Scan using postalcodes_pkey on postalcodes
(cost=0.00..120.50rows=1234 width=10)
 


foo=# explain select min(postalcode) from postalcodes where postalcode > 'K0C1N2';

Aggregate  (cost=10373.45..10373.45 rows=1 width=10) ->  Seq Scan on postalcodes  (cost=0.00..9697.11 rows=270535
width=10)

-- 
greg



pgsql-hackers by date:

Previous
From: Greg Stark
Date:
Subject: Newbie hacker looking to get started
Next
From: "Christopher Kings-Lynne"
Date:
Subject: Re: Bad query optimisation