In this article, we will discuss a few very common questions that you may be asked during a SQL Server administrator or developer technical job interview.

在本文中,我们将讨论一些非常常见的问题,在SQL Server管理员或开发人员进行技术面试时可能会询问您。

Q1:什么是SQL Server执行计划? (Q1: What is a SQL Server Execution Plan?)

SQL Server Execution Plan is a binary representation of the steps that are followed by the SQL Server Engine to execute the query. It also is known as the most efficient roadmap for the query

SQL Server 执行计划是SQL Server引擎执行查询所遵循的步骤的二进制表示。 它也被称为查询的最有效路线图

For more information, check SQL Server Execution Plans overview

有关更多信息,请查看SQL Server执行计划概述。

Q2:SQL Server Engine的哪个组件负责为提交的查询生成执行计划? (Q2: Which component of the SQL Server Engine is responsible for generating an Execution Plan for the submitted query?)

A: The SQL Server Query Optimizer is responsible for creating the most efficient plan to execute the provided query

答:SQL Server查询优化器负责创建最有效的计划以执行提供的查询

For more information, check SQL Server Execution Plans overview

有关更多信息,请查看SQL Server执行计划概述。

问题3:将生成的执行计划存储在哪里? (Q3: Where will the generated Execution Plan be stored?)

A: The SQL Server Execution Plan will be stored in the Plan Cache memory storage

答:SQL Server执行计划将存储在计划缓存的存储器中

For more information, check SQL Server Execution Plans overview

有关更多信息,请查看SQL Server执行计划概述。

问题4:将查询的执行计划存储在计划缓存中的目的是什么? (Q4: What is the goal behind storing the Execution Plan for the query in the Plan Cache?)

A: The process of generating the most optimal execution plan is an expensive process. Instead of creating a new Execution Plan each time a new query is submitted, the SQL Server Query Optimizer will search in the plan cache storage for an existing Execution Plan for the submitted query and use it. If there is no plan that can be used for that query, the Query Optimizer will create a new plan, taking more time to execute that query. The Execution plans reuse mechanism is very helpful when there are stored procedures executed frequently

答:生成最佳执行计划的过程非常昂贵。 SQL Server查询优化器将在计划缓存存储中搜索已提交查询的现有执行计划,并使用它,而不是每次提交新查询时都创建新的执行计划。 如果没有可用于该查询的计划,则查询优化器将创建一个新计划,这将花费更多时间来执行该查询。 当存储过程频繁执行时,执行计划重用机制非常有用

For more information, check SQL Server Execution Plans overview

有关更多信息,请查看SQL Server执行计划概述。

Q5:可以为T-SQL查询生成的执行计划的主要类型是什么?这两种类型之间有什么区别? (Q5: What are the main types of Execution Plans that you can generate for a T-SQL query and what is the difference between these two types?)

A: The Estimated Execution Plan. It is the plan that is generated by parsing the submitted query as an estimate of how the query will be executed, without being executed

答: 预计执行计划 。 它是通过解析提交的查询作为不执行该查询将如何执行的估计而生成的计划

The Actual Execution Plan, that is generated by executing the submitted query, displaying the actual steps that followed while executing the query

通过执行提交的查询生成的实际执行计划 ,显示执行查询时遵循的实际步骤

For more information, check SQL Server Execution Plans types

有关更多信息,请检查SQL Server执行计划类型。

问题6:三种执行计划格式是什么? (Q6: What are the three Execution Plan formats?)

A: Graphical Format, Text Format and XML Format

答: 图形格式文本格式和XML格式

For more information, check SQL Server Execution Plans types

有关更多信息,请检查SQL Server执行计划类型。

问题7:执行计划如何帮助识别特定查询的缺失索引? (Q7: How could the Execution Plan help in identifying the missing index for a specific query?)

A: Based on the available SQL Server statistics and the workload performed on the SQL Server, the SQL Server Query Optimizer will provide us with a suggested index, that may improve the performance of the submitted query in a calculated percentage. So, it will display that index as a recommendation with the query plan in green

