SQL中的索引是什么? [英] What is an index in SQL?

查看:106
本文介绍了SQL中的索引是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL中的索引是什么?你能解释或参考清楚地理解吗?

What is an index in SQL? Can you explain or reference to understand clearly?

我应该在哪里使用索引?

Where should I use an index?

推荐答案

索引是用于加快数据库中的搜索速度。 MySQL有关于这个主题的一些很好的文档(这也与其他SQL服务器相关):
http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html

An index is used to speed up searching in the database. MySQL have some good documentation on the subject (which is relevant for other SQL servers as well): http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html

索引可用于有效地查找与查询中某些列匹配的所有行,然后仅遍历表的该子集以查找完全匹配。如果 WHERE 子句中的任何列上没有索引,则 SQL 服务器必须遍历整个表并检查每一行是否匹配,这可能是对大表的缓慢操作。

An index can be used to efficiently find all rows matching some column in your query and then walk through only that subset of the table to find exact matches. If you don't have indexes on any column in the WHERE clause, the SQL server have to walk through the whole table and check every row to see if it matches, which may be a slow operation on big tables.

索引也可以是 UNIQUE index,这意味着你不能在该列中有重复的值,或者在某些存储引擎中定义的 PRIMARY KEY 数据库文件中存储值的位置。

The index can also be a UNIQUE index, which means that you cannot have duplicate values in that column, or a PRIMARY KEY which in some storage engines defines where in the database file the value is stored.

在MySQL中,您可以在<$前面使用 EXPLAIN c $ c> SELECT 语句,查看您的查询是否将使用任何索引。这是解决性能问题的良好开端。在这里阅读更多内容:
http://dev.mysql.com /doc/refman/5.0/en/explain.html

In MySQL you can use EXPLAIN in front of your SELECT statement to see if your query will make use of any index. This is a good start for troubleshooting performance problems. Read more here: http://dev.mysql.com/doc/refman/5.0/en/explain.html

这篇关于SQL中的索引是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