› MySQL 5.5 Community Server
› MySQL 5.6 Community Server
› Percona Configuration Wizard
› XtraBackup 搭建主从复制
Great Sites on MySQL
› Percona
› MySQL Performance Blog
› Severalnines
推荐管理工具
› Sequel Pro
› phpMyAdmin
推荐书目
› MySQL Cookbook
MySQL 相关项目
› MariaDB
› Drizzle
参考文档
› http://mysql-python.sourceforge.net/MySQLdb.html
JarvisRay
V2EX  ›  MySQL

关于 left join 多张表后, order by 效率陡然下降,如何优化??

  •  
  •   JarvisRay · Aug 25, 2020 · 3198 views
    This topic created in 2222 days ago, the information mentioned may be changed or developed.

    已经很多次碰到这种情况了,一直得不到很好的解决方案,写个帖子问问。

    SELECT DISTINCT p.id, p.channel_id, o.channel_name, d.drug_manufacturer, p.patient_name, p.patient_gender, p.patient_age, p.patient_tel, p.diagnostic_name AS diagnosis, p.doctor_name, p.review_doctor_name AS pharmacist_name, p.pharmacist_name AS config_pharmacist_name, p.STATUS, p.review_time, p.rp_id, p.rp_url, p.refuce_reason, p.total_price, p.add_time FROM prescription_in_channel p, org_channel o, drug_in_channel d WHERE p.id = d.pre_id AND o.id = p.channel_id ORDER BY p.add_time DESC limit 1,10

    上述语句中,没加 order by 目前是 0.2s 左右的时间,加了之后,变为 1.5s 。后期业务数据会逐步变多,我想到时候肯定就特慢了。 不知道有没有什么好的解决方案?

    5 replies  •  2020-09-06 18:32:09 +08:00
    des
        1
    des  
       Aug 25, 2020
    先上个 explain 吧
    weirdo
        2
    weirdo  
       Aug 25, 2020
    ....你这没有 left join 啊。。
    JarvisRay
        3
    JarvisRay  
    OP
       Aug 25, 2020
    @weirdo 不好意思。。。。。。。。我重新发帖,擦,语句搞错了
    zshneedmoney
        4
    zshneedmoney  
       Aug 25, 2020
    join (select add_time from prescription_in_channel ordrr by add_time DESC ) 别名 on p.add_time = 别名
    zhz1237ok
        5
    zhz1237ok  
       Sep 6, 2020
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2386 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 05:46 · PVG 13:46 · LAX 22:46 · JFK 01:46
    ♥ Do have faith in what you're doing.