Home All Groups Group Topic Archive Search About

how do I test the cost of udf?

Author
7 Sep 2006 3:23 PM
Justin
I am currently doing performance tuning, in particular, query tuning.

Before I used a user defined function to get the result set.  The new query
now uses "set-based" approach to get the result set.  I am pretty sure the
newer version is a lot more efficient.  Since the new query has more joins
to get the desired result, when I run the "Display estimated execution plan"
to compare, the estimated cost is higher than the query that uses user
defined function since the cost of user defined function was not taken into
account.

So how do I test quantatively to see the newer version is more efficient?
Thanks

Author
7 Sep 2006 3:29 PM
Tibor Karaszi
I prefer to use Profiler to catch reads, CPU etc. Profiler does not exclude UDF work.

Show quote
"Justin" <nospam@nospam.com> wrote in message news:eQDBLGp0GHA.4920@TK2MSFTNGP06.phx.gbl...
>I am currently doing performance tuning, in particular, query tuning.
>
> Before I used a user defined function to get the result set.  The new query now uses "set-based"
> approach to get the result set.  I am pretty sure the newer version is a lot more efficient.
> Since the new query has more joins to get the desired result, when I run the "Display estimated
> execution plan" to compare, the estimated cost is higher than the query that uses user defined
> function since the cost of user defined function was not taken into account.
>
> So how do I test quantatively to see the newer version is more efficient?
> Thanks
>
Author
7 Sep 2006 3:34 PM
David Browne
<DIV>&quot;Justin&quot; &lt;nospam@nospam.com&gt; wrote in message
news:eQDBLGp0GHA.4920@TK2MSFTNGP06.phx.gbl...</DIV>>I am currently doing
performance tuning, in particular, query tuning.
>
> Before I used a user defined function to get the result set.  The new
> query now uses "set-based" approach to get the result set.  I am pretty
> sure the newer version is a lot more efficient.  Since the new query has
> more joins to get the desired result, when I run the "Display estimated
> execution plan" to compare, the estimated cost is higher than the query
> that uses user defined function since the cost of user defined function
> was not taken into account.
>
> So how do I test quantatively to see the newer version is more efficient?
> Thanks
>

SET STATISTICS IO ON
SET STATISTICS TIME ON

And compare the Logical Reads and CPU time.

David
Author
7 Sep 2006 3:50 PM
Justin
When you run the profile or SET STATISTICS IO ON, SET STATISTICS TIME ON, do
you need to clear buffer every time?  I would think so but just want to make
sure

Thanks all!

Show quote
"David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
message news:uqiQaMp0GHA.2356@TK2MSFTNGP03.phx.gbl...
>
>
> <DIV>&quot;Justin&quot; &lt;nospam@nospam.com&gt; wrote in message
> news:eQDBLGp0GHA.4920@TK2MSFTNGP06.phx.gbl...</DIV>>I am currently doing
> performance tuning, in particular, query tuning.
>>
>> Before I used a user defined function to get the result set.  The new
>> query now uses "set-based" approach to get the result set.  I am pretty
>> sure the newer version is a lot more efficient.  Since the new query has
>> more joins to get the desired result, when I run the "Display estimated
>> execution plan" to compare, the estimated cost is higher than the query
>> that uses user defined function since the cost of user defined function
>> was not taken into account.
>>
>> So how do I test quantatively to see the newer version is more efficient?
>> Thanks
>>
>
> SET STATISTICS IO ON
> SET STATISTICS TIME ON
>
> And compare the Logical Reads and CPU time.
>
> David
Author
7 Sep 2006 4:00 PM
David Browne
<DIV>&quot;Justin&quot; &lt;nospam@nospam.com&gt; wrote in message
news:OjZpJVp0GHA.1548@TK2MSFTNGP02.phx.gbl...</DIV>> When you run the
profile or SET STATISTICS IO ON, SET STATISTICS TIME ON, do
> you need to clear buffer every time?  I would think so but just want to
> make sure
>

No.  Absolutely do not clear the buffer cache or the procedure cache.  And
you might need to run it a couple of times to warm up the caches.

You should generally assume that your data will be cached, and tune on that
basis.  For a number of reasons, it's a much more valid assumption than
assuming that your data will not be cached.

David
Author
7 Sep 2006 3:37 PM
Jim Underwood
The cost shown in the execution plans is a good guidline for tuning, but not
100%.

Memory, IO, and CPU requirements are all taken into account when determining
the cost, and thus the execution plan.  Two queries with different plans but
the same cost will not necessarily perform equally.  The available memory,
IO speed, CPU speed and number of processors are all variables that won't be
reflected in the cost.  A memory intensive plan may have twice the cost of
an IO intensive plan, but still run in half the time if you have enough
memory to support it.

Even if you get an estimated plan that takes into account your UDF, the
actual numbers are not as useful as testing and benchmarking the performance
of each option.

Show quote
"Justin" <nospam@nospam.com> wrote in message
news:eQDBLGp0GHA.4920@TK2MSFTNGP06.phx.gbl...
> I am currently doing performance tuning, in particular, query tuning.
>
> Before I used a user defined function to get the result set.  The new
query
> now uses "set-based" approach to get the result set.  I am pretty sure the
> newer version is a lot more efficient.  Since the new query has more joins
> to get the desired result, when I run the "Display estimated execution
plan"
> to compare, the estimated cost is higher than the query that uses user
> defined function since the cost of user defined function was not taken
into
> account.
>
> So how do I test quantatively to see the newer version is more efficient?
> Thanks
>
>

AddThis Social Bookmark Button