MYSQL performance slow using filesort

前端 未结 5 1036
Happy的楠姐
Happy的楠姐 2020-12-14 03:53

I have a simple mysql query, but when I have a lot of records (currently 103,0000), the performance is really slow and it says it is using filesort, im not sure if this is w

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-14 04:06

    I have two suggestions. First, remove the quotes around the zero in your where clause. That line should be:

    price >= 0
    

    Second, create this index:

    CREATE INDEX `helper` ON `adverts`(`status`,`approved`,`price`,`date_created`);
    

    This should allow MySQL to find the 10 rows specified by your LIMIT clause by using only the index. Filesort itself is not a bad thing... the number of rows that need to be processed is.

提交回复
热议问题