If I create a Postgres index, what's the difference between ASC and DESC?

Does this mean that ASC is better suited for queries such as

PRICE> 40

and DESC is better for queries like

PRICE <40?

+5
source share
3 answers

The where clause cannot be affected, but ORDER BY is definitely affected

PostgreSQL Index Documentation

+7
source

PostgreSQL (or any other database engine, for that matter) will read your index anyway. You will receive an index scan or reverse index scan.

The problem is that you have multi-column scanning. In this case:

index on (foo, bar)

foo asc, bar asc, foo desc, bar desc. foo desc, bar asc ( foo, ignores bar) foo asc, bar desc ( foo, ).

+6

Decreasing can give you a boost if the column contains sequential data referenced by the "last" values ​​- date columns, identifier columns, etc.

Generally speaking, tables / indexes would have to be very large so that it could make a difference.

It will not affect what returns, only how.

0
source

All Articles