We have a payment table that has 35 columns with a primary key (autoinc bigint) and 3 non-clustered, non-unique indexes (each with one int column).
Among the table columns, there are two datetime fields:
The table has about 1,200,000 rows. Only ~ 1000 rows have an edit_date = null column. 9000 lines have edit_date not null and not equal payment_date Others have edit_date = payment_date
When we run the following query 1 :
select top 1 *
from payments
where edit_date is not null and (payment_date=edit_date or payment_date<>edit_date)
order by payment_date desc

ServerIt takes a few seconds to do this. But if we run query 2 :
select top 1 *
from payments
where edit_date is not null
order by payment_date desc

"tempdb" . , .
* , . 3
select top 1 payment_date
from payments
where edit_date is not null
order by payment_date desc

.
?
1 , , . , 2 tempdb.
ANSWER
, , - , . , : sql - ( 1 2); . , tempdb , ...
, , , , ( )