Created
June 26, 2012 01:05
-
-
Save karlseguin/2992426 to your computer and use it in GitHub Desktop.
sample code used by ranking post
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
# this somewhat similar code to what I used in http://openmymind.net/Paging-And-Ranking-With-Large-Offsets-MongoDB-vs-Redis-vs-Postgresql/ | |
lids = ['4fe907f1210b2e9e3080f001', '4fe907f1210b2e9e3080f002', '4fe907f1210b2e9e3080f003', '4fe907f1210b2e9e3080f004', '4fe907f1210b2e9e3080f005'] | |
# insert the data | |
open('data.csv', 'w') do |f| | |
6000000.times do |i| | |
f.puts "#{lids.sample},user_#{i},#{(rand() * 10000000).to_i}" | |
end | |
end | |
# create table scores (lid char(24), u varchar(15), score integer); | |
# create index scores_lid_u on scores(lid, u); | |
#import data.csv | |
# run the test | |
100.times do |i| | |
pg.exec("select score, u from scores where lid = $1 order by score limit 20 offset $2", [lids.sample, i * 10000]).to_a | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment