Should I add and delete index in one page?

B1tHunt3r

New Member
Let's say I have \[code\]players\[/code\] table. It consists with 3 rows(it has much more, but let's suppose it has only 3). \[code\]member_id, name, exp\[/code\]. I use \[code\]member_id\[/code\] row in every page so that's why I added index only to \[code\]member_id\[/code\]. But I want to make a top players' list in one page with the highest \[code\]exp\[/code\]. So I do something like that:\[code\]$query = mysql_query("SELECT * FROM players ORDER BY `exp` DESC");\[/code\]If I have 10k players, I can't run query like this without adding index to \[code\]exp\[/code\]. So my question is, should I do like this:\[code\]mysql_query("ALTER TABLE `players` ADD INDEX ( `exp` )");$query = mysql_query("SELECT * FROM players ORDER BY `exp` DESC");mysql_query("ALTER TABLE `players` DROP INDEX `exp`");\[/code\]Or there is something else better I can do? Because adding and removing indexes is quite expensive. But probably I could do cache every 10 minutes for example.
 
Back
Top