答:根据可用SQL Server统计信息和在SQL Server上执行的工作量,SQL Server查询优化器将为我们提供建议的索引,该索引可以按计算出的百分比提高提交的查询的性能。 因此,它将以推荐的形式显示该索引,并以绿色显示查询计划

For more information, check How to Analyze SQL Execution Plan Graphical Components

有关更多信息,请检查如何分析SQL执行计划图形组件

Q8:阅读执行计划的正确方法是什么? (Q8: What is the correct way of reading the Execution Plan?)

A: The correct way to read the SQL Execution Plan is to start from the right side of the plan to the left side and from the top to the bottom, and the most left SELECT operator contains the final result of the submitted query

答:读取SQL执行计划的正确方法是计划的右侧开始到左侧,从顶部到底部 ,最左边的SELECT运算符包含提交的查询的最终结果。

For more information, check How to Analyze SQL Execution Plan Graphical Components

有关更多信息,请检查如何分析SQL执行计划图形组件

Q9:如何使用执行计划操作员之间的箭头来阅读计划? (Q9: How could we use the arrow between the Execution Plan operators to read the plan?)

A: You can make use of the arrows that are connecting the operators in identifying the direction and the amount of the data passed between the Execution Plan operators. In addition, the arrow is an indication of how much data passed between the operators

答:您可以利用连接运算符的箭头来确定执行计划运算符之间传递的数据的方向和数据 。 此外,箭头表示操作员之间传递了多少数据

For more information, check How to Analyze SQL Execution Plan Graphical Components

有关更多信息,请检查如何分析SQL执行计划图形组件

Q10:可以估计SQL执行计划的结果吗? (Q10: Can the Estimated SQL Execution Plan result be trusted?)

A: This depends on the statistics. If it is updated, the results should be the same. You need the Estimated SQL Execution Plan in case the query will take a long time to execute and you need to troubleshoot it

答:这取决于统计数据。 如果更新,结果应相同。 您需要估算SQL执行计划,以防查询需要很长时间来执行并且需要对其进行故障排除

For more information, check How to Analyze SQL Execution Plan Graphical Components

有关更多信息,请检查如何分析SQL执行计划图形组件

Q11:RID和密钥查找运算符之间有什么区别? (Q11: What is the difference between the RID and the Key Lookup operators?)

A: RID is a row locator that includes information about the location of that record such as the database file, the page, the slot numbers that helps to identify the location of the row quickly

答:RID是一个行定位器,其中包含有关该记录位置的信息,例如数据库文件,页面,插槽号,这些信息有助于快速识别行的位置

The Key Lookup operator is the Clustered equivalent of the RID Lookup operator

键查找操作是RID Lookup操作的集群等同

For more information, check SQL Server Execution Plan Operators – Part 2

有关更多信息,请检查SQL Server执行计划操作员–第2部分

问题12:执行计划中的汇总运算符是什么? (Q12: What is the Aggregate operator in the Execution Plan?)

A: The Aggregate Operator is mainly used to calculate the aggregate expressions in the submitted query, by grouping the values of an aggregated column. The aggregate expressions include the MIN, MAX, COUNT, AVG, SUM operations

答:聚合运算符主要用于通过对聚合列的值进行分组来计算提交的查询中的聚合表达式。 聚合表达式包括MIN,MAX,COUNT,AVG,SUM操作

For more information, check SQL Server Execution Plan Operators – Part 3

有关更多信息,请检查SQL Server执行计划操作员–第3部分

问题13:执行计划中的Compute Scalar运算符是什么? (Q13: What is the Compute Scalar operator in the Execution Plan?)

A: The Compute Scalar operator is used to perform scalar computation operations in order to calculate a new value from the existing row value

答: Compute Scalar运算符用于执行标量计算操作,以便从现有行值中计算新值

