Re: select single entry and its neighbours using direct-acess to index? - Mailing list pgsql-general

From Pierre-Frédéric Caillaud
Subject Re: select single entry and its neighbours using direct-acess to index?
Date
Msg-id opsild7osscq72hf@musicbox
Whole thread Raw
In response to Re: select single entry and its neighbours using direct-acess to index?  (Andrew - Supernews <andrew+nonews@supernews.com>)
Responses Re: select single entry and its neighbours using direct-acess to index?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
>> SELECT * FROM test WHERE (name='b' and name2>'a') OR (name>'b') ORDER BY
>> name,name2 ASC LIMIT 1;
> Write that WHERE clause instead as:
>  WHERE name>='b' AND (name>'b' OR (name='b' AND name2>'a'))
> This is logically equivalent, but it gives the planner a better handle on
> how to use an index scan to satisfy the query.

    I thought the planner had an automatic rewriter for these situations.
It'd be interesting to see an EXPLAIN ANALYZE output to see if it's indeed
rewritten.

>> SELECT * FROM test WHERE (name='b' and name2<'a') OR (name<'b') ORDER BY
>> name,name2 DESC LIMIT 1;
> That needs to be ORDER BY name DESC, name2 DESC (the direction indicator
> applies per-column and not to the output ordering). Same goes for the
> WHERE clause in this query as the previous one, too.

    You're right, I screwed up !
    Sorry ;)



pgsql-general by date:

Previous
From: Andrew - Supernews
Date:
Subject: Re: select single entry and its neighbours using direct-acess to index?
Next
From: Martijn van Oosterhout
Date:
Subject: Re: Performance tuning on RedHat Enterprise Linux 3