I have a table highscore containing the columns:
game(text)date(timestamp)score(integer)- more irrelevant ones...
The query most often run on it is:
SELECT *
FROM highscore
WHERE game = :gamename
AND date BETWEEN :start AND :end
ORDER BY score DESC
LIMIT 10
I currently have three B-tree indexes on this table, one for each column above.
I'm thinking that I could further optimize performance by adding some sort of multi-column index, which starts with game. However, when thinking through the various options for the next column(s), I get stuck.
Can I use a multi-column index for further optimization here?
I'm using PostgreSQL 9.1
(game, date, score). Although thescorecolumn probably doesn't help very much to speed up the ordering though (if it's used at all). Probably an index on(game, date)will be just as good. Btw: it's a bad habit to use column names that are also reserved words likedate- and it actually doesn't tell anyone what the column contains. Something likehappened_onorscheduled_foris much more descriptive. – Nov 10 '12 at 17:41