Re: select single entry and its neighbours using direct-acess to index?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Pierre-Frédéric Caillaud <lists(at)boutiquenumerique(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: select single entry and its neighbours using direct-acess to index?
Date: 2004-12-06 15:40:58
Message-ID: 1708.1102347658@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

=?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= <lists(at)boutiquenumerique(dot)com> writes:
> 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.

No. There was a prior discussion of this, saying that we really ought
to support the SQL-spec row comparison syntax:
... WHERE (name, name2) > ('b', 'a');
which would map directly onto the semantics of a 2-column index. We
don't have that functionality yet, though (we take the syntax but the
semantics are not SQL-compliant) let alone any ability to pass it
through to a 2-column index.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message C G 2004-12-06 15:46:31 triggers, transactions and locks
Previous Message Martijn van Oosterhout 2004-12-06 15:38:40 Re: Performance tuning on RedHat Enterprise Linux 3