Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Databases General > Re: reduce time...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 6 Topic 3109 of 3295
Post > Topic >>

Re: reduce time for search query

by Erland Sommarskog <esquel@[EMAIL PROTECTED] > Mar 8, 2008 at 07:49 PM

(jan.afzal@[EMAIL PROTECTED]
) writes:
> Sorry for not having to replied earlier.
>
> here is the code.
>
> this is the query that gets fired;

Most likely what is killing you is all the calls to
fnCommonFriendsStep. (But if the vw_search view is complex, the reason
may be found there.)

I see that Plamen has offered a rewrite where he
has turned the function into a table-valued function, but will I have
to admit that I am skeptical that this will have any particular effect.

If you are lucky that these conditions:

   WHERE  U.UserID IN (SELECT DISTINCT UserID FROM vw_search)
     AND  UP.PropertyDefinitionID = 29

filter away a major share of the rows, say 90%, it may be suffcient
to do:

   INSERT #temp(UserID, ....)
      SELECT U.UserID, U.FirstName + ' ' + U.LastName as Name,
             UP.PropertyValue as Location,
             pI.headline as Headline,
             i.industryName as Industry,
             pI.summary as Summary,
             pI.interests
      FROM   Users U
      JOIN   UserProfile ON U.UserID = UP.UserID
      JOIN   professionalInfo pI ON U.UserID = pI.memberId
      JOIN   industries i ON pI.primaryIndustry = i.industryId
      WHERE  U.UserID IN (SELECT DISTINCT UserID FROM vw_search)
      AND    UP.PropertyDefinitionID = 29

   SELECT UserID, Name, Location, Headline, Industry, Summary, interests,
          dbo.GetConnectionsCount(U.UserID) AS Connections,
          dbo.GetRecommendations(U.UserID) AS Recommendations,
          dbo.fnCommonFriendsStep(U.UserID, 36) AS Degree
   FROM   #temp
   WHERE  dbo.fnCommonFriendsStep(U.UserID, 36) >= 0

But if the call to dbo.fnCommonFriendsStep is the major filter, the above
is useless.

It is possible that you could replace the function with a recursive CTE.
No, I am not go to give you a sample, because I don't know your tables,
I don't know your business rules, and I don't have any sample data to
test with. And there are some unfortuate restrictions with recursive
CTEs which makes me uncertain that they can actually do the job.

If that does not help, the only remaining option is to materialise the
result of fnCommonFriendsStep to a table with the columns (User1, User2,
Degrees). How to maintain that table when a row is added, deleted or
update in the network table would be a new headache.

In summary, while we are some people out here that knows SQL Server well,
our expertise in the product as such is not sufficient to solve a
performance problem like this. We also need specific problem about
the problem at hand:

o  What is the purpose of this query? More generally what is the context
   for it?
o  How often does a query of this type run?
o  How common are updates? Partiularly, how common are updates to the
   network table?
o  CREATE VIEW for all views involved and CREATE TABLE and CREATE INDEX
   for the tables involved, including those referred to by views and
   function.
o  Rowcounts for all involved tables.
o  The query-plan for the query.
o  Sample data to test solutions for correctness. (To test for performance
   we would need more data that is practical to include a news post.)

Yes, it would take you some effort to compile this information, but
you are asking us to make a community to help you. If you are not
prepared to make that effort, should you really expect us to make any
effort?


--
Erland Sommarskog, SQL Server MVP, esquel@[EMAIL PROTECTED]
 Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
 




 6 Posts in Topic:
reduce time for search query
paankhate@[EMAIL PROTECTE  2008-02-26 04:41:24 
Re: reduce time for search query
Najm <najm25@[EMAIL PR  2008-02-27 10:59:09 
Re: reduce time for search query
"Plamen Ratchev"  2008-02-27 22:51:27 
Re: reduce time for search query
jan.afzal@[EMAIL PROTECTE  2008-03-05 02:18:20 
Re: reduce time for search query
"Plamen Ratchev"  2008-03-06 17:43:22 
Re: reduce time for search query
Erland Sommarskog <esq  2008-03-08 19:49:45 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Dec 5 9:56:23 CST 2008.