Types of Indexes in MySQL
MySQL supports the following indexes
- B+ Tree indexes
- Hash indexes
- Full-Text index
- R Tree indexes
B+ Tree Indexes
- Highly Useful(>90%) in many real-time use-cases
- Work for Equality WHERE clause condition filters (Ex age=35) and range Condition filters (Ex salary > 2000)
- In some cases, MySQL optimizer uses it for avoiding costly temp tables and file sorting operations.
- The default use B+tree index for Primary key and Unique key constraints
- Occupy the same or more amount of data size for managing B+ tree indexes.
Hash Index:
- Give good performance compare to B+ tree indexes
- useful only for Equality WHERE clause condition filters (Ex age=35)
- Take less storage space
- Not useful for many use cases
Full-Text Indexes:
- Useful to find out keyword in a large text Ex: find out candidate skill set in a resume.
- Create Full–text indexes only for VARCHAR, CHAR or TEXT columns
- Need more storage space.
- faster to load your data into a table that has no
FULLTEXT
index - Useful only selected use cases.
Spatial Indexes:
- MySQL can create spatial indexes using syntax similar to that for creating regular indexes, but using the
SPATIAL
keyword - SPATIAL INDEX creates an R-tree index
- A B-tree index on spatial values is useful for exact-value lookups, but not for range scans
Ex:
CREATE TABLE geom (g GEOMETRY NOT NULL SRID 4326)
ALTER TABLE geom ADD SPATIAL INDEX(g);
Types of Indexes in MySQL
MySQL supports the following indexes
- B+ Tree indexes
- Hash indexes
- Full-Text index
- R Tree indexes
B+ Tree Indexes
B+ Tree index useful in many cases. It occupies the same amount of storage as data for storing indexes. Most of the cases B+ tree indexes can help to speed up your queries with equality condition filters (Ex age=35) and range condition filters (Ex salary > 2000). There are many rules we need to follow while creating a B+ tree index for speed up queries.