
时间:2015-06-28 00:00 来源:IT猫扑网|http://www.itmop.com/ 作者:网管联盟 我要评论(0)
一,索引的重要性
索引用于快速找出在某个列中有一特定值的行。不使用索引,MySQL必须从第1条记录开始然后读完整个表直到找出相关的行。表越大,花费的时间越多。如果表中查询的列有一个索引,MySQL能快速到达一个位置去搜寻到数据文件的中间,没有必要看所有数据。注意如果你需要访问大部分行,顺序读取要快得多,因为此时我们避免磁盘搜索。
假如你用新华字典来查找&张&这个汉字,不使用目录的话,你可能要从新华字典的第一页找到最后一页,可能要花二个小时。字典越厚呢,你花的时间就越多。现在你使用目录来查找&张&这个汉字,张的首字母是z,z开头的汉字从900多页开始,有了这条线索,你查找一个汉字可能只要一分钟,由此可见索引的重要性。但是索引建的是不是越多越好呢,当然不是,如果一本书的目录分成好几级的话,我想你也会晕的。
二,准备工作
- //准备二张测试表
- mysql> CREATE TABLE `test_t` (
- -> `id` int(11) NOT NULL auto_increment,
- -> `num` int(11) NOT NULL default '0',
- -> `d_num` varchar(30) NOT NULL default '0',
- -> PRIMARY KEY (`id`)
- -> ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
- Query OK, 0 rows affected (0.05 sec)
- mysql> CREATE TABLE `test_test` (
- -> `id` int(11) NOT NULL auto_increment,
- -> `num` int(11) NOT NULL default '0',
- -> PRIMARY KEY (`id`)
- -> ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
- Query OK, 0 rows affected (0.05 sec)
- //创建一个存储过程,为插数据方便
- mysql> delimiter |
- mysql> create procedure i_test(pa int(11),tab varchar(30))
- -> begin
- -> declare max_num int(11) default 100000;
- -> declare i int default 0;
- -> declare rand_num int;
- -> declare double_num char;
- ->
- -> if tab != 'test_test' then
- -> select count(id) into max_num from test_t;
- -> while i < pa do
- -> if max_num < 100000 then
- -> select cast(rand()*100 as unsigned) into rand_num;
- -> select concat(rand_num,rand_num) into double_num;
- -> insert into test_t(num,d_num)values(rand_num,double_num);
- -> end if;
- -> set i = i +1;
- -> end while;
- -> else
- -> select count(id) into max_num from test_test;
- -> while i < pa do
- -> if max_num < 100000 then
- -> select cast(rand()*100 as unsigned) into rand_num;
- -> insert into test_test(num)values(rand_num);
- -> end 相关阅读 Xbox Game Pass 10款MySQL数据库客户端图形界面管理工具推荐 MySQL常用维护管理工具 MySQL数据库启动失败1067进程意外终止的解决办法总结 MySQL故障:got error 127 when reading table 的错误的原因及解决办法 MySQL CPU 占用 100% 的解决过程
- 文章评论
热门文章
10款MySQL数据库客户端图形界面管理工具推荐
MySQL常用维护管理工具
使用命令行监控MYSQL
MySQL安装指南大盘点
mssql数据导入MySQL数据库实操
数据库技巧——MySQL十大优化技巧
相关下载
人气排行 10款MySQL数据库客户端图形界面管理工具推荐 MySQL数据库启动失败1067进程意外终止的解决办法总结 Mysql 1045错误解决办法 MySQL服务器进程CPU占用100%解决办法 MySQL导出导入命令的用例 MySQL连接字符串的实际操作步骤汇总 MySQL无法启动、无法停止各种解决方法总结 三种常用的MySQL建表语句 Mysql清空表的实现方法 MySQL故障:got error 127 when reading table 的错误的原因及解决办法 查看MySQL数据库表的命令介绍 Foxpro到MySQL的数据转换技术介绍
查看所有0条评论>>