小编lif*_*ney的帖子

Select * Order by 与 Select column 按性能排序

我有以下表格

Create Table dbo.product
(
productId varchar(100) primary key,
productStatus varchar(100),
productRegion varchar(100),
productCreated  datetime,
productUpdated datetime
)
Go

declare @id int = 1
while @id <= 100
Begin

Insert Into dbo.product values ('product'+cast(@id as varchar(10)),'Active','North',getdate(),getdate())
    set @id = @id + 1
End

set @id = 1
while @id <= 100
Begin

Insert Into dbo.product values ('inprod'+ cast(@id as varchar(10)),'InActive','South',getdate(),getdate())
    set @id = @id + 1
End
Go

Create Table dbo.productRef
(
productRef int Identity(1,1) primary key,
productId varchar(100),
productName …
Run Code Online (Sandbox Code Playgroud)

sql-server optimization query-performance

5
推荐指数
2
解决办法
3655
查看次数

测试时使用缓存数据的存储过程性能不佳

我有一个存储过程,第一次运行大约需要 15 秒,后续运行需要 1 到 2 秒。如果我等待一个小时并再次运行它,则再次需要 15 秒。

我猜测它在后续运行中使用缓冲池中的缓存数据,而第一次它必须将数据从磁盘加载到缓冲池。我正在尝试调整此存储过程,但第一次运行后我无法测试我的更改,因为它只需要 1 到 2 秒。

我知道我可以使用该DBCC DROPCLEANBUFFERS命令释放缓存并运行我的存储过程,但我不允许在工作中清除缓存。我WITH RECOMPILE也尝试过,但这只会创建一个新计划,但仍然使用缓存的数据。是否有另一种方法强制存储过程不使用缓存数据?

sql-server optimization performance-tuning

4
推荐指数
1
解决办法
691
查看次数

SQL Server 中不等于运算符不返回 NULL 值

我有以下查询,我正在查找该列不等于 1 的任何行istrue。但结果只包含 0 的记录,忽略 null 的记录。虽然我知道使用(istrue != 1 or istrue is null)会产生预期的结果,但我很好奇导致 SQL Server 排除 null 值的底层机制。您能否提供对此行为的见解?谢谢!

create table #test
(
id int,
val varchar(100),
istrue bit
)

insert into #test values 
(1, 'test-1', 1),
(2, 'test-2', 0),
(3, 'test-3', 1),
(4, 'test-4', 0),
(5, 'test-5', null),
(6, 'test-6', null)

select * from #test
where istrue != 1

drop table if exists #test
Run Code Online (Sandbox Code Playgroud)

null sql-server query

3
推荐指数
3
解决办法
2173
查看次数