Home > Database > Mysql Tutorial > body text

mysql笔记6_索引_MySQL

WBOY
Release: 2016-06-01 13:07:15
Original
850 people have browsed it

什么是索引?

  数据库中的一个对象。

  在数据库中用来加速表的查询。

  通过使用快速路径访问方法定位数据,减少了磁盘的i/o。

  与表分别独立存放,但不能独立存在,必须属于某个表。

  由数据库自动维护,表被删除时,该表上的索引自动别删除。

  索引的作用类似于书的目录,几乎没有一本书没有目录,因此几乎没有一张表没有索引。

怎样创建索引:

  create index 索引名 on 表名(字段名);

使用索引:

  where之后加上索引字段即可。

索引原理:

      索引页                          表

  index_name|       loc    | 

       name   |c:/xxx/xx|                |  id   |  name(index)  |  sex  |  age  |

    ...     |...          |

数据库查询方式:

  1、全表扫描:扫描所有字段,定位数据所在磁盘下的位置。

  2、通过索引扫描: 通过索引页定位数据。

  3、共享语句。

注意:

  在经常查询的字段上建索引。

  如果表的列很少时不适合建索引。

  当执行过多次的insert、delete、update后,会出现索引碎片(类似磁盘碎片,垃圾文件之类),影响查询速度,所以我们应该对索引进行重组。即删除索引再重建索引。

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!