Skip to content

Instantly share code, notes, and snippets.

@karlseguin
Created June 26, 2012 01:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save karlseguin/2992426 to your computer and use it in GitHub Desktop.
Save karlseguin/2992426 to your computer and use it in GitHub Desktop.
sample code used by ranking post
# 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