Re: Fwd: Index on table when using DESC clause

From: Yves Vindevogel <yves(dot)vindevogel(at)implements(dot)be>
To: pgsql-performance(at)postgresql(dot)org
Cc: Hendrik De Hertogh <hendrik(dot)dehertogh(at)ecseed(dot)com>
Subject: Re: Fwd: Index on table when using DESC clause
Date: 2005-05-23 21:18:49
Message-ID: adcc4892d7715a10069cfd0c62028a9b@implements.be
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

God I love the sheer brilliance of that minus trick :-))
Tnx a lot

BTW: Are there any plans to change this kind of indexing behaviour ?
It makes no sense at all, and, it makes databases slow when you don't
know about this.

On 23 May 2005, at 23:15, Andrew Lazarus wrote:

> What you are trying to do makes perfect sense, but for some strange
> reason, Postgres doesn't like to do it. In a PG index, all of the
> columns are always stored in ascending order. So if you have an ORDER
> BY that is all ASC, it can start from the start of the index. And if
> you have an ORDER BY that is all DESC, it can start from the end. But
> if you want one column (like pages) DESC and the other (description)
> ASC, then PG will use a sequential scan or something else slow and
> stupid.
>
> Other RDBMS know how to do this, by supporting the
>
> CREATE INDEX foo ON bar(baz DESC, baz2 ASC)
>
> syntax. For PG, you need to fool it with an index on an expression, or
> a custom operator, or something. I once just made an extra column and
> used a trigger to be sure that -myvariable was in it at all times
> (-pages for you) and then made my index on the extra column. Since the
> extra column in ASC order is the same as the original in DESC, it
> works.
> <andrew.vcf>
Met vriendelijke groeten,
Bien à vous,
Kind regards,

Yves Vindevogel
Implements

Attachment Content-Type Size
Pasted Graphic 2.tiff image/tiff 5.6 KB

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message John A Meinel 2005-05-23 22:23:41 Re: seqential vs random io
Previous Message David Parker 2005-05-23 20:58:22 seqential vs random io