|
Hi I have a stored procedure which queries in 5 secs. Recently i have added a UDF in select select col1,col2,col3,UDF_function(col1),col4 from table inner join table 1 ..........11 tables are joined here. after adding udf_function() my query execution time is taking minimum 15 mins which is horrible. Kindly help me to how to improve the performance. the function returns the values of a column as comma seperated string. it means i am looping through the records in the function. The reason why i am using UDF is becos of the below table structure and requirement Table1 p.k col1 col2 col3 1 x z 2 v q 3 n w 4 m e Table2 f.k 1 a 1 b 1 c 2 a 2 d Output col1 col2 1 a,b,c 2 a,d 3 4 This is mainly to avoid duplicates Thanks in advance Usha
(comments are locked)
|
|
You could try creating an indexed view based off the UDF for pre-aggregation. Go to BOL and search on Creating Indexed Views Based on your new information I would say you could create an indexed view utilizing the UDF for every table. The views would basically be
You would then have persisted data and could join this into your query. Assuming the views created column one as the FK and column two as the comma separated list you could do something similar to the following: Thank u. The example you have given is very clear. Now my query execution is taking 3 mins for 270 records which is better when compared to 15 mins .
Nov 05 '09 at 02:59 AM
Usha
(comments are locked)
|
|
I suspect your problem is that you're falling into Jeff Moden's RBAR (Row By Agonising Row). What you're attempting to do should be possible with an appropriate aggregate.
(comments are locked)
|
|
You probably want to read this blog post http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx It is all about how to return grouped strings. There is an attached file which contains the winning scripts. Look at them to see what can be done with this matter. //Peso You're only linking to that because you won! ;)
Nov 03 '09 at 09:44 AM
Melvyn Harbour 1 ♦♦
(comments are locked)
|
|
Also, bear in mind that calling any sort of scalar UDF on a row-by-row basis can dramatically reduce performance.
(comments are locked)
|
|
Im not clear behind your reasons for doing this. You say "This is mainly to avoid duplicates" surely, is that you want the distinct characters in the columns ? Please provide a better example , as SQL script would be perfect I have a table1 and table2. table2 is child of table1 and one row od table1 has many rows in table2. when joining i am havind duplicates of table1 in the result. as i need only 1 col of table2 i want all the values for table.id to be shown as comma seperated string. hope am clear with the requirement.
Nov 04 '09 at 06:03 AM
Usha
(comments are locked)
|
1 2 next page »


Can you provide us with some more details please (table strucutre, sample data)?