› 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
Keshawn
V2EX  ›  MySQL

MySQL 的 select.. where in 在大数据量下的性能问题

  •  
  •   Keshawn · Jun 17, 2016 · 10191 views
    This topic created in 3756 days ago, the information mentioned may be changed or developed.

    我现在有一个查询语句: select uuid, feature from faces where uuid in (uuid1, uuid2,....)

    其中, faces 表中的数据量千万级别,而查询条件 in 后边的 uuid 集合大约几千条,是通过其他方式获取到的 uuid 集合,直接在 sql 语句中使用

    现在我如果直接执行这条语句,性能很差,个人 PC 执行需要花费 30 多秒,实在是太慢了。

    请教各位有没有什么优化方案。

    9 replies  •  2016-06-17 12:12:11 +08:00
    F281M6Dh8DXpD1g2
        1
    F281M6Dh8DXpD1g2  
       Jun 17, 2016 via iPhone
    in 改成 join
    haoqiangim
        2
    haoqiangim  
       Jun 17, 2016
    给 uuid 加个 index 呀。
    ovear
        3
    ovear  
       Jun 17, 2016
    JiShuTui
        4
    JiShuTui  
       Jun 17, 2016
    根据 3 楼的链接,用 temporary table 也就是临时表
    zrp1994
        5
    zrp1994  
       Jun 17, 2016
    同样遇到过这种情况,数据量快到一亿。从数据库结构来说,分表比较靠谱。
    realpg
        6
    realpg  
       Jun 17, 2016
    1000 万条记录 执行 5000 次 select * from table where uuid= 也不用 30 秒吧
    你确定 uuid 有索引?以及你的磁盘 IO 适配千万行的数据量
    jetyang
        7
    jetyang  
       Jun 17, 2016
    先确定 uuid 有没有索引, in 的效率很高的,几千个 uuid 有点多,但不至于这么慢
    alouha
        8
    alouha  
       Jun 17, 2016
    平时也遇到这样的问题,基本上都是先从缓存里取,找不到再查数据库……
    Weixiao0725
        9
    Weixiao0725  
       Jun 17, 2016
    select A.uuid, A.feature from faces as A, (select uuid from table where condition) as B where A.uuid = B.uuid
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1075 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 23:00 · PVG 07:00 · LAX 16:00 · JFK 19:00
    ♥ Do have faith in what you're doing.