mysql 索引太多?

2023-10-25数据库问题
3

本文介绍了mysql 索引太多?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在花一些时间优化我们当前的数据库.

I am spending some time optimizing our current database.

我正在专门研究索引.

有几个问题:

  • 索引是否过多?
  • 索引会加速什么?
  • 索引会减慢什么?
  • 什么时候添加索引比较好?
  • 什么时候添加索引是个坏主意?
  • 多索引与多列索引的优缺点?

推荐答案

索引会加速什么?

What will indexes speed up?

数据检索 -- SELECT 语句.

Data retrieval -- SELECT statements.

索引会减慢什么?

数据操作 -- INSERT、UPDATE、DELETE 语句.

Data manipulation -- INSERT, UPDATE, DELETE statements.

什么时候添加索引比较好?

When is it a good idea to add an index?

如果您想获得更好的数据检索性能.

If you feel you want to get better data retrieval performance.

什么时候添加索引是个坏主意?

When is it a bad idea to add an index?

在将要进行大量数据操作的表上 -- 插入、更新...

On tables that will see heavy data manipulation -- insertion, updating...

多索引与多列索引的优缺点?

Pro's and Con's of multiple indexes vs multi-column indexes?

在处理覆盖索引(多列上的索引)时,查询需要处理列的顺序,在索引列定义中从左到右.语句中的列顺序无关紧要,只有第 1、2 和 3 列的顺序 - 在使用索引之前,语句需要引用第 1 列.如果只有第 2 列或第 3 列的引用,则无法使用 1/2/3 的覆盖索引.

Queries need to address the order of columns when dealing with a covering index (an index on more than one column), from left to right in index column definition. The column order in the statement doesn't matter, only that of columns 1, 2 and 3 - a statement needs have a reference to column 1 before the index can be used. If there's only a reference to column 2 or 3, the covering index for 1/2/3 could not be used.

在 MySQL 中,查询中的每个 SELECT/语句只能使用一个索引(子查询/等被视为单独的语句).MySQL 允许的每个表的空间量是有限制的.此外,在索引列上运行函数会使索引无用 - IE:

In MySQL, only one index can be used per SELECT/statement in the query (subqueries/etc are seen as a separate statement). And there's a limit to the amount of space per table that MySQL allows. Additionally, running a function on an indexed column renders the index useless - IE:

WHERE DATE(datetime_column) = ...

这篇关于mysql 索引太多?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

Mysql目录里的ibtmp1文件过大造成磁盘占满的解决办法
ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致...
2025-01-02 数据库问题
151

按天分组的 SQL 查询
SQL query to group by day(按天分组的 SQL 查询)...
2024-04-16 数据库问题
77

SQL 子句“GROUP BY 1"是什么意思?意思是?
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)...
2024-04-16 数据库问题
62

MySQL groupwise MAX() 返回意外结果
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)...
2024-04-16 数据库问题
13

MySQL SELECT 按组最频繁
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)...
2024-04-16 数据库问题
16

在 Group By 查询中包含缺失的月份
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)...
2024-04-16 数据库问题
12