April 20, 2010 at 8:26 am
David Walker-278941 (4/19/2010)
This article, like many discussions of Cross Apply and Outer Apply, says "APPLY is named after the process of applying a set of input rows to a table-valued function."It then backtracks a little and says that you don't have to use a table-valued function. Still, I think it's a disservice that many examples leave you with the impression that the only use for Apply is with functions.
I often use an expression on the right side of the Apply operator. I wish there were more examples like this.
The right side of the expression can be a correlated subquery, for example, and that can be very useful.
Can you share some examples of other ways to use APPLY. I would definitely like to learn some other techniques. Thanks.
April 20, 2010 at 5:21 pm
Carla Wilson-484785 (4/20/2010)
Can you share some examples of other ways to use APPLY. I would definitely like to learn some other techniques. Thanks.
Take a look in the download files for both parts, and be sure to read part 2 of the article as well.
May 7, 2010 at 12:22 am
I haven't got around to read the 2nd part of the article completely. I did have a glance. I just want to thank you again as what i learned here helped me to optimize a query by a great margin. You Rock! 🙂
-arjun
https://sqlroadie.com/
December 15, 2010 at 7:05 am
Just wanted to express my thanks for putting this article together! You got the concept of CROSS APPLY across perfectly. I'm grateful to all you DBA/DEV boddhisattvas out there sharing the knowledge! 🙂
Doodles
December 15, 2010 at 8:28 am
Thanks, Doodles 🙂
December 21, 2010 at 12:02 am
choice names for the students
chur!
December 21, 2010 at 12:34 am
rob mcnicol (12/21/2010)
choice names for the studentschur!
Best comment so far! :laugh:
October 18, 2011 at 9:58 am
Great article (although I am a little late getting to read it)!
A question that I have is... Is there a performance reason to use or not use a TVF (by this I mean one that uses CREATE FUNCTION versus a correlated subquery). I can see business cases for both as well as personal preference, but I was curious about performance.
Also, you spoke briefly about multi-statement functions, but I am still not 100% clear on this. Does this mean a function that uses CREATE FUNCTION that contains multiple statements in it?
Just trying to find out more of an answer about "functions" here versus the subquery route.
Thanks,
Jared
Jared
CE - Microsoft
October 18, 2011 at 11:39 am
jared-709193 (10/18/2011)
A question that I have is... Is there a performance reason to use or not use a TVF (by this I mean one that uses CREATE FUNCTION versus a correlated subquery). I can see business cases for both as well as personal preference, but I was curious about performance.
Hi Jared,
In-line TVFs are like (parameterized) views in that the definition of the function is expanded into the query text before optimization. A query that uses an in-line TVF will be optimized the same as if you wrote the function text out by hand as a subquery.
Also, you spoke briefly about multi-statement functions, but I am still not 100% clear on this. Does this mean a function that uses CREATE FUNCTION that contains multiple statements in it?
There's quite a lot of good information about functions in Books Online, for example: Types of Functions (link)
A multi-statement TVF definition contains the keywords BEGIN and END (as do scalar user-defined functions) and more than one statement. In-line TVFs use the RETURNS TABLE syntax to introduce a single SELECT. In-line functions do not use the BEGIN/END combination.
Multi-statement functions (and their scalar relations) are often, though not always, a performance drag for many reasons. One reason is that only in-line TVFs are expanded into the parent query for optimization. Scalar UDFs can be especially troublesome because they are executed once per row, in a new T-SQL context, and cannot use parallelism.
October 18, 2011 at 11:42 am
SQL Kiwi (10/18/2011)
jared-709193 (10/18/2011)
A question that I have is... Is there a performance reason to use or not use a TVF (by this I mean one that uses CREATE FUNCTION versus a correlated subquery). I can see business cases for both as well as personal preference, but I was curious about performance.Hi Jared,
In-line TVFs are like (parameterized) views in that the definition of the function is expanded into the query text before optimization. A query that uses an in-line TVF will be optimized the same as if you wrote the function text out by hand as a subquery.
Also, you spoke briefly about multi-statement functions, but I am still not 100% clear on this. Does this mean a function that uses CREATE FUNCTION that contains multiple statements in it?
There's quite a lot of good information about functions in Books Online, for example: Types of Functions (link)
A multi-statement TVF definition contains the keywords BEGIN and END (as do scalar user-defined functions) and more than one statement. In-line TVFs use the RETURNS TABLE syntax to introduce a single SELECT. In-line functions do not use the BEGIN/END combination.
Multi-statement functions (and their scalar relations) are often, though not always, a performance drag for many reasons. One reason is that only in-line TVFs are expanded into the parent query for optimization. Scalar UDFs can be especially troublesome because they are executed once per row, in a new T-SQL context, and cannot use parallelism.
Great! Thanks for the quick response Paul.
Jared
Jared
CE - Microsoft
December 1, 2011 at 2:02 am
This is very good Paul.
Concise and Clear, not too long and with easily understandable examples.
Thanks for taking the time to create this article. I appreciate your efforts.
10 minutes learning something new in the morning is a great way to start my day.
December 1, 2011 at 5:01 am
Thanks, Tom.
January 6, 2012 at 4:11 am
Just a trivial remark: right at the start it says
APPLY is named after the process of applying a set of input rows to a table-valued function.
Surely you mean to say applying a table-valued function to a set of input rows.
January 6, 2012 at 7:27 am
Really Nice article ..looking forward for more...
good luck..
January 6, 2012 at 11:03 am
reinpost (1/6/2012)
Just a trivial remark: right at the start it saysAPPLY is named after the process of applying a set of input rows to a table-valued function.
Surely you mean to say applying a table-valued function to a set of input rows.
I think it makes sense either way! 😎
Viewing 15 posts - 61 through 75 (of 89 total)
You must be logged in to reply to this topic. Login to reply