June 21, 2015 at 10:48 pm
Comments posted to this topic are about the item The Case for Specifying Data Types and Query Performance
June 22, 2015 at 3:27 am
Good job, you clearly explained the problem and the solution. Also specifying correct types should be of much assistance improving query performance.
June 22, 2015 at 4:13 am
May I suggest showing an extra couple of screenshots of the query plans showing where to see the implicit conversion? It might add a little to the learning experience. 😀
June 22, 2015 at 6:42 am
Good to know.
I'd point out that if someone's application is calling the same query repeatedly in a tight loop you might have a design issue though. You likely need to examine batching it via using a table type parameter to a stored procedure or some other method since individual DB calls each have a certain amount of overhead.
June 22, 2015 at 7:00 am
Thanks Chad, this is exactly the sort of article I want read. It took me about 5mins to read and learnt a valuable lesson
June 22, 2015 at 9:37 am
Very good and clear article Chad. Thanks!
June 22, 2015 at 10:58 am
Great article Chad! I learned something new today.
-- Itzik Ben-Gan 2001
June 22, 2015 at 2:17 pm
Great article. Also a great take on some of the problems ORM can cause. It's one reason I'm not a LINQ-to-SQL fan. For anything but the simplest queries, you really need to work in SQL, get an efficient solution, then work back to your .Net program, probably using a stored procedure derived from your best SQL query.
Gerald Britton, Pluralsight courses
June 22, 2015 at 7:41 pm
I have enjoyed many great articles published to sqlservercentral.com. I am very happy to "pay it forward".
-Chad
June 22, 2015 at 7:45 pm
MarbryHardin (6/22/2015)
Good to know.I'd point out that if someone's application is calling the same query repeatedly in a tight loop you might have a design issue though. You likely need to examine batching it via using a table type parameter to a stored procedure or some other method since individual DB calls each have a certain amount of overhead.
Thank you for your feedback Marbry. Great point, I agree if the situation allows refactoring and making bulk calls, reduces chatter and contention.
-Chad Feghali
June 22, 2015 at 7:50 pm
RichB (6/22/2015)
May I suggest showing an extra couple of screenshots of the query plans showing where to see the implicit conversion? It might add a little to the learning experience. 😀
Thank you for your feedback Rich. Good call, I will add that screenshot when an opportunity comes up for editing the article.
-Chad Feghali
June 22, 2015 at 7:55 pm
I have enjoyed many great articles published to sqlservercentral.com. I am very happy to "pay it forward"!
Thank you all for the compliments!
-Chad Feghali
June 22, 2015 at 11:41 pm
I love this article mainly because I can pass it on to one of senior .NET developers and do not have to write up anything myself to demo for him 😀
I was just explaining this concept to him last week when asking if he declared his data types when adding items to the Parameters Collection and he confirmed he did not. Thanks for the clear and concise explanation of a very important topic!
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
June 23, 2015 at 7:34 am
Or of course you could just call a stored procedure and avoid this issue correct?
June 23, 2015 at 7:50 am
MarbryHardin (6/23/2015)
Or of course you could just call a stored procedure and avoid this issue correct?
Nope...the same issue persists with stored procedures but to a far, far, far lesser degree. Only the call into the proc interface would force an implicit type-conversion which is magnitudes better than using parameterized SQL as it would save the system from the scans shown in the article. It would look like this:
-- call from .NET [without] strong types used in the Parameters Collection
EXEC sys.sp_executesql
N'exec dbo.storedProcedure @accountNumber',
N'@accountNumber nvarchar(7)',
@accountNumber = N'R123456';
-- call from .NET [with] strong types used in the Parameters Collection
EXEC sys.sp_executesql
N'exec dbo.storedProcedure @accountNumber',
N'@accountNumber char(20)', --< correct type
@accountNumber = 'R123456';
For a high volume system you might take a cumulative hit from the first type of arrangement but on the average system, probably not enough to register a noticeable dip in performance.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
Viewing 15 posts - 1 through 15 (of 18 total)
You must be logged in to reply to this topic. Login to reply