请问这两段条件有什么不同吗,查询效率相差好大 - V2EX
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 4690 次点击
    这是一个创建于 2272 天前的主题,其中的信息可能已经有所发展或是发生改变。
    条件 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     Solana     5661 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 32ms UTC 02:37 PVG 10:37 LAX 18:37 JFK 21:37
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86