SQL Server 2008: decimal column where decimal part effects parameter requests speed

I have a decimal (15,10) column that contains the OLE date creation date format. And when you execute a query like

SELECT * FROM SOMETABLE WHERE RECORDTIMEOA BETWEEN 41667 AND 41667.9999999999 --Decimal Part is 10 characters

the query returns all results after 8 or 9 seconds. But instead of using the integer value 41667, you use 41667.0000000000, then the query returns all results in less than 1 second . This also happens when you put 9 or 8 characters in the second decimal part, for example

SELECT * FROM SOMETABLE WHERE RECORDTIMEOA  BETWEEN 41667 AND 41667.99999999 --Decimal part is 8 characters

I have a non-clustered index in this column, maybe this affects this problem, so I'm wondering what is the difference between the below queries, why does the first return in 8 seconds and the rest in less than 1 second?

SELECT * FROM SOMETABLE WHERE RECORDTIMEOA  BETWEEN 41667 AND 41667.9999999999
SELECT * FROM SOMETABLE WHERE RECORDTIMEOA  BETWEEN 41667 AND 41667.9999999
SELECT * FROM SOMETABLE WHERE RECORDTIMEOA  BETWEEN 41667.0000000000 AND 41667.9999999999

, , .

UPDATE:

This is the execution plan of slow query.

This is the execution plan of fast query.

UPDATE: CAST This is the execution plan after CAST method applied.

+4
2

, , . SSMS , .

, , , . ( ) .

0

Between, , where >= and <, , , SQL- .

SELECT * FROM SOMETABLE WHERE RECORDTIMEOA >= 41667 AND RECORDTIMEOA < 41668

Turgay Sahtiyan, where , . : http://technet.microsoft.com/en-us/library/ms191530.aspx, .

0

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


All Articles