Impossible WHERE noticed after reading const tables

一 背景

今天某个用户报名活动被拒绝了,然后我这边需要分析下原因,sql查询的时候给了个这个提示

explain select * from test_user_mobile where uid = 1401912121

 

 'Extra' => 'Impossible WHERE noticed after reading const tables'

然而uid 是test_user_mobile表的主键

二 分析

 

  • 主键查询或者唯一性索引查询,如果这条数据没有的话,它会全表扫描,然后得出一个结论,该数据不在表中
  • 如果数据在表中,会走索引
    EXPLAIN SELECT * FROM `test_user_mobile` WHERE uid = 4

     

     

  •  所以从侧面也反映了,我查询的1401912121 用户是不存在

  • 如果要强行走索引,可以通过
    select * from test_user_mobile where uid >= 1401912121 and uid <= 1401912121

     

     


  • 经过测试,非uniq/pre_id ,仅仅是index:走索引,其中查询的index为varchar的情况下,请➕'';如果不➕''是不走索引的!!

    explain SELECT * FROM `test_user_mobile` WHERE mobile = 1212

     

     


     explain SELECT * FROM `test_user_mobile` WHERE mobile = '1212'

     

     



 

posted @ 2022-08-23 19:38  布叔喂丶  阅读(70)  评论(0编辑  收藏  举报