For more information, check SQL Server Execution Plan Operators – Part 3

有关更多信息,请检查SQL Server执行计划操作员–第3部分

问题14:执行计划中的串联运算符是什么? (Q14: What is the Concatenation operator in the Execution Plan?)

A: The Concatenation operator takes one or more data sets in sequence as inputs and returns all records from all the input data set. A good example of the concatenation operator is the UNION ALL T-SQL statement

答: 串联运算符按顺序将一个或多个数据集作为输入,并从所有输入数据集中返回所有记录。 连接运算符的一个很好的例子是UNION ALL T-SQL语句

For more information, check SQL Server Execution Plan Operators – Part 3

有关更多信息,请检查SQL Server执行计划操作员–第3部分

问题15:执行计划中的ASSERT运算符是什么? (Q15: What is the ASSERT operator in the Execution Plan?)

A: The Assert operator will verify whether the inserted values meet the defined CHECK or FOREIGN KEY constraints on the table called by the query

答: Assert运算符将验证插入的值是否满足查询调用的表上定义的CHECK或FOREIGN KEY约束

For more information, check SQL Server Execution Plan Operators – Part 3

有关更多信息,请检查SQL Server执行计划操作员–第3部分

问题16:执行计划中的哈希匹配运算符是什么? (Q16: What is the Hash Match operator in the Execution Plan?)

A: Hashing table is used when the SQL Server engine divides the joined tables in the query into equally sized buckets, using a Hashing Function, so that it can access these data in a quick manner. In this case, the SQL Server Optimizer will use the Hash Match operator to perform that action

答:当SQL Server引擎使用哈希 函数将查询中的联接表划分为大小相等的存储桶时,将使用哈希表 以便它可以快速访问这些数据。 在这种情况下,SQL Server Optimizer将使用哈希匹配运算符执行该操作

For more information, check SQL Server Execution Plan Operators – Part 3

有关更多信息,请检查SQL Server执行计划操作员–第3部分

Q17:执行计划中的惰性假脱机操作员是什么? (Q17: What is the Lazy Spool operator in the Execution Plan?)

A: The SQL Server Lazy Spool is used to build a temporary table on the TempDB and fill it in a lazy manner. In other words, it fills the table by reading and storing the data only when individual rows are required by the parent operator

答:SQL Server惰性缓冲池用于在TempDB上构建临时表并以惰性方式填充它。 换句话说,仅当父运算符需要单独的行时,它才通过读取和存储数据来填充表

For more information, check SQL Server Execution Plan Operators – Part 4

有关更多信息,请检查SQL Server执行计划操作员–第4部分

问题18:执行计划中的并行运算符是什么? (Q18: What is the Parallelism operator in the Execution Plan?)

A: The parallel plan is used by the SQL Server Engine to execute the expensive queries faster. The SQL Server Engine decides to use a parallel plan to execute the query when the SQL Server is installed on a multi-processor server, the number of threads that are requested are available to be assigned, the value of the Maximum Degree of Parallelism option is not equal to 1 and the cost of the submitted query is larger than the Cost Threshold for Parallelism value. The Parallelism operator is used by the SQL Server Engine to execute the query using a parallel plan

答:SQL Server Engine使用并行计划来更快地执行昂贵的查询。 当SQL Server安装在多处理器服务器上时,SQL Server引擎决定使用并行计划执行查询,可以分配请求的线程数,“ 最大并行度”选项的值为不等于1,并且提交的查询的成本大于“ 并行度的成本阈值”值。 SQL Server引擎使用Parallelism运算符使用并行计划执行查询

For more information, check SQL Server Execution Plan Operators – Part 4

有关更多信息,请检查SQL Server执行计划操作员–第4部分

问题19:我们如何从SQL Server执行计划中受益,以调整T-SQL查询性能? (Q19: How could we take benefits from the SQL Server Execution Plan in tuning the T-SQL queries performance?)

