StmtText ------------------------------------------------------------------------- select * from objective o where isnull(o.userdefinedstatus,0)<5(1 行受影响)StmtText ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |--Clustered Index Scan(OBJECT:([dzh_mobile].[dbo].[OBJECTIVE].[pk_objective_guid] AS [o]), WHERE:(CONVERT_IMPLICIT(int,isnull([dzh_mobile].[dbo].[OBJECTIVE].[USERDEFINEDSTATUS] as [o].[USERDEFINEDSTATUS],'0 '),0)<(5)))(1 行受影响)StmtText -------------------------------------------------------------------------------select * from objective o where isnull(o.userdefinedstatus,0) in(0,1,2,3,4)(1 行受影响)StmtText ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |--Clustered Index Scan(OBJECT:([dzh_mobile].[dbo].[OBJECTIVE].[pk_objective_guid] AS [o]), WHERE:(CONVERT_IMPLICIT(int,isnull([dzh_mobile].[dbo].[OBJECTIVE].[USERDEFINEDSTATUS] as [o].[USERDEFINEDSTATUS],'0 '),0)=(4) OR CONVERT_IMPLICIT(int,isnull([(1 行受影响)这个执行计划怎么看,从上面分析可以看出什么东西出来呢?
select * from sale where isnull(o.userdefinedstatus,0)<=4 . 不过建议不要有NULL值,给字段一个Default值那样查询的效率就更高了.
select * from sale where isnull(o.userdefinedstatus,0) in(0,1,2,3,4)
这个运行快还是isnull(o.userdefinedstatus,0)<5还是这个运行快呢?能否分析为什么会快?
set showplan_Text on
-------------------------------------------------------------------------
select * from objective o where isnull(o.userdefinedstatus,0)<5(1 行受影响)StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Clustered Index Scan(OBJECT:([dzh_mobile].[dbo].[OBJECTIVE].[pk_objective_guid] AS [o]), WHERE:(CONVERT_IMPLICIT(int,isnull([dzh_mobile].[dbo].[OBJECTIVE].[USERDEFINEDSTATUS] as [o].[USERDEFINEDSTATUS],'0 '),0)<(5)))(1 行受影响)StmtText
-------------------------------------------------------------------------------select * from objective o where isnull(o.userdefinedstatus,0) in(0,1,2,3,4)(1 行受影响)StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|--Clustered Index Scan(OBJECT:([dzh_mobile].[dbo].[OBJECTIVE].[pk_objective_guid] AS [o]), WHERE:(CONVERT_IMPLICIT(int,isnull([dzh_mobile].[dbo].[OBJECTIVE].[USERDEFINEDSTATUS] as [o].[USERDEFINEDSTATUS],'0 '),0)=(4) OR CONVERT_IMPLICIT(int,isnull([(1 行受影响)这个执行计划怎么看,从上面分析可以看出什么东西出来呢?