mysql 索引
1
索引的意义:
优点:
索引用来快速地寻找那些具有特定值的记录,如果没有索引,执行查询时必须从第一个记录开始扫描表中所有记录,表里面的记录数量越多,这个操作的代价就越高。
缺点:
索引要占用磁盘空间;且任何写操作涉及的索引个数多的话会引起降速,因为
MySQL
不仅要把改动数据写入数据文件,而且它还要把这些改动写入索引文件。
以下就对索引:
Index Test (col1,col2,col3)
进行分析,如有不准确之处,欢迎大家拍砖。
2
从左至右的正向索引匹配(第一行是索引可用场景,第二行是索引不可用场景)
右边的适用
where
col1=$para1;
where
col1=$para1and col2=$para2;
where col1=$para1
and col2=$para2 and col3=$para3;
右边的不适用
where
col2=$para2;
where
col1=$para1and col3=$para3;
where col2=$para2
and col3=$para3;
3
like
与索引有效性的关系(第一行是索引可用场景,第二行是索引不可用场景)
右边的适用
where col1 like
‘aaa%’;
where col1 like
‘aaa%’ and col2 like ‘bbb%’ ;
where col1 like
‘aa%a%’ and col2 like ‘bb%b%’ ;
右边的不适用
where col1 like
‘%aaa’; (
通配符在前,无确定范围
)
where col1 like
‘%aaa’ and col2 like ‘%bbb’ ;
where col1 like
‘%aa%a’ and col2 like ‘%bb%b’
;
4
or
、
and
与索引有效性的关系(第一行是索引可用场景,第二行是索引不可用场景)
右边的适用
where
col1=$para1and col2=$para2;
where
col1=$para1or col1=$para11; (
同一
column
)
where col1=$para1
or col1=$para11 and col2=$para2;
右边的不适用
where
col1=$para1or col2=$para2; (
无确定范围
)
where col1 like
‘%aaa’ or col2 like ‘%bbb’ ;
where col1=$para1
or col2=$para2 and
col3=$para3;
5
其他
mysql
内置函数与索引有效性的关系
(
以
col1
举例
)
(第二列是可用场景,第三列是不可用场景)
函数名
可用场景
不可用场景
替代办法
SUBSTRING
--
SUBSTRING
(
col1,1,2
)
不可用,拆分了
sq
相关文档:
郁闷!CSDN的博客编辑器右边怎么没有显示出来完啊,搞个什么“如何使用客户端写博客”,害我输入的字都被那个提示挡住了!
转入正题:
今天一大早起来,打开eclipse启动tomcat,昨晚还正常运行的一个项目却报错,给我的心情真是一个打击呀~~新年第一天就不太顺利!
经过检查才知道使用的数据库mysql没有启动, ......
仅仅是看一些书是零零散散记下的,给自己备忘而已。建议去看专业网站的笔记。
1.主键的值必须是唯一的,并且不能为空,这可以提高MySQL从多个表中取得数据或者取得指定键值对应的行的速度。MySQL通过一个特殊的称为Index索引的数据结构做到这一点,Index是找到一条记录的快捷方式,就像图书馆的卡片目录。
2.查看表的列定 ......
1、php与mysql建立连接
php.ini 加载mysql组件
extension=php_mysql.dll前的;去掉
exetension_dir=""路径是否正确
Php连接mysql函数
mysql_connect:开启MYSQL连接
mysql_select_dir:打开一个数据库
@和or die 隐藏错误和条件显示
mysql_connect("主机","用户名","密码");
mysql_sele ......
1.SET GLOBAL event_scheduler = ON;
2.show processlist;
3.创建一个表 test 主要字段 no,name,sex,age
4.对该表插如几条数据
5.创建存储过程add_age
drop procedure if exists add_age;
delimiter|
create procedure add_age()
begin
start transaction;
update eventtest set age = age +1;
&n ......
截取province字符串中第一个<br>前的字符串~!
update lcjd
set `province` = substring_index( `province` , '<br>', '1' );
在需要添加‘0’的位置添加一个‘0’
update lcjd
set lc_name2 = concat('0', lc_name2)
WHERE length(lc_name2) = 3
http://www.sqlstudy.com/s ......