"order by" taking too much time in mysql

"order by" in a query takes a lot of time in MySQL. SHOW PROFILES indicates that the time is being executed by the sorting process. Is there a setup / workaround that will reduce the sorting time?

+3
source share
6 answers

If you do not have an index in the field that you order, add it:

"In some cases, MySQL may use the index to execute the ORDER BY clause without additional sorting.

Edit: (From the section on optimizing ORDER BY in the MySQL documentation.)

+7
source

Adding the appropriate indexes for the fields you order should do the trick.

+5

, (), , .

+1
ALTER TABLE `tablename` ADD INDEX `indexname` (`columnname`);

, _ .

+1

, , , ; , .

0

: show create table tbl_name " "

MySQL , , , . , , , .

0

Source: https://habr.com/ru/post/1712664/