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没有启动, ......
show variables like 'character%';查看字符编码
--更改字符集
SET character_set_client = utf-8 ;
SET character_set_connection = utf-8 ;
SET character_set_database = utf-8 ;
SET character_set_results = utf-8 ;
SET character_set_server = utf-8 ;
SET collation_connection = utf8 ;
SET colla ......
Memcached Functions for MYSQL官方主页:
https://launchpad.net/memcached-udfs
两篇基本文章:
http://www.libing.name/2009/02/06/mysql-map-data-to-memcached.html
http://www.libing.name/2008/02/26/mysql-map-memcached.html
安装和验证的SQL语句:
http://hg.tangent.org/memcached_functions_mysql/file/7 ......
代码如下:
//链接时设定
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 ......
官方手册上是这么写的:
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{f ......