Skip to content

Instantly share code, notes, and snippets.

@tamtam180
Created October 24, 2012 17:41
Show Gist options
  • Save tamtam180/3947586 to your computer and use it in GitHub Desktop.
Save tamtam180/3947586 to your computer and use it in GitHub Desktop.
create table hoge(
id bigint unsigned not null,
primary key pk_hoge (id)
)engine=InnoDB;
pager(slider)
< 1 2 3 ... 100 >
例えば100万件ある場合、
50を押すと50万番目から表示する。
70を押すと70万番目から表示する。
100等分してスキップするページャー。
idは非連続な値なので、普通のアプリのように最新を表示して、次へ次へ(過去へ過去へ)と表示する場合、
select id from hoge where id < @min order by id desc limit 100
-> min(id)を次のアクセスで@minに使う
のように行う事でoffset不要でアクセスできる。
この時に、50を押して50万番目にどーんとスキップしたい場合、
↑のクエリに当てはめようとすると50万番目のidが必要になってしまう。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment