Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL query is much faster if I create indexes

Is it ok if I create like 8 indexes inside a table which has 13 columns?

If I select data from it and sort the results by a key, the query is really fast, but if the sort field is not a key it's much slower. Like 40 times slower.

What I'm basically asking is if there are any side effects of having many keys in the database...

like image 284
JohnSmith Avatar asked Dec 09 '11 22:12

JohnSmith


1 Answers

Creating indexes on a table slows down all write operations on it a little, but speeds up read operations on the relevant columns a lot. If your application is not going to be doing lots and lots of writes to that table (which is true of most applications) then you are going to be fine.

like image 185
Jon Avatar answered Oct 24 '22 11:10

Jon