MYSQL, very slow order by

后端 未结 5 1415
轮回少年
轮回少年 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:02

    From 30 seconds to 0.015 sec / 0.000 sec using Quassnoi answer ! This is what I called MySql expertise ! I cut out one Join from my personal project (no join with itself)

    Select ser.id_table, ser.id_rec, ser.relevance, cnt, title, description, sell_url, medium_thumb,  
            unique_id_supplier, keywords width, height, media_type 
    from (    
            Select ser.id_rec, ser.id_table, ser.relevance, ser.cnt 
            from searchEngineResults ser     
            where thisSearch = 16287     
        order by  ser.relevance desc, cnt desc, id_rec 
        ) ser 
    join photo_resell sou on sou.id = ser.id_rec 
    #join searchEngineResults ser on ser.id_rec = tmp.id_rec 
    limit 0, 9
    

提交回复
热议问题