
user defined function question
[posted and mailed, please reply in news]
Quote:
> if i have a user defined function that simply returns a subset of a table
> (ie a simple query), will it still have access to the indexes on the
> original table?
> i would like to include the results of the function in a second query
> involving a join. so what i am also asking is whether or not that join
> is going to really struggle (because there is no index) or whether it is
> still an efficient option - if not then i must join to the original
> table instead.
I assume that your table is a table-valued function.
There is a distinct difference here between a multi-step function where
you return a table variable. This is equivalent that prior to the query
fill a temp table and then use that temp table in the query. (But the
table variable may be somewhat faster in this operation.)
On the other hand an inline function where you just say RETURN(SELECT-
statement) works a bit you like you ask for. That is, such a function
is basically a macro, and the query optimizer will consider the expanded
query as a whole.
--
Erland Sommarskog, SQL Server MVP
Books Online (updated!) for SQL 2000 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp