Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1605200
  • 博文数量: 695
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 4027
  • 用 户 组: 普通用户
  • 注册时间: 2013-11-20 21:22
文章分类

全部博文(695)

文章存档

2018年(18)

2017年(74)

2016年(170)

2015年(102)

2014年(276)

2013年(55)

分类: Mysql/postgreSQL

2017-11-07 10:38:43


一、索引
1、首先主键和外键也算是特殊的索引。
2、命令:
CREATE INDEX index_name ON table_name (column_list)
ALTER TABLE table_name ADD INDEX index_name (column_list)
3、索引使用原则:

a、where 语句里面如果带有or条件, myisam表能用到索引, innodb不行。

b、必须所有的or条件都必须是独立索引

c、用UNION替换OR (适用于索引列)

高效:select loc_id , loc_desc , region from location where loc_id = 10 union   select loc_id , loc_desc , region  from location where region = "melbourne低效:
  1. select loc_id , loc desc , region from location where loc_id = 10 or region = "melbourne"  
d、

用in来替换or  

     这是一条简单易记的规则,但是实际的执行效果还须检验,在oracle8i下,两者的执行路径似乎是相同的. 
低效: 
select…. from location where loc_id = 10 or loc_id = 20 or loc_id = 30 
高效 
select… from location where loc_in  in (10,20,30);

4、组合索引
ALTER TABLE table_name ADD INDEX index_name (a,b,c) 相当于创建了3个索引 (a,b,c)、(a,b)、(a)
以下查询语句 select * from where a="1" and c="2",只能使用索引a;
select * from where b="1" and a="2" 在5.6以后会进行查询优化交换 and前后的顺序 所以可使用索引 (a,b)

二、事务级别,默认事务级别




阅读(576) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~