当前位置: 首页 > news >正文

北京网站策划联系电话深圳服装网站建设

北京网站策划联系电话,深圳服装网站建设,网页设计作业水晶,建筑公司网站运营方案索引 1.索引 在数据中索引最核心的作用就是:加速查找 1.1 索引原理 索引的底层是基于BTree的数据存储结构 如图所示: 很明显,如果有了索引结构的查询效率比表中逐行查询的速度要快很多且数据越大越明显。 数据库的索引是基于上述BTree的…

索引

1.索引

在数据中索引最核心的作用就是:加速查找

1.1 索引原理

索引的底层是基于B+Tree的数据存储结构

如图所示:

请添加图片描述

很明显,如果有了索引结构的查询效率比表中逐行查询的速度要快很多且数据越大越明显。

数据库的索引是基于上述B+Tree的数据结构实现,但在创建数据库表时,如果指定不同的引擎,底层使用的B+Tree结构的原理有些不同:

  • myisam 引擎,非聚簇索引(数据和索引结构分开索引)
  • innodb引擎,聚簇索引(数据和主见索引存储在一起)
myisam引擎(非聚簇索引)
create table 表名(id int(11) not null auto_increment primary key,name varchar(32) not null,age int
)engine=myisam default charset=utf8

在这里插入图片描述

innodb引擎(聚簇索引)
create table 表名(id int(11) not null auto_increment primary key,name varchar(32) not null,age int
)engine=innodb default charset=utf8

在这里插入图片描述

  • 常见的索引

在开发过程中常见的索引类型:

  • 主键索引:加速查找、不能为空,不能重复。+联合主键索引
  • 唯一索引:加速查找、不能重复。+联合唯一索引
  • 普通所以那就:加速查找。+联合索引

创建主键和联合主键索引

create table t1(id int not null auto_increment primary key,name varchar(32) not null
)default charset=utf8;create table t2 (id int not null auto_increment primary key,name varchar(32) not null
)default charset=utf8;create table t3(id int not null auto_increment,name varchar(32) not null,primary key (id,name))   --如果是多列,称为联合主键(不常用myisam引擎支持)
alter table 表名 add primary key (列名);
  • 删除索引时可能会报错,自增列必须定义为键。
alter table 表名 drop primary key;
[42000][1075] Incorrect table definition; there can be only one auto column and it must be defined as a key

唯一和联合唯一索引

#在创建表之前创建唯一索引create table unique_t1
(id    int         not null auto_increment primary key,name  varchar(32) not null,email varchar(64) not null,unique unique_name (name),unique unique_email (email)
) default charset = utf8;create table unique_t2
(id    int         not null auto_increment primary key,name  varchar(32) not null,email varchar(64) not null,unique unique_name_email (name, email)  -- 如果多列,联合唯一索引,也就是如果允许有一项是重复的,联合索引的列不全都重复即可
) default charset = utf8;# 在创建表后创建唯一索引 
create unique index unique_age on unique_t2 (age);
# 删除索引
drop  index unique_age on unique_t2;

索引和联合索引

create table index_t1
(id    int         not null auto_increment primary key,name  varchar(32) not null,email varchar(64) not null,index index_name (name)
) default charset = utf8;create table index_t2
(id    int         not null primary key,name  varchar(16) not null,email varchar(32) not null,age   int(11)     not null,index index_name_email (name, email)
) default charset = utf8;create index index_t1_age on index_t2(age);drop index index_t1_age on index_t2;

命中索引

  • 类型不一致
select * from resume_library where 姓名=123;  --没有命中索引
select * from resume_library where 位置=123;    --没有命中索引select * from  resume_library where r_id = '3000000';   -- 命中索引
  • 使用不等于
select * from resume_library 姓名!=于金龙;-- 未命中
select * from resume_library email !=yujinlong2002@outlook.com;-- 未命中# 主键有特殊情况(resume_library的id列是表的主键)
select * from resume_library where id = 10; -- 命中索引🎯
  • or,当or条件中有未建立索引的列才有效(id:主键,name 有索引 ,email 没有索引)
