Menu

1 / 5

Postgres 18 Skip Scan Turns 393 Ms Into 2.4 Ms for One Column Order Only

Long article (2433 words) — no AI summary yet.
Reading 0:00
15s threshold

Slow Postgres, part 4 of 8.

On PostgreSQL 17.7, the planner ignored an index on (status, created_at) for one day of orders and read all ten million rows, 393 ms. On 18.7 the same index answers it in 2.4 ms with B-tree skip scan. The other order got no rescue. Counting pending orders through (created_at, status) still reads the whole table on 18, 295 ms against 6.6 with the columns swapped.

Five queries against both column orders on PostgreSQL 18

The short version:

Equality columns go first and the range column last, on 17 and 18 alike: for the same 4,031 failed orders of one week, (status, created_at) read 19 index pages and (created_at, status) 787.

Skip scan lets 18 use an index with no condition on its first column, searching it about once per value of that column: four statuses, seven searches, 2.4 ms.

The planner counts on skipping only while the first column's estimated distinct values stay below the index's page count, 38,506 here.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.