Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 1234»»»

Beware of Search Argument (SARG) Data Types Expand / Collapse
Author
Message
Posted Tuesday, June 27, 2006 1:17 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 8:16 AM
Points: 1,035, Visits: 410
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/dpeterson/bewareofsearchargumentsargdatatypes.asp


/*****************

If most people are not willing to see the difficulty, this is mainly because, consciously or unconsciously, they assume that it will be they who will settle these questions for the others, and because they are convinced of their own capacity to do this. -Friedrich August von Hayek



*****************/
Post #290539
Posted Thursday, July 13, 2006 4:58 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Thursday, August 28, 2014 12:47 AM
Points: 7,005, Visits: 8,451

add this one to "10 things i wish my developers knew about sql"

Make sure you use the datatype of your columns ! because you avoid your dbms to translate it for you (each and every time again and again)



Johan


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


"press F1 for solution", "press shift+F1 for urgent solution"


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me but most of the time this is me
Post #294028
Posted Thursday, July 13, 2006 6:00 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 7:55 AM
Points: 15,662, Visits: 28,055
Great article. Thanks for all the work. While I was aware that avoiding implicit converts resulted in better query plans, I didn't know about the data precedence. That's a great piece of information the next time (and there will be one) I have the same issue (read: argument) with a developer who can't seem to understand why the crazy dba's want you to explicitly declare the correct data types in stored procedures instead of using strings for everything (because, after all, strings are eaiser, aren't they? And SQL Server will just implicitly convert them, so I don't have to worry about data types...).

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #294033
Posted Thursday, July 13, 2006 6:04 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Thursday, August 28, 2014 12:47 AM
Points: 7,005, Visits: 8,451

btw precedence has been changed with sql2000 sp4

Let's hope they don't do that again



Johan


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


"press F1 for solution", "press shift+F1 for urgent solution"


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me but most of the time this is me
Post #294034
Posted Thursday, July 13, 2006 6:13 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, September 1, 2010 12:34 PM
Points: 7, Visits: 15
This was just the article I needed to print out roll up and beat my development team with! Thanks for the effort!

I am looking forward to your views concerning ORM and Hibernate. I am not a big fan either. Currently fighting with the dev group about how they are wanting to use it.
Post #294035
Posted Thursday, July 13, 2006 7:14 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, February 15, 2013 11:54 AM
Points: 4, Visits: 12

I have NEVER posted a reply to any article before.  But this one deserves some praise.

I'm a developer and constantly bugging my dba for ways to make my apps runs faster and jump higher.

He has probably already read this article, but I'm going to go sit and show him that developers can be taught if properly beaten...

Post #294063
Posted Thursday, July 13, 2006 7:22 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, July 18, 2014 1:48 AM
Points: 430, Visits: 312

Nice info to know. Fell foul of the conversion rules with SP4 when trying to use a variable devalred as Decimal(16,0) against a Primary key column defined as Decimal(12,0).

It managed to persuade SQL to do a table scan instead of an Index seek!

Post #294065
Posted Thursday, July 13, 2006 7:46 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Thursday, August 28, 2014 12:47 AM
Points: 7,005, Visits: 8,451
And probably INTEGER would be mutch faster   and preferable because you have precision 0.

Johan


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


"press F1 for solution", "press shift+F1 for urgent solution"


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me but most of the time this is me
Post #294078
Posted Thursday, July 13, 2006 8:53 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, October 4, 2012 11:13 AM
Points: 257, Visits: 80

Excellent.

I will even forward a link to this to the folks at Learning tree who developed their high performance DB course, and while they covered SARGs, they did not cover anything like this.

Thanks again.

Post #294131
Posted Thursday, July 13, 2006 9:25 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Saturday, October 12, 2013 10:42 PM
Points: 263, Visits: 297

Good article, but I disagree with the DATEDIFF/DATEADD statement "The first query can't possibly use an index and performs the DATEDIFF on every row in the table." used on the DateOfBirth example.

I believe this is because of the "select *", and not because of the DateDiff/DateAdd differences. (Also as a side note, both return a different amount of rows in my testing so I'd say they are not interchangeable). If you reduce the number of fields needed (maybe down to just CustomerID ) and they are also in an index ( DateOfBirth, CustomerID ), then that index can be used in both types of queries.

Post #294140
« Prev Topic | Next Topic »

Add to briefcase 1234»»»

Permissions Expand / Collapse