Created
August 29, 2018 10:57
-
-
Save aliaspooryorik/25e4b18680d1fb6c7861d73100a247d8 to your computer and use it in GitHub Desktop.
efficient MYSQL pagination with window functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT * | |
FROM ( | |
SELECT uuid, | |
row_number() over (ORDER BY uuid) AS rn, | |
count(*) over () AS totalrows | |
FROM tblfoo | |
) AS tmp | |
WHERE rn BETWEEN 212201 AND 212210 | |
ORDER BY uuid | |
; | |
-- LIMIT gets slower the greater the offset as it gets the records then discards them |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment