Create composite index

suggest change

This creates a composite index on mycol and myothercol. It can speed queries that test both columns in the WHERE clause.

CREATE INDEX idx_mycol_myothercol ON my_table(mycol, myothercol)

Note: The order is important! If the search query does not include both columns in the WHERE clause, it can only use the leftmost index. In this case, a query with mycol in the WHERE will use the index, a query searching for myothercol without also searching for mycol will not. For more information check out this blog post.

Note: In a B-tree index, put a column that you query as a range last. DATETIME columns are usually queried like WHERE datecol >= '2016-01-01 00:00:00'. The index can satisfy that range only when the range column is the last one used.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents