› 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
cc959798
V2EX  ›  MySQL

mysql 隐式类型转换的问题

  •  
  •   cc959798 · Oct 19, 2018 · 3258 views
    This topic created in 2897 days ago, the information mentioned may be changed or developed.

    比如一个表 tb 的字段是这 tid 是字符串类型 我们 select * from tb where id='123'走索引 select * from tb where id=123 不走走索引

    隐式转化率就不走索引了,为什么隐式转换的了就不走索引了,和索引的结构有关吗

    但是假设这个 tid 是 int 类型的话

    无论上面的两种写法都会走索引的,这是为什么

    1 replies  •  2018-10-19 19:15:35 +08:00
    Ashitaka4
        1
    Ashitaka4  
       Oct 19, 2018
    1、如果比较的类型不一致 id=123 ,mysql 会把 id 的值和 123 转换成浮点型, 涉及到 varchar 值转为浮点的多种情况,会存在可能很多记录转换为同一个值的情况,不会用到索引。
    2、int 类型,转换也都会转换成浮点,int 类型转换到 float 是唯一
    3、转换的过程就叫这个过程就叫隐形转换。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2571 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 09:31 · PVG 17:31 · LAX 02:31 · JFK 05:31
    ♥ Do have faith in what you're doing.