热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

MySQL5.78.2.1OptimizingSELECTStatements(优化SELELCT语句)

Queries,intheformof SELECT statements,performallthelookupoperationsinthedatabase.查询以SELECT

Queries, in the form of SELECT statements, perform all the lookup operations in the database.

查询以SELECT语句的形式执行数据库中的所有查找操作。

Tuning these statements is a top priority, whether to achieve sub-second response times for dynamic web pages, or to chop hours off the time to generate huge overnight reports.

调优这些语句是最重要的,无论是为了实现动态网页的次秒级响应时间,还是为了减少生成大量夜间报告的时间。

Besides SELECT statements, the tuning techniques for queries also apply to constructs such as CREATE TABLE...AS SELECT, INSERT INTO...SELECT, and WHERE clauses in DELETE statements. 

除了SELECT语句,查询的调优技术也适用于诸如CREATE TABLE…As select, insert into…DELETE语句中的SELECT和WHERE子句。

 Those statements have additional performance considerations because they combine write operations with the read-oriented query operations.

这些语句有额外的性能考虑因素,因为它们将写操作与面向读的查询操作结合在一起。

NDB Cluster supports a join pushdown optimization whereby a qualifying join is sent in its entirety to NDB Cluster data nodes, where it can be distributed among them and executed in parallel. For more information about this optimization, see Conditions for NDB pushdown joins.

NDB集群支持一个连接下推优化,通过这个优化,一个合格的连接被完整地发送到NDB集群的数据节点,在那里它可以分布在它们之间并并行执行。有关此优化的更多信息,请参见NDB下推连接的条件。

The main considerations for optimizing queries are:

优化查询的主要考虑事项是:

To make a slow SELECT ... WHERE query faster, the first thing to check is whether you can add an index. Set up indexes on columns used in the WHERE clause, to speed up evaluation, filtering, and the final retrieval of results. To avoid wasted disk space, construct a small set of indexes that speed up many related queries used in your application.

要做一个缓慢的SELECT…在查询速度更快的地方,首先要检查的是是否可以添加索引。在WHERE子句中使用的列上设置索引,以加快对结果的计算、筛选和最终检索。为了避免浪费磁盘空间,可以构建一小组索引,以加速应用程序中使用的许多相关查询。

Indexes are especially important for queries that reference different tables, using features such as joins and foreign keys. 

索引对于使用连接和外键等特性引用不同表的查询尤其重要。

You can use the EXPLAIN statement to determine which indexes are used for a SELECT. See Section 8.3.1, “How MySQL Uses Indexes” and Section 8.8.1, “Optimizing Queries with EXPLAIN”.

您可以使用EXPLAIN语句来确定用于SELECT的索引。

Isolate and tune any part of the query, such as a function call, that takes excessive time.

隔离和调优查询的任何部分(如函数调用),因为这些部分占用了过多的时间。

Depending on how the query is structured, a function could be called once for every row in the result set, or even once for every row in the table, greatly magnifying any inefficiency.

根据查询的结构,可以对结果集中的每一行调用一次函数,甚至可以对表中的每一行调用一次函数,这大大提高了效率

Minimize the number of full table scans in your queries, particularly for big tables.

在查询中尽量减少全表扫描的次数,特别是对于大表。

Keep table statistics up to date by using the ANALYZE TABLE statement periodically, so the optimizer has the information needed to construct an efficient execution plan.

通过定期使用ANALYZE table语句,来保持表统计信息的更新,这样优化器就有了构建高效执行计划所需的信息。

Learn the tuning techniques, indexing techniques, and configuration parameters that are specific to the storage engine for each table.

学习特定于每个存储引擎的调优技术、索引技术和配置参数。

Both InnoDB and MyISAM have sets of guidelines for enabling and sustaining high performance in queries. For details, see Section 8.5.6, “Optimizing InnoDB Queries” and Section 8.6.1, “Optimizing MyISAM Queries”.

InnoDB和MyISAM都有一套在查询中启用和保持高性能的指导原则。

You can optimize single-query transactions for InnoDB tables, using the technique in Section 8.5.3, “Optimizing InnoDB Read-Only Transactions”.

你可以优化InnoDB表的单查询事务

Avoid transforming the query in ways that make it hard to understand, especially if the optimizer does some of the same transformations automatically.

避免以难以理解的方式转换查询,特别是在优化器自动执行一些相同的转换时。

If a performance issue is not easily solved by one of the basic guidelines, investigate the internal details of the specific query by reading the EXPLAIN plan and adjusting your indexes, WHERE clauses, join clauses, and so on. (When you reach a certain level of expertise, reading the EXPLAIN plan might be your first step for every query.)

如果性能问题不容易通过基本准则解决,可以通过阅读EXPLAIN计划并调整索引、WHERE子句、连接子句等来研究特定查询的内部细节。(当您达到一定的专业水平时,阅读EXPLAIN计划可能是您处理每个查询的第一步)

Adjust the size and properties of the memory areas that MySQL uses for caching.

调整MySQL用于缓存的内存区域的大小和属性。

With efficient use of the InnoDB buffer pool, MyISAM key cache, and the MySQL query cache, repeated queries run faster because the results are retrieved from memory the second and subsequent times.

