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 · Oct 9, 2019 · 4925 views
    This topic created in 2418 days ago, the information mentioned may be changed or developed.
    条件 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 replies    2019-10-10 10:46:11 +08:00
    msaionyc
        1
    msaionyc  
       Oct 9, 2019 via Android
    explain
    lituancheng
        2
    lituancheng  
    OP
       Oct 9, 2019
    @msaionyc explain 的结果是一样的
    lituancheng
        3
    lituancheng  
    OP
       Oct 9, 2019
    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
       Oct 9, 2019
    @lituancheng explain 结果
    wangyzj
        5
    wangyzj  
       Oct 9, 2019
    你这问的没法回答啊
    Aresxue
        6
    Aresxue  
       Oct 10, 2019
    两条 sql 都不是等价的。感觉像是 null 导致的问题,但是没有执行计划也说不准
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2197 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 00:36 · PVG 08:36 · LAX 17:36 · JFK 20:36
    ♥ Do have faith in what you're doing.