Skip to content

Instantly share code, notes, and snippets.

@kaja47
Created October 21, 2012 23:19
Show Gist options
  • Save kaja47/3928896 to your computer and use it in GitHub Desktop.
Save kaja47/3928896 to your computer and use it in GitHub Desktop.
MySQL - same queries, vastly different perfomance
-- InnoDB table posts (uid, chan, board, threadId, id, ....)
-- primary (uid)
-- index (chan, board, threadId, id)
-- slow as fuck (Using where; Using index)
select distinct board
from posts
where chan = '4chan'
-- fast (Using where; Using index for group-by)
select distinct chan, board
from posts
where chan = '4chan'
-- fast (Using where; Using index for group-by)
select board
from posts
where chan = '4chan'
group by chan, board
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment