当我遇到这个东西时,我正在研究其他东西。我正在生成包含一些数据的测试表并运行不同的查询,以了解编写查询的不同方式如何影响执行计划。这是我用来生成随机测试数据的脚本:
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID('t') AND type in (N'U'))
DROP TABLE t
GO
CREATE TABLE t
(
c1 int IDENTITY(1,1) NOT NULL
,c2 int NULL
)
GO
insert into t
select top 1000000 a from
(select t1.number*2048 + t2.number a, newid() b
from [master]..spt_values t1
cross join [master]..spt_values t2
where t1.[type] = 'P' and t2.[type] = 'P') a
order by b
GO
update t set c2 = null
where c2 < 2048 * 2048 …Run Code Online (Sandbox Code Playgroud) 有人知道我如何列出 SQL Server 实例中的准备好的语句吗?
使用 StackOverflow2010 数据库,我可以在 users 表上创建索引,如下所示:
CREATE INDEX IX_DisplayName ON dbo.Users
(
DisplayName,
UpVotes
)
Run Code Online (Sandbox Code Playgroud)
然后对索引的键运行不等式搜索:
SELECT DisplayName,
UpVotes
FROM Users
WHERE DisplayName <> N'Alex'
Run Code Online (Sandbox Code Playgroud)
我在这里得到计划
我正在尝试弄清楚 SQL Server 如何获取此查询的结果。
该计划从一些持续扫描开始,但输出列表是空白的,因此我不清楚它们的用途。
然后,每个恒定扫描进入一个计算标量,每个计算标量输出
Compute Scalar Node6
Expr1002 = 10
Expr1003 = NULL
Expr1004 = N'Alex'
Compute Scalar Node9
Expr1005 = 6
Expr1006 = N'Alex'
Expr1007 = NULL
Run Code Online (Sandbox Code Playgroud)
然后,连接运算符似乎连接了上面的一些输出:
Expr1010 = Expr1008,Expr1006
Expr1011 = Expr1004,Expr1009
Expr1012 = Expr1002,Expr1005
Run Code Online (Sandbox Code Playgroud)
但它有我在计划中看不到的输入(Expr 1008 和 Expr1009)
我也不知道为什么需要TOP N排序
索引搜索是有意义的 - 它正在寻找 > Expr1011 和 < Expr1012。我 …
sql-server ×3