# Indexes ![cover](./sql-performance-explained-cover.png "Cover")
# Overview - What is the purpose and structure of an index? - How does an index work? - Why are my queries slow? - How do I improve my performance? (Live Demo)
### What is the purpose of an index? ![mess](./mess.jpeg "mess")
### How in an index stored? - Doubly linked list ![list](./linked.png "list")
### B-tree ![list](./tree.png "leaf nodes")
### Tree Traversal `>= 57` ![list](./57.png "leaf nodes")
### 3 Steps of Index Lookup 1. Tree Traversal 2. Following leaf-node chain 3. Fetching table data
### Why is my index slow? 1. Tree Traversal (Fast) 2. Following leaf-node chain (Slow) 3. Fetching table data (Slow)
### `EXPLAIN` `type` 1. `system` 2. `const` 3. `eq_ref` 4. `ref` 5. `range` 6. `index` 7. `all`
# Live Demo!
# References - SQL Perfomance Explained by Markys Winad - https://use-the-index-luke.com - https://dev.mysql.com/doc/internals/en/optimizer-determining-join-type.html - https://dev.mysql.com/doc/refman/8.0/en/explain-output.html - https://stackoverflow.com/questions/4508055/what-does-eq-ref-and-ref-types-mean-in-mysql-explain