Skip to content

Instantly share code, notes, and snippets.

@kfly8
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kfly8/2e9e144f608dfcf7bc0f to your computer and use it in GitHub Desktop.
Save kfly8/2e9e144f608dfcf7bc0f to your computer and use it in GitHub Desktop.
CREATE TABLE user_event_ranking (
event_id INTEGER,
user_id INTEGER,
score INTEGER,
PRIMARY KEY (event_id, user_id),
INDEX KEY (event_id, score)
);
CREATE TABLE user_event_ranking (
id INTEGER AUTO_INCREMENT,
event_id INTEGER,
user_id INTEGER,
score INTEGER,
PRIMARY KEY (id),
INDEX KEY (event_id, score)
);
# SELECT event_id, user_id FROM user_event_ranking ORDER BY score LIMIT 10
#「考えなしにサロゲートをキーを使いたくない」
#「よく考えればuser_idが主キー(の一部)になるテーブルはある」
# この例だと、ちょうどcovering indexになる。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment