Home Database Mysql Tutorial MYSQL索引无效和索引有效的详细介绍_MySQL

MYSQL索引无效和索引有效的详细介绍_MySQL

Jun 01, 2016 pm 01:24 PM
data sheet

bitsCN.com 1、WHERE字句的查询条件里有不等于号(WHERE column!=...),MYSQL将无法使用索引
2、类似地,如果WHERE字句的查询条件里使用了函数(如:WHERE DAY(column)=...),MYSQL将无法使用索引
3、在JOIN操作中(需要从多个数据表提取数据时),MYSQL只有在主键和外键的数据类型相同时才能使用索引,否则即使建立了
 索引也不会使用
4、如果WHERE子句的查询条件里使用了比较操作符LIKE和REGEXP,MYSQL只有在搜索模板的第一个字符不是通配符的情况下才能
使用索引。比如说,如果查询条件是LIKE 'abc%',MYSQL将使用索引;如果条件是LIKE '%abc',MYSQL将不使用索引。
5、在ORDER BY操作中,MYSQL只有在排序条件不是一个查询条件表达式的情况下才使用索引。尽管如此,在涉及多个数据表的查
询里,即使有索引可用,那些索引在加快ORDER BY操作方面也没什么作用。
6、如果某个数据列里包含着许多重复的值,就算为它建立了索引也不会有很好的效果。比如说,如果某个数据列里包含了净是
些诸如“0/1”或“Y/N”等值,就没有必要为它创建一个索引。

7、索引有用的情况下就太多了。基本只要建立了索引,除了上面提到的索引不会使用的情况下之外,其他情况只要是使用在
WHERE条件里,ORDER BY 字段,联表字段,一般都是有效的。 建立索引要的就是有效果。 不然还用它干吗? 如果不能确定在
某个字段上建立的索引是否有效果,只要实际进行测试下比较下执行时间就知道。bitsCN.com

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Data table compression technology in MySQL Data table compression technology in MySQL Jun 16, 2023 am 08:16 AM

Data table compression technology in MySQL

mysql modify data table name mysql modify data table name Jun 20, 2023 pm 05:52 PM

mysql modify data table name

Data table DDL operation technology in MySQL Data table DDL operation technology in MySQL Jun 15, 2023 pm 07:55 PM

Data table DDL operation technology in MySQL

How to calculate the average value of numeric columns in a data table using MySQL's AVG function How to calculate the average value of numeric columns in a data table using MySQL's AVG function Jul 24, 2023 pm 09:52 PM

How to calculate the average value of numeric columns in a data table using MySQL's AVG function

Data table reloading techniques in MySQL Data table reloading techniques in MySQL Jun 15, 2023 pm 11:28 PM

Data table reloading techniques in MySQL

How to implement MySQL underlying optimization: horizontal and vertical splitting strategies for data tables How to implement MySQL underlying optimization: horizontal and vertical splitting strategies for data tables Nov 08, 2023 pm 06:57 PM

How to implement MySQL underlying optimization: horizontal and vertical splitting strategies for data tables

How to use the MAX function in MySQL to find the largest value in the data table How to use the MAX function in MySQL to find the largest value in the data table Jul 25, 2023 pm 09:49 PM

How to use the MAX function in MySQL to find the largest value in the data table

How to use thinkorm to implement related queries between data tables How to use thinkorm to implement related queries between data tables Aug 01, 2023 am 08:25 AM

How to use thinkorm to implement related queries between data tables

See all articles