In SQL Server, what works best: where ProcessedDate is null or where Processed = 0

I am trying to decide which approach to take in the database that I am developing. I will add a column ProcessedDate datetime nullto the table. It will be null if the record was not processed. So is it worth having a column Processed bit not null default 0?

With the following queries:

select * from tablename where ProcessedDate is null

and

select * from tablename where Processed = 0

All things being equal *, what is the difference in performance between the two versions?

*: The corresponding indexes apply to the table in each version. I'm not looking for tips on which indexes to create. I need information on filter efficiency in only one line. If all the rows of the table should be scanned or the search is done, this is not relevant to the issue under consideration.

, , Processed , , , ( ). , .

+3
4

ProcessedDate is null , ( ) .

where Processed = 0, SQL- Processed = @p, , @p = 0. - , where Processed = 1, @p = 1, , , , , .

+1

, , . . , , , . , , , .


WITH Test (MyInt, MyNull)
AS
(
SELECT 1 AS MyInt, Null AS MyNull

UNION ALL

SELECT 
    MyInt + 1,
    CASE
        WHEN MyInt % 2 = 0 THEN Null
        ELSE MyInt
    END
FROM Test
WHERE MyInt < 10000
)

SELECT * FROM Test
WHERE MyNull IS NULL
OPTION (MAXRECURSION 32767);

WITH Test (MyInt, MyBit)
AS
(
SELECT 1 AS MyInt, 0 AS MyBit

UNION ALL

SELECT 
    MyInt + 1,
    CASE
        WHEN MyInt % 2 = 0 THEN 0
        ELSE 1
    END
FROM Test
WHERE MyInt < 10000
)

SELECT * FROM Test
WHERE MyBit = 0
OPTION (MAXRECURSION 32767);

, , 0. CTE , .

+3

.

.

( , "" " " , ).

+2

SQL, , SQL. , , .

ProcessedDate , * , .

, Processed , ( " " , ).

ProcessedDate , .

, : , . .

+2

Source: https://habr.com/ru/post/1733991/


All Articles