PC Review


Reply
Thread Tools Rate Thread

Calling SQL from code has different behaviour than calling it from MS SQL Server Management Studio

 
 
jeeji
Guest
Posts: n/a
 
      29th Jun 2006
HI

I am experiencing something funny here where I have two equivalent
queries: If I run them through query analyzer, the first runs slower
than the second, but if run through C# application, the first runs
faster than the second.

I have the following two equivalent versions of a query which I will
present in psuedo code:

-------------------------
(1) Simple JOIN of two SELECT statements

SELECT Col1 FROM
(
SELECT table1.Col1 FROM table1 WHERE exp1
JOIN
SELECT table1.Col1 FROM table2 WHERE exp2
ON table1.Col1 = table2.Col1
)

-------------------------
(2) I create temporary tables, JOIN them and then DROP them.

-- Create Temp tables
SELECT table1.Col1
INTO #temp_table1
FROM table1 WHERE exp1

SELECT table1.Col1
INTO #temp_table2
FROM table2 WHERE exp2

-- JOIN the temp tables
SELECT Col1 FROM
(
#temp_table1
JOIN
#temp_table2
ON #temp_table1.Col1 = #temp_table2.Col1
)

-- DROP the tamp tables
DROP Table #temp_table1
DROP Table #temp_table2

-------------------------

If I run (1) from the query analyzer in MS SQL Server Management
Studio, it runs slower than (2). I clear the SQL server cache before
each call.

If I run (1) from the C# test application, it runs faster the (2) from
the same C# test app. I use .Net 2.0 using the System.Data.SqlClient
calls.

The way I can see the different in execution times is through the SQL
server profiler.

Can anybody explain that?
Any help would be much appreciated

Thank you in advance
Jeeji

 
Reply With Quote
 
 
 
 
jeeji
Guest
Posts: n/a
 
      29th Jun 2006
Hi again

I found out what was wrong. I did not clear the cache from the C# code,
which is obviously necessary .Sorry for the disturbance

Jeeji

jeeji skrev:

> HI
>
> I am experiencing something funny here where I have two equivalent
> queries: If I run them through query analyzer, the first runs slower
> than the second, but if run through C# application, the first runs
> faster than the second.
>
> I have the following two equivalent versions of a query which I will
> present in psuedo code:
>
> -------------------------
> (1) Simple JOIN of two SELECT statements
>
> SELECT Col1 FROM
> (
> SELECT table1.Col1 FROM table1 WHERE exp1
> JOIN
> SELECT table1.Col1 FROM table2 WHERE exp2
> ON table1.Col1 = table2.Col1
> )
>
> -------------------------
> (2) I create temporary tables, JOIN them and then DROP them.
>
> -- Create Temp tables
> SELECT table1.Col1
> INTO #temp_table1
> FROM table1 WHERE exp1
>
> SELECT table1.Col1
> INTO #temp_table2
> FROM table2 WHERE exp2
>
> -- JOIN the temp tables
> SELECT Col1 FROM
> (
> #temp_table1
> JOIN
> #temp_table2
> ON #temp_table1.Col1 = #temp_table2.Col1
> )
>
> -- DROP the tamp tables
> DROP Table #temp_table1
> DROP Table #temp_table2
>
> -------------------------
>
> If I run (1) from the query analyzer in MS SQL Server Management
> Studio, it runs slower than (2). I clear the SQL server cache before
> each call.
>
> If I run (1) from the C# test application, it runs faster the (2) from
> the same C# test app. I use .Net 2.0 using the System.Data.SqlClient
> calls.
>
> The way I can see the different in execution times is through the SQL
> server profiler.
>
> Can anybody explain that?
> Any help would be much appreciated
>
> Thank you in advance
> Jeeji


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling (something like a) Window.Alert from Server Side code Marc Microsoft ASP .NET 1 22nd Jul 2008 12:54 PM
Calling server side code from teh client... Jerry Camel Microsoft ASP .NET 5 27th Sep 2005 06:07 PM
Server Side button calling page_load before calling it's own click event. Ryan Ternier Microsoft ASP .NET 4 29th Jul 2004 02:06 PM
Calling opener's server code denull Microsoft ASP .NET 0 22nd Oct 2003 04:30 AM
Disabling a button but calling its server code Paul Microsoft ASP .NET 4 1st Aug 2003 08:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:24 PM.