• 008.mysql-mysql索引失效几种场景


    1.对过滤字段进行了函数处理

    对字段做了函数计算,就用不上索引了

    比如对时间类型的处理  select month(now())

    2.发生了字段类型的隐式转换---尤其在存数据期时一定要注意,为数值类型

    过滤值为字符型--走索引

     过滤值为数值型--字段的vachar发生隐式转换  相当于执行了函数 cast ('10'   as  signed int ),不走索引

     

    附:

    字符类型         '10' 比  '9'  小    返回0

     

    数值类型   10 比  9  大  返回1

     

    在数据库中如果一个是varchar  一个是int,  发生隐式转换

     相当于 cast ('10'   as  signed int )

     

    3.关联时失效---字符集类型不同

    bbb  utf8;    bb_s   utf8mb4

    -- utf8   =  utf8b4  走索引
    explain 
    select 
    a.*,b.*
    from gaoshuiwei a 
    ,gaoshuiwei b 
    where a.bbb = b.bb_s and a.bbb  = '127'
    
    
    -- utf8b4    = utf8  不走索引
    explain 
    select 
    a.*,b.*
    from gaoshuiwei a 
    ,gaoshuiwei b 
    where a.bb_s = b.bbb and a.bbb = '127'
    
    -- utf8b4 转为utf8   = utf8   走索引
    explain 
    select 
    a.*,b.*
    from gaoshuiwei a 
    ,gaoshuiwei b 
    where CONVERT(a.bb_s USING utf8) = b.bbb and a.bbb = '127'

    1.

    2.

    3.

  • 相关阅读:
    JDE函数--获取当前登录人的描述
    JDE报表开发笔记(R5537011 收货校验统计表)
    JDE函数--GetUDC(B函数)
    JDE隐藏Constant等(Hide Object)
    Oracle “dba_tables”介绍
    word2013设置页面边框
    makefile--#的不正确使用
    CICS定时
    程序的命名
    UE上传到FTP,会多出些字符
  • 原文地址:https://www.cnblogs.com/star521/p/13615549.html
Copyright © 2020-2023  润新知