I'm designing a Postgres database for an events app. The app lists events sorted by when they start. Initially the app displays only 30 events. As users scroll through the list of events, more events are fetched from the database. In reduced form, the queries (depending on the direction in which the user is scrolling) are:
SELECT ?
FROM events
WHERE starts_at >= ?
ORDER BY starts_at
OFFSET ? LIMIT ?
SELECT ?
FROM events
WHERE starts_at < ?
ORDER BY starts_at DESC
OFFSET ? LIMIT ?
I plan on clustering the table on starts_at
with a fill factor of about 70%, and expect I'll want to run the cluster command periodically to maintain performance.
Almost all of the events that users add will have a starts_at
value in the future. Therefore, although specifying a 70% fill factor for events which start in the future makes sense, using a 70% fill factor for events that started in the past seems like a waste of disk space.
Is there a way to have Postgres cluster the events table such that the fill factor for events where starts_at < CURRENT_TIMESTAMP
is 99% while the fill factor for events where starts_at >= CURRENT_TIMESTAMP
is 70%?