gpt4 book ai didi

sql-server - Sql 服务器的持续扫描 - 澄清吗?

转载 作者:行者123 更新时间:2023-12-02 16:11:12 26 4
gpt4 key购买 nike

我已阅读 this article about不断地扫描,但还是不明白什么时候会用到(人们评论作者说他的文章仍然不明白):

MSDN:

The Constant Scan operator introduces one or more constant rows into a query. A Compute Scalar operator is often used to add columns to a row produced by a Constant Scan operator.

非常不清楚。

例如:

为什么 SELECT TOP 1 GETDATE() 会产生:

enter image description here

虽然 select getdate() 没有产生任何结果。 (在执行计划中)。

我猜这与持续扫描有关。所以:

问题:

  • 到底什么是持续扫描
  • 如果它是常量,为什么需要扫描某些内容,并且
  • 为什么 select top 1 getdate() 产生的结果与普通 select getdate() 不同

最佳答案

因为大多数用于完成查询的运算符都是根据一个或多个输入行集和一个或多个输出行集指定的,因此如果您编写一个需要使用这些运算符之一时,您最好确保向该运算符提供的输入是行集。

因此,常量扫描运算符是一种特殊的运算符,它可以接受一个或多个标量输入并生成行集。

它使编写运算符变得更加容易。

<小时/>

Why does select top 1 getdate() yield different result than plain select getdate()

因为您要求使用 TOP 运算符。 TOP 运算符期望有一个输入行集。

<小时/>

为什么我认为关注性能无关紧要:

SET STATISTICS TIME ON
GO
SELECT TOP 1 GETDATE()
GO
SELECT GETDATE()

消息:

SQL Server parse and compile time:    CPU time = 0 ms, elapsed time = 0 ms. SQL Server Execution Times:   CPU time = 0 ms,  elapsed time = 0 ms.SQL Server parse and compile time:    CPU time = 0 ms, elapsed time = 0 ms.(1 row(s) affected) SQL Server Execution Times:   CPU time = 0 ms,  elapsed time = 0 ms.SQL Server parse and compile time:    CPU time = 0 ms, elapsed time = 0 ms.(1 row(s) affected) SQL Server Execution Times:   CPU time = 0 ms,  elapsed time = 0 ms.

也就是说,我们甚至无法测量任一语句执行所需的时间。

关于sql-server - Sql 服务器的持续扫描 - 澄清吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24751868/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com