MOCKSTACKS
EN
Questions And Answers

More Tutorials









MYSQL Performance Tips

Building a composite index


In many situations, a composite index performs better than an index with a single column. To build an optimal composite index, populate it with columns in this order.

.= column(s) from the WHERE clause first. (eg, INDEX(a,b,...) for WHERE a=12 AND b='xyz' ...)

.IN column(s); the optimizer may be able to leapfrog through the index.

.One "range" (eg x BETWEEN 3 AND 9, name LIKE 'J%') It won't use anything past the first range column.

.All the columns in GROUP BY, in order

.All the columns in ORDER BY, in order. Works only if all are ASC or all are DESC or you are using 8.0.


Notes and exceptions:


.Don't duplicate any columns.

.Skip over any cases that don't apply.

.If you don't use all the columns of WHERE, there is no need to go on to GROUP BY, etc.

.There are cases where it is useful to index only the ORDER BY column(s), ignoring WHERE.

.Don't "hide" a column in a function (eg DATE(x) = ... cannot use x in the index.)

.'Prefix' indexing (eg, text_col(99)) is unlikely to be helpful; may hurt.


Conclusion

In this page (written and validated by ) you learned about MYSQL Performance Tips . What's Next? If you are interested in completing MYSQL tutorial, your next topic will be learning about: MYSQL Performance Tuning.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.