Mysql-索引学习(一)_MySQL
Jun 01, 2016 pm 01:44 PMbitsCN.com
使用索引可以提高查询效率,废话不多说,先来个例子。
Sql代码:
CREATE TABLE `person` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL,
`birthday` datetime DEFAULT NULL,
`isMan` int(11) DEFAULT NULL,
`salary` double DEFAULT NULL,
`test` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
)
CREATE TABLE `person` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL,
`birthday` datetime DEFAULT NULL,
`isMan` int(11) DEFAULT NULL,
`salary` double DEFAULT NULL,
`test` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
)
在插入一些数据。例如:
运行:
EXPLAIN select name from person where name='linjia4'
观察结果:
row=23是因为这个表总共有23条记录,即是说做了全表扫描
在搜索的“name”加上索引:
create index testtest on person (name)
再执行EXPLAIN select name from person where name='linjia4'
观察结果:
rows=1,即是所当查询语句执行时通过name的索引,直接定位到那条数据,不用做全表扫描
索引的效果是显而易见的,大大的提高了查询的速度。但索引也不能滥用,增加索引是要付出代价的。
接下来的文章会介绍索引更深层次的知识,我希望通过自己的理解,用一种简单易懂的方式阐述知识
摘自:邻家的技术仓库
bitsCN.com
Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to check your academic qualifications on Xuexin.com

12306 How to check historical ticket purchase records How to check historical ticket purchase records

How to check the activation date on Apple mobile phone

Let's learn how to input the root number in Word together

Comparison of similarities and differences between MySQL and PL/SQL

How to check the latest price of Tongshen Coin?

Understand these 20 Dune analysis dashboards and quickly capture trends on the chain

Learn the main function in Go language from scratch
