Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
wjerla
Starting Member
3 Posts |
Posted - 2007-11-23 : 03:32:33
|
Hello,I have a stored proc similar to this:CREATE PROCEDUE SearchDB@param intASBEGINSELECT col1, col2, col3FROM tb1 INNER JOIN tb2 ON tb1.col1 = tb2.otherColumnWHERE dbo.IsMatch(@param, tb1.col1)ENDThis runs fine in SQL Management Studio, and gives the expected results. But when I call the stored proc from an ASP.NET application, the query never completes - it times out.I know I'm connected to SQL Server, I can access other stored procs in the same database just fine. It is the dbo.IsMatch() user-defined function that is causing SQL Server to timeout -- if I replace the function with, say, 'WHERE tb2.col1 = 5' it works fine from .NET.Anyone have any ideas? I'm a little lost on this one. The really weird thing is that another stored proc that uses the dbo.IsMatch() function runs fine from .NET. |
|
wjerla
Starting Member
3 Posts |
Posted - 2007-11-23 : 03:34:19
|
Ooops, the actual WHERE clause I have isWHERE dbo.IsMatch(@param, tb1.col1) = 1 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2007-11-23 : 04:10:40
|
It sounds like SQL is unable to resolve the where clause. What is IsMatch() doing exactly? It look to me like it is just trying doing an = or Like for the @param againt the column you pass in.In the procedure that is working, is the function called in the where clause as well? |
|
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2007-11-23 : 12:00:05
|
I'm guessing you have much more data in the live ASP.NET environment and using a function like that will perform very badly with lots of data - badly enough that it times out in your case.In cases like that where the function is probably doing something pretty simple anyway, and you're query lots of data, just put the expression right in the query and it will probably run considerably faster.Also check your indexing, do you have an index on tb1.col1 (I don't know what the function does so I can't say for sure that you need one, but you probably do for the join anyway)? |
|
|
wjerla
Starting Member
3 Posts |
Posted - 2007-11-23 : 14:36:17
|
Thank you, snSQL, you were correct. The amount of data was much larger in this case, causing it to timeout. I rewrote the query without the function, which resulted in a larger 'WHERE' clause but the query runs many orders of magnitude faster now.Thanks!! |
|
|
|
|
|
|
|