I have a site that gets a lot of traffic this time of year (around 50,000 users a day). The traffic goes up every year and all the sites on my server are starting to crash more, apparently because of non-optimized MySQL queries.
The worst offender I found in a slow log query is this one below. This particular table has 2,655,197 rows.
Would this be classified as a slight problem, big problem or maybe a horrific/fix-this-immediately problem?
I have no experience with "indexing" but it seems after doing some googling that I should create an index for this query. Would that help significantly? If so and if anyone can recommend any sites/videos that explain how to create indexes well, please share.
Count: 798 Time=5.75s (4589s) Lock=0.24s (189s) Rows_sent=0.9 (739), Rows_examined=2592353.9 (2068698439), Rows_affected=0.0 (0), retracted@localhost SELECT * from TABLE WHERE unique_id= 'S' LIMIT 1
Once you add
INDEX(unique_id), the time for that simple query will go down from 4589s to 0.01s.Is that enough incentive to learn about indexing?
50K users/day is 1/sec -- not very busy. 2M rows -- medium sized. But they act big because of the lack of indexing.
If
unique_idis "unique" then useUNIQUEorPRIMARY KEYinstead of simplyINDEX. Also, if it is unique, then theLIMIT 1is unnecessary.