Re: How to influence the planner - Mailing list pgsql-sql

From Tom Lane
Subject Re: How to influence the planner
Date
Msg-id 2170.1188597013@sss.pgh.pa.us
Whole thread Raw
In response to Re: How to influence the planner  (Michael Glaesemann <grzm@seespotcode.net>)
List pgsql-sql
Michael Glaesemann <grzm@seespotcode.net> writes:
> On Aug 31, 2007, at 16:07 , Richard Ray wrote:
>>> If length(bar) = 0 is a common operation on this table, you might  
>>> consider using an expression index on t1:
>> 
>>> create index t1_length_bar_idx on t1 (length(bar));
>> 
>> This is a one time procedure to fix some data but I've had this  
>> problem before

Actually, I just noticed that the OP does have an index on bar,
which means (assuming it's a string data type) that this query is
equivalent toselect * from t1 where bar = ''
which would be a far preferable way to do it because that condition
can use the index.  The Postgres planner is fairly data-type-agnostic
and does not have the knowledge that these are equivalent queries,
so you can't expect it to make that substitution for you.
        regards, tom lane


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: How to influence the planner
Next
From: Richard Ray
Date:
Subject: Re: How to influence the planner