V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
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
lituancheng
V2EX  ›  MySQL

请问这两段条件有什么不同吗,查询效率相差好大

  •  
  •   lituancheng · 2019-10-09 18:55:33 +08:00 · 3989 次点击
    这是一个创建于 1654 天前的主题,其中的信息可能已经有所发展或是发生改变。
    条件 1:
    (user_credit_change.pre_status is null and user_credit_change.after_status is null) or (user_credit_change.pre_status = 0 and user_credit_change.after_status = 30) or (user_credit_change.pre_status = 0 and user_credit_change.after_status = 41)

    条件 2:
    (user_credit_change.pre_status = 0 and user_credit_change.after_status = 41)

    条件 1 耗时 100ms,条件 2 耗时 20 多 s,哪位大神可以解惑下,谢谢啦
    6 条回复    2019-10-10 10:46:11 +08:00
    msaionyc
        1
    msaionyc  
       2019-10-09 18:59:27 +08:00 via Android
    explain
    lituancheng
        2
    lituancheng  
    OP
       2019-10-09 19:02:22 +08:00
    @msaionyc explain 的结果是一样的
    lituancheng
        3
    lituancheng  
    OP
       2019-10-09 19:03:16 +08:00
    id select_type table partitions type possible_keys key key_len ref rows filtered Extra
    1 SIMPLE user NULL ALL NULL NULL NULL NULL 15 10.00 Using where; Using temporary; Using filesort
    1 SIMPLE user_credit_apply NULL ref PRIMARY,uniq_user_status uniq_user_status 258 cashloan.user.uuid 10 50.00 Using index condition
    1 SIMPLE user_credit_change NULL eq_ref uniq_start_identifier,uniq_end_identifier uniq_end_identifier 259 cashloan.user_credit_apply.request_id,const 1 5.00 Using where
    1 SIMPLE user_id_card NULL eq_ref uniq_user uniq_user 134 cashloan.user_credit_apply.user_uuid,const 1 100.00 Using index condition
    lituancheng
        4
    lituancheng  
    OP
       2019-10-09 19:03:30 +08:00
    @lituancheng explain 结果
    wangyzj
        5
    wangyzj  
       2019-10-09 19:09:48 +08:00
    你这问的没法回答啊
    Aresxue
        6
    Aresxue  
       2019-10-10 10:46:11 +08:00
    两条 sql 都不是等价的。感觉像是 null 导致的问题,但是没有执行计划也说不准
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2585 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 15:29 · PVG 23:29 · LAX 08:29 · JFK 11:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.