A: The SQL Server Execution Plan can be used in identifying the bad performance parts of the query. The first thing to look at is the most expensive operator with the highest cost, compared with the overall query cost. In addition, having a fat arrow, which is followed by a thin one, is an indication of the missing index that forced scanning a large amount of data to retrieve a small number of records

答:SQL Server执行计划可用于识别查询的不良性能部分。 首先要考虑的是与整体查询成本相比,成本最高的最昂贵的运营商 。 此外,带有粗线箭头 (后接细线箭头)表示缺少索引,该索引强制扫描大量数据以检索少量记录

Next, you need to search for the extra operators, as its overhead will degrade the query performance. Also, the Scan operators that read the overall table or index is an indication of a missing index, the existing index is badly used, or the submitted query has no filtering condition. The Execution Plan Warnings messages are a sign of different query performance problems that should be checked

接下来,您需要搜索额外的运算符 ,因为它的开销会降低查询性能。 此外,读取整个表或索引的扫描运算符还指示缺少索引,现有索引使用不当或所提交的查询没有过滤条件。 执行计划警告消息是应检查的不同查询性能问题的标志。

For more information, check Using the SQL Execution Plan for Query Performance Tuning

有关更多信息,请选中“ 使用SQL执行计划进行查询性能调整”

问题20:当大多数系统工作负载为临时查询时,可以使用什么SQL Server级选项来提高计划缓存使用性能并最大程度地减少内存压力? (Q20: What is the SQL Server level option that can be used to enhance the Plan Cache usage performance and minimize the memory pressure when the majority of your system workload are ad-hoc queries?)

A: You can enable the Optimize for Ad hoc Workloads option, to store the SQL Execution Plan of the query in the Plan Cache at the second execution of the query

答:您可以启用“ 优化临时工作负载”选项,以在第二次执行查询时将查询SQL执行计划存储在计划缓存中

For more information, check Saving your SQL Execution Plan

有关更多信息,请选中保存您SQL执行计划。

Q21:计划将在计划缓存中存储多长时间? (Q21: How long will the plan be stored in the Plan cache?)

A: It is useless to keep the SQL Server Execution Plan in the Plan cache forever. The SQL Server Engine will automatically drop any plan from the Plan Cache whenever more memory is required by the system or when the plan becomes old and not called for a long time. The SQL Server Engine users the Lazy Writer system process to clean these aged plans

答:将SQL Server执行计划永久保留在计划缓存中是没有用的。 每当系统需要更多内存或计划变旧且长时间未调用时,SQL Server引擎都会自动从计划缓存中删除任何计划。 SQL Server Engine用户使用Lazy Writer系统进程来清理这些老化的计划

For more information, check Saving your SQL Execution Plan

有关更多信息,请选中保存您SQL执行计划。

问题22:如何明确清除计划缓存? (Q22: How could we explicitly clear the Plan cache?)

A: Using the DBCC FREEPROCCACHE T-SQL command

答:使用DBCC FREEPROCCACHE T-SQL命令

For more information, check Saving your SQL Execution Plan

有关更多信息,请选中保存您SQL执行计划。

翻译自: https://www.sqlshack.com/sql-server-execution-plans-interview-questions/

