4 ms·
> SELECT * > FROM external_api > WHERE id = :my_id > AND sync_token = (SELECT max(sync_token) FROM ext_api WHERE id = :my_id) Does this have an advant
by minitech 3y ago
> SELECT *
> FROM external_api
> WHERE id = :my_id
> AND sync_token = (SELECT max(sync_token) FROM ext_api WHERE id = :my_id)
Does this have an advantage over
SELECT * FROM external_api
WHERE id = :my_id
ORDER BY sync_token DESC
LIMIT 1
? Assuming the index is on (id, sync_token).
- sa46 3y agoFor my specific setup and a single row lookup, the ORDER BY ... LIMIT 1 is faster (0.1 ms vs. 1.2 ms). The ORDER BY ... LIMIT 1 one is the same as the DISTINCT ON query, but the DISTINCT ON can return more than one resource.