What appears on the second page with OFFSET if a new event arrives?
A feed displays events from newest to oldest, 3 per page, using ORDER BY created_at DESC, id DESC LIMIT 3 OFFSET …. The user opens the first page and sees events 10, 9, and 8. While they're reading the feed, a new event arrives. It's inserted into the database and moves to the top of the sort order. Which events will the user see on the second page?
Predict the resultEXPLAIN and optimizationJuniorBackendData Engineer
Input data · iv_events
| id | user_id | event_type | created_at |
|---|---|---|---|
| 1 | 1 | login | 2026-01-31 23:59:00 |
| 2 | 1 | login | 2026-01-31 23:59:00 |
| 3 | 1 | view | 2026-02-01 00:00:00 |
| 4 | 2 | login | 2026-02-01 08:00:00 |
| 5 | 2 | view | 2026-02-01 08:05:00 |
| 6 | 2 | view | 2026-02-01 08:05:00 |
| 7 | 3 | login | 2026-02-02 10:00:00 |
| 8 | NULL | view | 2026-02-03 11:00:00 |
| 9 | 1 | purchase | 2026-02-03 12:00:00 |
| 10 | 2 | logout | 2026-02-28 23:59:59 |
Query
INSERT INTO iv_events (id, user_id, event_type, created_at)
VALUES (11, 3, 'view', '2026-03-01 09:00:00');
SELECT id
FROM iv_events
ORDER BY created_at DESC, id DESC
LIMIT 3 OFFSET 3