SQL server Date = @date 但 executionplan xml 显示为不等式
SQL server Date = @date but executionplan xml show it in inequality
所以我试图猜测 SQL 服务器将根据我编写的查询建议哪个缺失索引。请帮助我理解为什么这不被执行计划XML视为“平等”?我正在使用 SQL Server 2017。
我原以为这会被认为是“平等”,但显然对缺少索引创建语法的顺序做出了错误的猜测。
数据库名称 - Whosebug2013
查询:
set statistics io on
declare @year int = 2008
declare @date nvarchar(10)
while @year <= 2015
begin
set @date = cast (@year as nvarchar(6))+ cast('-05-27' as nvarchar(6))
select
title,
cast (CreationDate as date)
from
posts
where
cast (CreationDate as date) = @date
and title = 'Tool to diagonalize large matrices'
set @year = @year + 1
end
缺少索引建议:
/*
create NONCLUSTERED INDEX [NonClusteredIndex_creationdate]
ON [dbo].[Posts] ([Title],[CreationDate])
*/
执行计划XML:
<MissingIndexes>
<MissingIndexGroup Impact="99.9676">
<MissingIndex Database="[Whosebug2013]" Schema="[dbo]" Table="[Posts]">
<ColumnGroup Usage="EQUALITY">
<Column Name="[Title]" ColumnId="19" />
</ColumnGroup>
<ColumnGroup Usage="INEQUALITY">
<Column Name="[CreationDate]" ColumnId="8" />
</ColumnGroup>
</MissingIndex>
</MissingIndexGroup>
</MissingIndexes>
所以我试图猜测 SQL 服务器将根据我编写的查询建议哪个缺失索引。请帮助我理解为什么这不被执行计划XML视为“平等”?我正在使用 SQL Server 2017。
我原以为这会被认为是“平等”,但显然对缺少索引创建语法的顺序做出了错误的猜测。
数据库名称 - Whosebug2013
查询:
set statistics io on
declare @year int = 2008
declare @date nvarchar(10)
while @year <= 2015
begin
set @date = cast (@year as nvarchar(6))+ cast('-05-27' as nvarchar(6))
select
title,
cast (CreationDate as date)
from
posts
where
cast (CreationDate as date) = @date
and title = 'Tool to diagonalize large matrices'
set @year = @year + 1
end
缺少索引建议:
/*
create NONCLUSTERED INDEX [NonClusteredIndex_creationdate]
ON [dbo].[Posts] ([Title],[CreationDate])
*/
执行计划XML:
<MissingIndexes>
<MissingIndexGroup Impact="99.9676">
<MissingIndex Database="[Whosebug2013]" Schema="[dbo]" Table="[Posts]">
<ColumnGroup Usage="EQUALITY">
<Column Name="[Title]" ColumnId="19" />
</ColumnGroup>
<ColumnGroup Usage="INEQUALITY">
<Column Name="[CreationDate]" ColumnId="8" />
</ColumnGroup>
</MissingIndex>
</MissingIndexGroup>
</MissingIndexes>