posted by aqshakirzhan on March 28, 2021

https://www.youtube.com/watch?v=39e1vAGD3hg

объединение примари кей может быть более удобным
post_id + comment_id чем просто comment_id ( >=5.6)

составной индекс по полям A,B,C
если в условии нет A, то индекс работать не будет

если в условии используется диапазон, то по следующим полям индекс работать не будет
A > 5 AND B = 2 (только по A)
A = 5 AND B > 2 AND C = 2 (только по A и B)


KEY (A, B)
will use index for sorting
order by A //sorting by leadeng column
A=5 ORDER BY B //EQ filtering by 1st and sorting by 2nd
ORDER BY A DESC, B DESC // sorting by 2 columns in same order
A>5 ORDER BY A // range on the column, sorting on the same

will not use index for sorting
ORDER BY B - sorting by second column in the index
A>5 ORDER BY B - range on first column, sorting by second
A IN (1,2) ORDER BY B - in range on first column
ORDER BY A ASC, B DESC - sorting in the different order

"covering index" - покрывающий индекс.

A = 5 AND B = 6 - лучше использовать key(A,B)
A = 5 OR B = 6 - лучше использовать key(A), key(B)

Leave a Comment

Fields with * are required.