Friday, November 9, 2018

MySQL Slow Queries

SELECT * FROM `mysql`.slow_log ORDER BY query_time DESC;

Wednesday, November 7, 2018

Database related - Composite Indexes

How do composite indexes work - https://stackoverflow.com/questions/795031/how-do-composite-indexes-work


https://stackoverflow.com/a/795068

Composite indexes work just like regular indexes, except they have multi-values keys.
If you define an index on the fields (a,b,c) , the records are sorted first on a, then b, then c.
Example:
| A | B | C |
-------------
| 1 | 2 | 3 |
| 1 | 4 | 2 |
| 1 | 4 | 4 |
| 2 | 3 | 5 |
| 2 | 4 | 4 |
| 2 | 4 | 5 |
  • 12 Please note also that indexes are stored as Btree, so an (a,b,c) index will help on a search on (a) and on (a, b),
     but not on other searches like (b) or (b,c). – aexl Apr 30 '16 at 17:53




"MySQL can use multiple-column indexes for queries that test all the columns in the index, or queries that test just the first column, the first two columns, the first three columns, and so on. If you specify the columns in the right order in the index definition, a single composite index can speed up several kinds of queries on the same table." - Multiple-Column Indexes – AlikElzin-kilaka Sep 9 at 4:46


https://stackoverflow.com/questions/2349817/two-single-column-indexes-vs-one-two-column-index-in-mysql
https://stackoverflow.com/questions/179085/multiple-indexes-vs-multi-column-indexes?rq=1

Followers

Blog Archive