• MySQL-索引


    索引的工作原理及其种类
    一是增加了数据库的存储空间,二是在插入和修改数据时要花费较多的时间(因为索引也要随之变动)。
    索引的实现通常使用B树及其变种B+树。
    二叉树 索引文件 效率 log2N
    检索10次,2的10次方,1024条记录
    查看数据文件
    .frm:表的结构
    .myd:表的数据
    .myi:索引的文件
    通过explain分析执行低效SQL的执行计划
    通过show profile分析SQL
    (1)首先先看MySQL是否支持show profile
    select @@have_profiling;
    (2)如果profiling是关闭的,可以通过set语句在session级别开启profiling
    set profiling=1;
    (3)执行完毕后,可以通过show profile语句查看当前SQL的queryID
    (4)通过show profile for query querID.


    查看是否有索引?
    show index from user1;
    show keys from employee;
     explain select * from employee where id =1G
    索引分类
    主键索引
    alter table 表名 add primary key (索引针对的列)
    唯一索引
    唯一的索引所在的列可以为NULL值。
    唯一的索引所在的列不能为 空字符串
    create unique index 索引名称 on表名(列名)
    普通索引
    先创建表,然后再创建普通索引
    create index 索引名称 on 表名(列)
    全文索引
    fulltext索引,用于全文搜索,只有myisam表类型支持,
    可以从CHAR,VARCHAR和text列中创建,整个列都会被编入索引
    不支持对部分列编索引。
    create table articles(
    id int unsigned auto_increment not null primary key,
    title varchar(200),
    body  text,
    fulltext(title,body)
    )engine=myisam default charset=utf8;

    select * from articles where match(title,body) against('a');




    索引的删除
    alter table 表名 drop index 索引名称

    CREATE TABLE IF NOT EXISTS employee(
    id SMALLINT UNSIGNED ,
    username VARCHAR(20) NOT NULL,
    depId TINYINT UNSIGNED
    )ENGINE=INNODB;

  • 相关阅读:
    回调函数实例
    Java StringBuffer 和 StringBuilder 类
    excel被保护或者锁定时候按住alt和enter可以输入换行
    ArrayUtils.
    excel中在某一列上的所有单元格的前后增加
    decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值)
    正则表达式:Pattern类与Matcher类详解
    Cocos2d-x文本菜单
    msp430在ccsv5下出现的问题总结
    与TCP/IP协议的初次见面(一)
  • 原文地址:https://www.cnblogs.com/3ddan/p/10361706.html
Copyright © 2020-2023  润新知