Showing posts with label therei. Show all posts
Showing posts with label therei. Show all posts

Wednesday, March 7, 2012

function executed as part of a stored procedure?

Hi there!

I've a stored procedure who gets a lot of data sets (50.000 - 200.000). For each of this data set i've to make further (recursiv) calculations what i do in an user defined function. The problem is that the functions needs to make a heavy query (everytime the same) and calculates something based on this query resultset. But the query requieres ~ 600ms, what results in a great amount of time (i.e. 6 hours)by executing this function 50.000 or more times.

I am wondering if it is possible to create the function as part of the stored procedure, so that the heavy query is beeing executed only one time and the function run in the scope of the stored procedure.

Is there any idea?

Cheers, Torsten

Torsten:

What exactly are you meaning by 50,000 - 200,000 result sets? Do you mean records or do you mean 50,000 -200,000 multi-record datasets? To me it sounds like you are talking about a record-based process instead of a set-based process.

If so, then yes, you should by all means convert the stored procedure to a set-based process and call your function only one time.

It would help if you could provide the main part of the process you are doing and important elements of your data schema.

|||

Hi Kent!

My procedure makes something like

select a,b,c,d,e,f,dbo.fct_my_funktion(a,b,c,d,e,f) amount from somewhere. This are > 50.000 sets, so the function is called > 50.000 times.

The function dbo.fct_my_funktion makes something like that:

Insert into a table var (...) (Select <a hierarchy left outer join to somethiong> from x,y.) <<<- That is the bottleneck

Aggregate recursiv on the table var <<<- That is very fast (3 to 20 ms, that quiet okay)

return the amount

Torsten

|||

Torsten:

A few things. First, you have done a good job of identifying your bottleneck. If this insert statement is taking about 600 ms per iteration then yes, this is what is killing you. Therefore, it would be good if you could give details that relate to this particular insert statement. Also, is it possible for you to run of the SELECT statements for that INSERT in isolation and get the QUERY PLAN for that particular SELECT.

Also, a couple of other issues. Are you running SQL Server 2005? A secondary issue here is that you are using a SCALAR function. It would be best if we could retrieve this information by some other means because scalar functions tend to be inefficient.

But FIRST: we need to look at the SELECT that statement.

|||

I did it!

I'm running SQL Server 2005. The solution ist to create a cursor (over the very heavy query - is only executed once) and then calculate the staff for each row in the cursor loop. So i dont need to use another function - i have gone from ~ 600ms per row to 13-17ms. That's quite good.

Thank you for your comments, may be it has openend my mind...

Greetings from germany,

Torsten

Sunday, February 26, 2012

Full-Text Search stops working

Hi There
I have a single server with Win 2000 Server and SQL 2000 SP3a.
I have a database with 1 full-text index, and everything works fine.....
BUT!!
Suddenly the search stops working. There are no errors in the eventlog and
all services are running fine.
The only way I can start the search, is to reboot the server !!
Whats wrong !?!?
/Peter
are there any messages in the gatherer logs?
"Microsoft" <pemaz@.wmdata.dk> wrote in message
news:%23hGeHL7TFHA.2124@.TK2MSFTNGP14.phx.gbl...
> Hi There
> I have a single server with Win 2000 Server and SQL 2000 SP3a.
> I have a database with 1 full-text index, and everything works fine.....
> BUT!!
> Suddenly the search stops working. There are no errors in the eventlog and
> all services are running fine.
> The only way I can start the search, is to reboot the server !!
> Whats wrong !?!?
> /Peter
>
|||No, there are no errors in the gatherer logs.
The index is only populated once.
/Peter
Hilary Cotter wrote:

> 220 0 article <uItFbR#TFHA.2664@.TK2MSFTNGP15.phx.gbl>
> From: "Hilary Cotter" <hilary.cotter@.gmail.com>
> References: <#hGeHL7TFHA.2124@.TK2MSFTNGP14.phx.gbl>
> Subject: Re: Full-Text Search stops working
> Date: Tue, 3 May 2005 09:28:58 -0400
> Lines: 23
> X-Priority: 3
> X-MSMail-Priority: Normal
> X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
> X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
> X-RFC2646: Format=Flowed; Original
> Message-ID: <uItFbR#TFHA.2664@.TK2MSFTNGP15.phx.gbl>
> Newsgroups: microsoft.public.sqlserver.fulltext
> NNTP-Posting-Host: ool-4353c4df.dyn.optonline.net 67.83.196.223
> Path: TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
> Xref: TK2MSFTNGP08.phx.gbl microsoft.public.sqlserver.fulltext:14771
>
> are there any messages in the gatherer logs?
> "Microsoft" <pemaz@.wmdata.dk> wrote in message
> news:%23hGeHL7TFHA.2124@.TK2MSFTNGP14.phx.gbl...
>
|||I have checked the gather logs and theres nothing "fishy"
5/3/2005 9:22:16 AM Add The gatherer has started
5/3/2005 9:22:18 AM Add The initialization has completed
5/3/2005 12:40:48 PM Add The gatherer has started
5/3/2005 12:40:50 PM Add The initialization has completed
5/3/2005 1:13:10 PM Add The gatherer has started
5/3/2005 1:13:12 PM Add The initialization has completed
Peter Mazzarella wrote:

> No, there are no errors in the gatherer logs.
> The index is only populated once.
> /Peter
>
>
>
>
>
> Hilary Cotter wrote:
>
|||What happens if you stop and start MSSearch after your search functionality
stops?
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Peter Mazzarella" <pemaz@.wmdata.dk> wrote in message
news:uB2oNUJUFHA.1040@.TK2MSFTNGP10.phx.gbl...
> No, there are no errors in the gatherer logs.
> The index is only populated once.
> /Peter
>
>
>
>
>
> Hilary Cotter wrote:
>