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
相关文档:
MYSQL数据库中的常用SQL语句
1、SELECT 查询语句和条件语句
SELECT 查询字段 from 表名 WHERE 条件
查询字段:可以使用通配符* 、字段名、字段别名
表名: 数据库.表名 ,表名
常用条件: = 等于 、<>不等于、in 包含 、&nb ......
在网上找了很多IIS+PHP的配置的方法,试过之后很多都不能达到效果。于是总结了大部分的文章后就得出了这样的方法:(本次操作系统以Win2000为例,如果你要改为其它系统就把系统根目录变一下就Ok了)
一、下载必须的程序:
(1) 先到PHP的官方网站下载一个PHP(本文就以PHP 4.4.2为例)。 ......
代码如下:
//链接时设定
mysql_real_connect( ..., CLIENT_MULTI_STATEMENTS );
//或者
//中途指定
mysql_set_server_option( mysql, MYSQL_OPTION_MULTI_STATEMENTS_ON ); //mysql是连接的名称
当使用执行多语句功能后,一定要读完整个resault集,否则会出现错误:Commands out of sync; you can't run this co ......
截取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 ......