Re: index in desc order

Lists: pgsql-general
From: AI Rumman <rummandba(at)gmail(dot)com>
To: pgsql-general General <pgsql-general(at)postgresql(dot)org>
Subject: index in desc order
Date: 2010-11-02 09:36:52
Message-ID: AANLkTik4-RUvYtnQncB47+cyzvBxF8KX1yaiABqT4Pts@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Is it possible to create an index in descending order?


From: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>
To: AI Rumman <rummandba(at)gmail(dot)com>
Cc: pgsql-general General <pgsql-general(at)postgresql(dot)org>
Subject: Re: index in desc order
Date: 2010-11-02 09:41:35
Message-ID: AANLkTimnhCGoAhGaSqT5hNdZjRgmM=UBtD4YYBAJ4T0m@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On 2 November 2010 12:36, AI Rumman <rummandba(at)gmail(dot)com> wrote:
> Is it possible to create an index in descending order?
>

Yes it is - http://www.postgresql.org/docs/current/interactive/indexes-ordering.html

--
Sergey Konoplev

Blog: http://gray-hemp.blogspot.com /
Linkedin: http://ru.linkedin.com/in/grayhemp /
JID/GTalk: gray(dot)ru(at)gmail(dot)com / Skype: gray-hemp


From: Szymon Guz <mabewlun(at)gmail(dot)com>
To: AI Rumman <rummandba(at)gmail(dot)com>
Cc: pgsql-general General <pgsql-general(at)postgresql(dot)org>
Subject: Re: index in desc order
Date: 2010-11-02 09:42:05
Message-ID: AANLkTikfCFVL47G9xG5y1O3_bbZLTbzxz7MTuBL34HDy@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On 2 November 2010 10:36, AI Rumman <rummandba(at)gmail(dot)com> wrote:

> Is it possible to create an index in descending order?
>

yes...

create index i on t(i desc);

regards
Szymon


From: AI Rumman <rummandba(at)gmail(dot)com>
To: Szymon Guz <mabewlun(at)gmail(dot)com>
Cc: pgsql-general General <pgsql-general(at)postgresql(dot)org>
Subject: Re: index in desc order
Date: 2010-11-02 09:57:01
Message-ID: AANLkTimOSoHmBwn0MGjdT8vvt4qpJ2koxGW_X3-O9kev@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

But I am using Postgresql 8.1. Is it possible here?

On Tue, Nov 2, 2010 at 3:42 PM, Szymon Guz <mabewlun(at)gmail(dot)com> wrote:

>
>
> On 2 November 2010 10:36, AI Rumman <rummandba(at)gmail(dot)com> wrote:
>
>> Is it possible to create an index in descending order?
>>
>
> yes...
>
> create index i on t(i desc);
>
>
> regards
> Szymon
>


From: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>
To: AI Rumman <rummandba(at)gmail(dot)com>
Cc: Szymon Guz <mabewlun(at)gmail(dot)com>, pgsql-general General <pgsql-general(at)postgresql(dot)org>
Subject: Re: index in desc order
Date: 2010-11-02 10:07:59
Message-ID: AANLkTim-SrPX8ETVxjZFRrXAUevuf0wnXRnpDPfDBLVB@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On 2 November 2010 12:57, AI Rumman <rummandba(at)gmail(dot)com> wrote:
> But I am using Postgresql 8.1. Is it possible here?

I am afraid not. You could try to do the index using kind of 1/field
trick but I am not sure if it performs better than backward index scan
in general.

>
> On Tue, Nov 2, 2010 at 3:42 PM, Szymon Guz <mabewlun(at)gmail(dot)com> wrote:
>>
>>
>> On 2 November 2010 10:36, AI Rumman <rummandba(at)gmail(dot)com> wrote:
>>>
>>> Is it possible to create an index in descending order?
>>
>> yes...
>> create index i on t(i desc);
>>
>> regards
>> Szymon
>

--
Sergey Konoplev

Blog: http://gray-hemp.blogspot.com /
Linkedin: http://ru.linkedin.com/in/grayhemp /
JID/GTalk: gray(dot)ru(at)gmail(dot)com / Skype: gray-hemp


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Szymon Guz <mabewlun(at)gmail(dot)com>
Cc: AI Rumman <rummandba(at)gmail(dot)com>, pgsql-general General <pgsql-general(at)postgresql(dot)org>
Subject: Re: index in desc order
Date: 2010-11-02 14:10:19
Message-ID: 25586.1288707019@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Szymon Guz <mabewlun(at)gmail(dot)com> writes:
> On 2 November 2010 10:36, AI Rumman <rummandba(at)gmail(dot)com> wrote:
>> Is it possible to create an index in descending order?

> create index i on t(i desc);

Note that there is actually no point at all in such a declaration.
The planner is perfectly capable of using backwards indexscans at
need, so the above index doesn't do anything you couldn't do with
a regular ascending-order index.

The cases where this feature is actually worth something is where
you have a multi-column index and you need different sort orders
for the components, for example

create index xy on t (x asc, y desc);

which could be used to satisfy SELECT ... ORDER BY x ASC, y DESC.

The OP didn't say what he wanted to use the feature for, but
unless it's something like that, there's probably a better way.

regards, tom lane


From: Michal Politowski <mpol+pg(at)meep(dot)pl>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: index in desc order
Date: 2010-11-02 14:21:57
Message-ID: 20101102142157.GA12638@meep.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Tue, 2 Nov 2010 10:10:19 -0400, Tom Lane wrote:
> Szymon Guz <mabewlun(at)gmail(dot)com> writes:
> > On 2 November 2010 10:36, AI Rumman <rummandba(at)gmail(dot)com> wrote:
> >> Is it possible to create an index in descending order?
>
> > create index i on t(i desc);
>
> Note that there is actually no point at all in such a declaration.
> The planner is perfectly capable of using backwards indexscans at
> need, so the above index doesn't do anything you couldn't do with
> a regular ascending-order index.

Cannot there be a (system/hardware) setup where there is a perceptible
performance difference between forward and backward index scans?

--
Michał Politowski
Talking has been known to lead to communication if practiced carelessly.


From: Dimitri Fontaine <dimitri(at)2ndQuadrant(dot)fr>
To: Michal Politowski <mpol+pg(at)meep(dot)pl>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: index in desc order
Date: 2010-11-02 15:23:15
Message-ID: m262wf3g2k.fsf@2ndQuadrant.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Michal Politowski <mpol+pg(at)meep(dot)pl> writes:
> Cannot there be a (system/hardware) setup where there is a perceptible
> performance difference between forward and backward index scans?

I think it's been reported already that backward index scans indeed can
be much slower than forward index scan, but that how to model that is
still unclear and undone in the cost estimations.

You will have to crawl the pgsql-performance list yourself, though…

Regards,
--
Dimitri Fontaine
http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support