MYSQL, very slow order by

后端 未结 5 1386
轮回少年
轮回少年 2020-12-08 22:45

I have got two tables. One is a User table with a primary key on the userid and the other table references the user table with a foreign key.

The User table has only

5条回答
  •  粉色の甜心
    2020-12-08 23:17

    Seems you're suffering from MySQL's inability to do late row lookups:

    • MySQL ORDER BY / LIMIT performance: late row lookups
    • Late row lookups: InnoDB

    Try this:

    SELECT  p.*, u.*
    FROM    (
            SELECT  id
            FROM    photo
            ORDER BY
                    uploaddate DESC, id DESC
            LIMIT   10
            OFFSET  100000
            ) pi
    JOIN    photo p
    ON      p.id = pi.id
    JOIN    user u
    ON      u.user_id = p.user_id
    

提交回复
热议问题