Index scan back and index scan

When troubleshooting a server with very high I / O latency, I notice that of the queries that make SELECT max(x) FROM t WHERE y = ? , a lot of I / O requests.

My index is btree (x, y) .

I notice that in terms of querying Index Index Backback to get the maximum value. This is bad? Should I worry about this and maybe add another index (vice versa)? Or is there a better way to create an index suitable for this type of query?

+6
postgresql query-optimization
source share
2 answers

No, this is not so, it takes as much time to start from the first index page as it takes to start from the last index page. You can see the โ€œdifferenceโ€ when creating a descending index using DESC .

The index (y, x) is likely to be better for this query.

+12
source share

The index is sorted with the lowest value. To find the maximum value, a reverse index scan will first find the maximum value :).

I assume that SELECT min (x) will result in a normal index scan, right?

+2
source share

All Articles