select * from tb where id = 213 or email='xxxxxx@xxxx.com'
-- 未命中
select * from tb where email='xxxxxx@xxxx.com' or name='阿龙的代码在报错';   未命中特殊情况
select * from tb where id = 213 or email='xxxxxx@xxxx.com' and name='阿龙的代码在报错' -- 命中 🎯
  • 排序,当根据索引进行排序的时候,选择的映射如果不是索引,那么就不走索引
select * from tb order by name asc -- 未命中
select * from tb order by name desc -- 未命中
select name  from tb order by name desc  -- 命中🎯特殊情况:(id 是主键)
select * from tb where order by id desc -- 命中🎯
  • like,模糊匹配时
select * from tb where name like "%代码在报错";  -- 未命中
select * from tb where name like "阿龙%在报错";  -- 未命中
select * from tb where name like "_龙在报错";  -- 未命中特别的(通配符在最后面可以命中)
select * from tb where name like "阿龙的代码%"  -- 命中🎯
select * from tb where name like "于%"
  • 使用函数
select * from tb where reverse(name)="阿龙的代码在报错";  -- 未命中
特殊的情况:
select * from tb where name=reverse("阿龙的代码在报错") -- 命中🎯
  • 最左前缀原则,如果是联合索引,要遵循最左前缀原则
如果是联合索引未(id,name,age)id and name -- 命中🎯
id    -- 命中🎯
name  -- 未命中
id or name  --未命中
name and age --未命中

以上是数据库索引中比较常见的无法命中索引的情况,如果有错误或者不规范的地方希望各位大佬指正

  • 最左前缀原则,如果是联合索引,要遵循最左前缀原则
如果是联合索引未(id,name,age)id and name -- 命中🎯
id    -- 命中🎯
name  -- 未命中
id or name  --未命中
name and age --未命中

以上是数据库索引中比较常见的无法命中索引的情况,如果有错误或者不规范的地方希望各位大佬指正

http://www.15wanjia.com/news/179869.html

相关文章:

  • 云南公司网站开发睢县做网站哪家好
  • 用动易做的诗歌协会网站深圳品牌馆设计公司
  • 课题组网站建设12306网站建设投标书
  • 商家网站建设模板个人做网站赚钱么
  • 成都企业网站建设费用广东网站设计费用
  • 网站开发最快的语言百度网站地图怎么做
  • 专业做网文的网站好洛可可设计公司估值
  • 做外贸必须有公司网站么帮别人做数学题赚钱的网站
  • 网站设计就业压力网站建设费用明细报告
  • o2o网站市场营销策划方案模板
  • 响应式网站制作公司宜黄住房和城乡建设部网站
  • 做网站平面模板是啥意思定制商城网站的费用
  • 怎么用dw软件做网站设计网站公司的口号
  • 专题定制网站建设农业特色网站建设
  • win7 iis创建网站百度发布平台官网
  • 网站前端怎么做方法互联网协会是干嘛的
  • 宁波网站制作与推广价格以服务营销出名的企业
  • 银川网站建设公司排名html网页设计网站
  • 个人网站开发如何赚钱吗专业ppt代做
  • 努力把网站建设成为wordpress固定链接标签加上页面
  • 家电维修怎么自己做网站制作华为手机网站建设规划书
  • 鄂州网站设计制作大数据网站开发
  • 做慕墙上什么网站好找事做专门做眼镜的网站
  • 做网站asp网站备案幕布照片ps
  • 无忧主机建站的过程中国网站排名站长之家
  • vps 内存影响 网站郑州手工网站建设
  • 公司做网站费用入什么科目数据展示网站
  • 郑州优化网站收费标准中天建设有限公司官方网站
  • 网站推广计划至少包括网页制作软件属于应用软件吗
  • 成都网站制作机构给wordpress加相册