Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

postgresql

Does it mean ASC is better for queries such as

PRICE > 40

and DESC is better for queries such as

PRICE < 40?

like image 564
deltanovember Avatar asked May 25 '11 21:05

deltanovember


People also ask

Does order of columns in index matter PostgreSQL?

The order of columns doesn't matter in creating tables in PostgreSQL, but it does matter sometimes in creating indexes in PostgreSQL.

Does creating an index lock the table Postgres?

One downside of creating index after importing is that table must be locked, and that may take long time (it will not be locked in opposite scenario). But, in PostgreSQL 8.2 and later, you can use CREATE INDEX CONCURRENTLY, which does not lock table during indexing (with some caveats).

Which index is faster in PostgreSQL?

In Postgres, a B-Tree index is what you most commonly want Using an index is much faster than a sequential scan because it may only have to read a few pages as opposed to sequentially scanning thousands of them (when you're returning only a few records).

What is the most common index type used in PostgreSQL?

The most common and widely used index type is the B-tree index. This is the default index type for the CREATE INDEX command, unless you explicitly mention the type during index creation.


1 Answers

The where condition might not be affected, but the ORDER BY is definitely affected

PostgreSQL Index Ordering Documentation

like image 161
Kallex Avatar answered Oct 22 '22 12:10

Kallex