当前位置:网站首页>MySQL 索引详解和什么时候创建索引什么时候不适用索引
MySQL 索引详解和什么时候创建索引什么时候不适用索引
2022-08-03 05:11:00 【张童瑶】
合适创建索引的情况
- 创建表的时候设置某字段为主键,则自动建立唯一索引
- 频繁作为查询条件的字段应该创建索引
- 查询中与其他表关联的字段,外检关系建立索引
- 查询中排序的字段,排序字段诺通过索引去访问将大大提高排序速度
- 查询中统计或者分组字段
不适合创建索引的情况
- 表数据太少
- 经常增删改的表
- 数据重复且分布平均的表字段,如果某个数据列包含许多重复的内容,为他建立索引没有太大的实际效果
- where条件里用不到的字段不创建索引
索引分类
- 单值索引:既一个索引只包含单个列,一个表可以有多个单利索引
- 唯一索引:索引列的值必须唯一,但允许有控制
- 复合索引:既一个索引包含多个列
创建索引
#创建单值索引
create index emp_lastName_idx
on employees(last_name)
#创建复合索引
create index emp_phoneNumber_email_idx
on employees(phone_number,email)
#删除索引
drop index emp_last_name_idx on employees
#查看索引
show index from employees
索引原理详解:https://blog.csdn.net/u014641168/article/details/124616071
我的其他文章
我的网站
边栏推荐
- 阿凡提的难题
- web安全-sql注入漏洞
- 7.18(7)
- Common lipophilic cell membrane dyes DiO, Dil, DiR, Did spectrograms and experimental procedures
- Response 重写设置返回值
- Pr第二次培训笔记
- breed Web刷机升级详细教材修正编译器固件说明_itkeji.top
- Common fluorescent dyes to modify a variety of groups and its excitation and emission wavelength data in the data
- tag单调栈-单调栈预备知识-lt.739. 每日温度
- 初步认识ZK
猜你喜欢

Exception (abnormal) and Error (error) difference analysis

web安全-sql注入漏洞

传说中可“免费白拿”的无线路由器 - 斐讯 K2 最简单刷 breed 与第三方固件教程

Common fluorescent dyes to modify a variety of groups and its excitation and emission wavelength data in the data

用pulp库解决运输问题【详细】

高可用 两地三中心

Pr第三次培训笔记

Ali cloud object storage oss private barrels to generate links

Djiango第四次培训笔记

Common lipophilic cell membrane dyes DiO, Dil, DiR, Did spectrograms and experimental procedures
随机推荐
轨迹(形状)相似性判断与度量方法
设计模式——组合模式、享元模式(Integer缓存)(结构型模式)
二叉树的合并[C]
飞机大战完整版
Gradle的安装配置
数据分析 第一篇
Install PostgreSQL on Windows
JS学习笔记(三)
传说中可“免费白拿”的无线路由器 - 斐讯 K2 最简单刷 breed 与第三方固件教程
【Flask】Flask-SQLAlchemy的增删改查(CRUD)操作
网络流媒体下载的 10 种方法(以下载 Echo 音乐为例)
一劳永逸解决vs编译器无法使用scanf函数
FileZilla 搭建ftp服务器
ss-4.1-1个eurekaServer+1个providerPayment+1个consumerOrder
Redis6学习笔记
web安全-SSTI模板注入漏洞
【打印菱形】
High availability, two locations and three centers
Modelarts第一次培训
斐讯K2路由编译Padavan华硕固件和心得