Created
November 3, 2012 19:57
-
-
Save dburger/4008503 to your computer and use it in GitHub Desktop.
This file contains 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
-- Say I have a very large table with a composite primary key with four parts, | |
-- primary key = (A, B, C, D) where these are all integers. I would like to be | |
-- able to select blocks of records of 10,000 in ORDER BY (A, B, C, D) primary | |
-- key order. I can get my first block with the query: | |
SELECT * FROM BigTable | |
ORDER BY (A, B, C, D) | |
LIMIT 10000; | |
-- Given the last block where the final | |
-- row had (A = a, B = b, C = c, D = d) a query for the next block is: | |
SELECT * FROM BigTable | |
WHERE | |
A > a OR | |
(A = a AND B > b) OR | |
(A = a AND B = b AND C > c) OR | |
(A = a AND B = b AND C = c AND D > d) | |
ORDER BY (A, B, C, D) | |
LIMIT 10000; | |
-- This query does not seem to run very fast though, is there a better way? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment