Created
November 3, 2012 19:57
-
-
Save dburger/4008503 to your computer and use it in GitHub Desktop.
Revisions
-
dburger revised this gist
Nov 3, 2012 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,13 @@ -- 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 -
dburger revised this gist
Nov 3, 2012 . 1 changed file with 1 addition and 12 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -13,15 +13,4 @@ WHERE ORDER BY (A, B, C, D) LIMIT 10000; -- This query does not seem to run very fast though, is there a better way? -
dburger revised this gist
Nov 3, 2012 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -23,4 +23,5 @@ WHERE ORDER BY (A, B, C, D) LIMIT 10000; -- but the query planner was probably smart enough to do that. I'll have -- to check if it is still not efficient. -
dburger revised this gist
Nov 3, 2012 . 1 changed file with 11 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -13,4 +13,14 @@ WHERE ORDER BY (A, B, C, D) LIMIT 10000; -- This query does not seem to run very fast though, is there a better way? -- Ah, I guess this can be collapsed down to: SELECT * FROM BigTable WHERE A >= a AND B >= b AND C >= c AND D > d ORDER BY (A, B, C, D) LIMIT 10000; -- but the query planner was probably smart enough to do that. -
dburger created this gist
Nov 3, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ -- 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. 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?