【发布时间】:2021-03-26 08:46:42
【问题描述】:
我有这个查询,基本上(现在)只返回 10 行结果:
select *
FROM Table1 as o
inner join Table2 as t on t.Field1 = o.Field2
where Code = 123456 and t.FakeData is not null
现在,如果我想解析 FakeData 字段(不幸的是,它可以包含不同类型的数据,从 DateTime 到 Surname/etc;即 nvarchar(70)),用于数据显示和/或过滤:
select *, TRY_PARSE(t.FakeData as date USING 'en-GB') as RealDate
FROM Table1 as o
inner join Table2 as t on t.Field1 = o.Field2
where Code = 123456 and t.FakeData is not null
执行查询需要 x10 倍。
我哪里错了?我怎样才能加快速度?
我无法编辑数据库,我只是读取数据的客户。
【问题讨论】:
-
你看过执行计划了吗?
-
包含不同类型数据的列表明存在架构设计缺陷,您可能会在查询中付出代价。
-
哪个表包含 where 子句中使用的
code? (提示:始终包含别名)
标签: sql-server performance datetime parsing