请问这两段条件有什么不同吗,查询效率相差好大 - 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 Oct 9, 2019 4903 views
    This topic created in 2411 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     3022 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 36ms UTC 02:48 PVG 10:48 LAX 19:48 JFK 22:48
    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