Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Join of Function or Join of View, which one is cost effective?


Join of Function or Join of View, which one is cost effective?

Author
Message
Paresh MD
Paresh MD
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 25
Hi,

I have a table "Table1" on which I want to apply a join. I have two options.

Option1: Create a multitable join view "View1" which will consist of union query as well along with a cross join. Apply join of "View1" on "Table1" to fetch the records.

Option2: Create a Function "Function1" which will do some processing and return data in a Table variable. Apply join of this table on "Table1" to fetch the records.

which one will be performance efficient in terms of time taken and memory utilisation.

Thanks.
HanShi
HanShi
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3042 Visits: 3625
This is hard to tell because your description is too vague.
You could build both solutions, set the statistics on (set statistics time on; set statistics io on;
) and execute both solutions. Also look at the execution plans. The output of the statistics and the execution plan will give you information to choose the best option.

** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
ChrisM@Work
ChrisM@Work
SSCrazy Eights
SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)

Group: General Forum Members
Points: 8941 Visits: 19009
Why restrict yourself to a view or a function? Why not just write the query?

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Erland Sommarskog
Erland Sommarskog
SSC Eights!
SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)

Group: General Forum Members
Points: 931 Visits: 866
A two-word answer is: it depends.

That said, generally, using a multi-statement table valued function lowers your odds for good performance, because the optimizer has no clue about how many rows that function will return, so if this solution is more efficient, it's a bit of luck.

On the other hand, if you replace the function with an INSERT into a temp table and then use that table in the query, this may be winner, because the temp table has statistics and may help with the next phase. Then again, the temp table means overhead.

A view is just macro and the only effect of the view is that it makes the query easier to read. Or more difficult.

Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Paresh MD
Paresh MD
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 25
Thanks Erland, I will use View based approach.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search