SQL Server执行计划面试问题相关推荐

  1. SQL Server 执行计划缓存

    原文:SQL Server 执行计划缓存 标签:SQL SERVER/MSSQL SERVER/数据库/DBA/内存池/缓冲区 概述 了解执行计划对数据库性能分析很重要,其中涉及到了语句性能分析与存储 ...

  2. 剖析SQL Server执行计划

    -->Title: 淺議SQL Server执行计划 -->Author: wufeng4552 -->Date :2009-10-20 15:08:24 前言: 最近溫習了執行計劃 ...

  3. 引用:初探Sql Server 执行计划及Sql查询优化

    引用:初探Sql Server 执行计划及Sql查询优化 原文:引用:初探Sql Server 执行计划及Sql查询优化 初探Sql Server 执行计划及Sql查询优化 收藏 MSSQL优化之-- ...

  4. SQL Server执行计划那些事儿(3)——书签查找

    接下来的文章是记录自己曾经的盲点,同时也透漏了自己的发展历程(可能发展也算不上,只能说是瞎混).当然,一些盲点也在工作和探究过程中慢慢有些眉目,现在也愿意发扬博客园的奉献精神,拿出来和大家分享一下. ...

  5. SQL Server 执行计划(8) - 使用 SQL 执行计划进行查询性能调优

    在本系列的前几篇文章(见底部索引)中,我们介绍了SQL 执行计划的多个方面,我们讨论了执行计划是如何在内部生成的,不同类型的计划,主要组件和运算符以及如何阅读和分析使用不同工具生成的计划.在本文中,我 ...

  6. 一文搞定 SQL Server 执行计划

    导读 数据开发过程中,开发完成的 SQL 发布到生产环境,经常会发生 SQL 执行慢甚至根本无法执行,如何避免这种情况呢?这一篇我们分析一下 SQL Server 的执行计划是如何生成及如何阅读评估执 ...

  7. SQL SERVER 执行计划各字段注释

    SET SHOWPLAN_ALL 使 Microsoft® SQL Server™ 不执行 Transact-SQL 语句.相反,SQL Server 返回有关语句执行方式和语句预计所需资源的详细信息 ...

  8. 浅析SQL SERVER执行计划中的各类怪相

    在查看执行计划或调优过程中,执行计划里面有些现象总会让人有些疑惑不解: 1:为什么同一条SQL语句有时候会走索引查找,有时候SQL脚本又不走索引查找,反而走全表扫描? 2:同一条SQL语句,查询条件的 ...

  9. SQL Server执行计划的理解

    要理解执行计划,怎么也得先理解,那各种各样的名词吧.鉴于自己还不是很了解.本文打算作为只写懂的,不懂的懂了才写. 在开头要先说明,第一次看执行计划要注意,SQL Server的执行计划是从右向左看的. ...

最新文章

  1. SpringMVC 原理和流程
  2. 传统金融PK互联网 必须透过现象看本质
  3. java鼠标经过时变色_鼠标经过时单元格变色
  4. Python 生成器(yield)
  5. 设置XenServer中的Linux vm从光驱启动
  6. 文字在状态栏上从右往左显示,而且是循环的
  7. mybatis 详解(三)------入门实例(基于注解)
  8. ElementUI 按需引入坑爹的点记录
  9. matlab可以用python代替吗_Python 会不会替代 MATLAB
  10. 取石子游戏,威佐夫博弈的推理
  11. R语言 rgl plot3d函数
  12. 查看论文是否被ISTP、EI检索
  13. Candidate是什么
  14. 简单使用PHP 的 Silm框架.
  15. 计算机专业—毕业设计题目大全
  16. pitfall when implementing multiple interfaces
  17. 信息系统项目管理师之信息化与信息系统
  18. shields 徽标_创意讲故事徽标的剖析
  19. 植物大战僵尸无尽版游泳池优秀阵容推荐(一)
  20. 起点篇:跨入半导体行业,数字IC设计

热门文章

  1. iphonex屏幕出现一条绿线_关于对 iPhone 11、iPhone X? 采用的 Liquid 视网膜显示屏的误区,在此说明。...
  2. suse linux系统备份,suse linux enterprise server 11 sp3 版克隆安装ebs r12.1.3注意事项
  3. HTML li标签排列有空白间隙
  4. [APIO / CTSC2007]数据备份 --- 贪心
  5. 安装apache 后,找不到服务,解决办法
  6. 20145101 《Java程序设计》第7周学习总结
  7. 你误解了Windows的文件后缀名吗?
  8. 第一百七十四天 how can i 坚持
  9. hdu 1003 Max Sum (DP)
  10. linux服务器上svn的log_SVN如何查看修改的文件记录