减少执行时间的提示

时间:2018-06-18 15:20:07

标签: sql-server

我有以下查询运行良好,并按预期给我结果。

但是查询的执行时间接近10分钟。有什么方法可以让它跑得更快吗?我假设这是因为超前滞后的方法。任何想法或建议,将不胜感激。我正在使用MS - SQL。基础表有近40K的记录。

提前致谢!

SQL查询:

you could try by importing  ComponentFixtureAutoDetect for auto detection change -

import { ComponentFixtureAutoDetect } from '@angular/core/testing'

then you can use it in provider - 

TestBed.configureTestingModule({
  declarations: [ BannerComponent ],
  providers: [
    { provide: ComponentFixtureAutoDetect, useValue: true }
  ]
});

By this you don't need to call fixture.detectchanges() every time 

1 个答案:

答案 0 :(得分:0)

取出ConvertIGDateTime函数并将该函数写入语句。可能正在计算每一行,并阻止日期字段被sargable。 如果可能,请从标题字段子句中删除%%。

将WHERE子句的结尾更改为:

and DateStart > CAST(n.CREATEDDATE AS DATETIME) + CAST(n.CREATEDTIME AS DATETIME) 
and (Dateend < CAST(n.CREATEDDATE AS DATETIME) + CAST(n.CREATEDTIME AS DATETIME)
or Dateend is null and getdate() < CAST(n.CREATEDDATE AS DATETIME) + CAST(n.CREATEDTIME AS DATETIME))

此外,条款:and convert(date, (convert(varchar(10), next_createddate))) > dateadd(day, 10, convert(date, convert(varchar(10), createddate)))

可以使用索引,并且可以更好地执行:

and cast(next_createddate as date) > dateadd(day, 10, cast(createddate as date))