Re: order by x DESC, y ASC indexing problem - Mailing list pgsql-sql

From Josh Berkus
Subject Re: order by x DESC, y ASC indexing problem
Date
Msg-id web-1771021@davinci.ethosmedia.com
Whole thread Raw
In response to order by x DESC, y ASC indexing problem  (Vincent-Olivier Arsenault <vincent@up4c.com>)
Responses Re: order by x DESC, y ASC indexing problem
List pgsql-sql
Vincent,

> SELECT * FROM TABLE1 ORDER BY X DESC, Y ASC;
> 
> (X is a date and Y a varchar)
> 
> What would that index be?
> 
> Is there a function I can use, to invert x (the date), so that I can
> make a query / index set like :

PostgreSQL's sorting mechanism can use an index either ascending or
descending; it does not make a difference.

However, most of the time ORDER BY does not use an index at all because
a seq scan is faster.   Usually, ORDER BY  uses an index only when
combined with related criteria and/or the LIMIT clause.

-Josh Berkus


pgsql-sql by date:

Previous
From: Vincent-Olivier Arsenault
Date:
Subject: order by x DESC, y ASC indexing problem
Next
From: Bruno Wolff III
Date:
Subject: Re: order by x DESC, y ASC indexing problem