通过有效地使用InnoDB缓冲池、MyISAM密钥缓存和MySQL查询缓存,重复查询运行得更快,因为结果后面是从内存中检索。

Even for a query that runs fast using the cache memory areas, you might still optimize further so that they require less cache memory, making your application more scalable.

即使对于使用缓存内存区域快速运行的查询,您仍然可以进一步优化,以便它们需要更少的缓存内存,从而使应用程序更具可伸缩性。

Scalability means that your application can handle more simultaneous users, larger requests, and so on without experiencing a big drop in performance.

可伸缩性意味着您的应用程序可以处理更多的并发用户、更大的请求等等,而不会出现性能上的大下降。

Deal with locking issues, where the speed of your query might be affected by other sessions accessing the tables at the same time.

处理锁定问题,其中查询的速度可能会受到同时访问表的其他会话的影响。



推荐阅读
  • WhenIusepythontoapplythepymysqlmoduletoaddafieldtoatableinthemysqldatabase,itdo ... [详细]
  • Oracle Database 10g许可授予信息及高级功能详解
    本文介绍了Oracle Database 10g许可授予信息及其中的高级功能,包括数据库优化数据包、SQL访问指导、SQL优化指导、SQL优化集和重组对象。同时提供了详细说明,指导用户在Oracle Database 10g中如何使用这些功能。 ... [详细]
  • Metasploit攻击渗透实践
    本文介绍了Metasploit攻击渗透实践的内容和要求,包括主动攻击、针对浏览器和客户端的攻击,以及成功应用辅助模块的实践过程。其中涉及使用Hydra在不知道密码的情况下攻击metsploit2靶机获取密码,以及攻击浏览器中的tomcat服务的具体步骤。同时还讲解了爆破密码的方法和设置攻击目标主机的相关参数。 ... [详细]
  • 解决VS写C#项目导入MySQL数据源报错“You have a usable connection already”问题的正确方法
    本文介绍了在VS写C#项目导入MySQL数据源时出现报错“You have a usable connection already”的问题,并给出了正确的解决方法。详细描述了问题的出现情况和报错信息,并提供了解决该问题的步骤和注意事项。 ... [详细]
  • 本文详细介绍了MySQL表分区的创建、增加和删除方法,包括查看分区数据量和全库数据量的方法。欢迎大家阅读并给予点评。 ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • 本文详细介绍了如何使用MySQL来显示SQL语句的执行时间,并通过MySQL Query Profiler获取CPU和内存使用量以及系统锁和表锁的时间。同时介绍了效能分析的三种方法:瓶颈分析、工作负载分析和基于比率的分析。 ... [详细]
  • MySQL外键1对多问题的解决方法及实例
    本文介绍了解决MySQL外键1对多问题的方法,通过准备数据、创建表和设置外键关联等步骤,实现了用户分组和插入数据的功能。详细介绍了数据准备的过程和外键关联的设置,以及插入数据的示例。 ... [详细]
  • PDO MySQL
    PDOMySQL如果文章有成千上万篇,该怎样保存?数据保存有多种方式,比如单机文件、单机数据库(SQLite)、网络数据库(MySQL、MariaDB)等等。根据项目来选择,做We ... [详细]
  • 本文主要复习了数据库的一些知识点,包括环境变量设置、表之间的引用关系等。同时介绍了一些常用的数据库命令及其使用方法,如创建数据库、查看已存在的数据库、切换数据库、创建表等操作。通过本文的学习,可以加深对数据库的理解和应用能力。 ... [详细]
  • VueCLI多页分目录打包的步骤记录
    本文介绍了使用VueCLI进行多页分目录打包的步骤,包括页面目录结构、安装依赖、获取Vue CLI需要的多页对象等内容。同时还提供了自定义不同模块页面标题的方法。 ... [详细]
  • MySQL语句大全:创建、授权、查询、修改等【MySQL】的使用方法详解
    本文详细介绍了MySQL语句的使用方法,包括创建用户、授权、查询、修改等操作。通过连接MySQL数据库,可以使用命令创建用户,并指定该用户在哪个主机上可以登录。同时,还可以设置用户的登录密码。通过本文,您可以全面了解MySQL语句的使用方法。 ... [详细]
  • Webpack5内置处理图片资源的配置方法
    本文介绍了在Webpack5中处理图片资源的配置方法。在Webpack4中,我们需要使用file-loader和url-loader来处理图片资源,但是在Webpack5中,这两个Loader的功能已经被内置到Webpack中,我们只需要简单配置即可实现图片资源的处理。本文还介绍了一些常用的配置方法,如匹配不同类型的图片文件、设置输出路径等。通过本文的学习,读者可以快速掌握Webpack5处理图片资源的方法。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 本文讨论了使用差分约束系统求解House Man跳跃问题的思路与方法。给定一组不同高度,要求从最低点跳跃到最高点,每次跳跃的距离不超过D,并且不能改变给定的顺序。通过建立差分约束系统,将问题转化为图的建立和查询距离的问题。文章详细介绍了建立约束条件的方法,并使用SPFA算法判环并输出结果。同时还讨论了建边方向和跳跃顺序的关系。 ... [详细]
author-avatar
淅沥的雨的海角_960
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有