Showing posts with label slow. Show all posts
Showing posts with label slow. Show all posts

Monday, March 26, 2012

Help Fix Slow Query.

I have a query that is taking too long to run. It take 14 seconds to return 6800 rows. However, if I move the query out of a stored proc, it takes 1 second. I want to understand this issue and ideally fix the stored proc case.

I've simplified my actual queries for readability.

-- @.filter is value to filter against or NULL to return all records.
CREATE PROCEDURE queryPlayerStations(@.filter INTEGER)
AS
SELECT * FROM MyTable
-- Other joins and query logic omitted for brevity
WHERE ((@.filter IS NULL) OR (MyTable.Column = @.filter))
GO

DECLARE @.filter INTEGER
SET @.filter = NULL

-- Takes 14 seconds to return 6800 rows. That's unacceptable performance
EXEC dbo.queryPlayerStations @.filter

When I run the query directly in Query Analyzer, it runs very fast.

DECLARE @.filter INTEGER
SET @.filter = NULL

-- Takes ~1 second to return 6800 rows. That's great performance
SELECT * FROM MyTable
-- Other joins and query logic omitted for brevity
WHERE ((@.filter IS NULL) OR (MyTable.Column = @.filter))

When I put the parameters in the stored proc it runs fast.

CREATE PROCEDURE queryPlayerStations
AS
DECLARE @.filter INTEGER
SET @.filter = NULL

SELECT * FROM MyTable
-- Other joins and query logic omitted for brevity
WHERE ((@.filter IS NULL) OR (MyTable.Column = @.filter))
GO

-- Takes ~1 second to return 6800 rows. That's great performance
EXEC dbo.queryPlayerStations

Anyone have any ideas what I can do to improve the stored proc case?Just a quick *guess* before I leave office for tonight...

The optimization in SQL Server works differently depending
on where the parameter is defined (as a procedure call argument or inside using DECLARE). In one of the cases,
it doesn't have enough info to optimize in the best way.|||As Coolberg implied, what happens if you do this:

ALTER PROCEDURE queryPlayerStations(@.filterIN INTEGER)
AS
DECLARE @.filter INTEGER
SET @.filter = @.filterIN

SELECT * FROM MyTable
-- Other joins and query logic omitted for brevity
WHERE ((@.filter IS NULL) OR (MyTable.Column = @.filter))
GO

DECLARE @.filterIN INTEGER
SET @.filterIN = NULL
EXEC dbo.queryPlayerStations @.filterIN

Monday, March 12, 2012

HELP ! Suddenly, terribly slow SQLServer Enterprise Manager

Hi,
I am using SQLServer on my development laptop, and it's running without
any problems since at least 6 or 7 months. Suddenly, since yesterday,
when I start the Entreprise Manager, it takes absolute AGES (minutes,
with a very intensive disk activity) until it shows the console root,
and each click on a table takes again ages until the rows are shown.
Even paging takes now 10 times longer as before. My DB is very snmall,
something like 50,000 rows in total max. A double click on the table
icon of the largest table (20,000 rows) takes 2 MINUTES to complete ! A
click on the "Run" icon in the tool bar takes more than 10 seconds to
complete, to show 40-50 rows !
I have reorganized the DB, but that does not help at all for the
performance.
I noticed that the log file is 76 Megabytes whereas the DB after
shrinking is only 8 Meg. I have done a backup of the log file, but it is
only a ridicule 196 KBytes, and the live log is just as big as before !
The very strange thing is that, if I log as another user on my laptop,
then I have the normal speed in Enterprise Manager. How is that possible ?
What's going on ? Why suddenly, where I can't remember having done
anything special these last days. And more importantly, how do I get
back to the previous status, where everything was real quick ? I just
can't work properly anymore if every single click is taking minutes !!!
Thanks for help.
Bernard
Sound like someone has turned on ODBC tracing.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"bthouin" <bernard_thouin@.bluewin.com> wrote in message
news:%230mAl35kFHA.1416@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I am using SQLServer on my development laptop, and it's running without any problems since at
> least 6 or 7 months. Suddenly, since yesterday, when I start the Entreprise Manager, it takes
> absolute AGES (minutes, with a very intensive disk activity) until it shows the console root, and
> each click on a table takes again ages until the rows are shown. Even paging takes now 10 times
> longer as before. My DB is very snmall, something like 50,000 rows in total max. A double click on
> the table icon of the largest table (20,000 rows) takes 2 MINUTES to complete ! A click on the
> "Run" icon in the tool bar takes more than 10 seconds to complete, to show 40-50 rows !
> I have reorganized the DB, but that does not help at all for the performance.
> I noticed that the log file is 76 Megabytes whereas the DB after shrinking is only 8 Meg. I have
> done a backup of the log file, but it is only a ridicule 196 KBytes, and the live log is just as
> big as before !
> The very strange thing is that, if I log as another user on my laptop, then I have the normal
> speed in Enterprise Manager. How is that possible ?
> What's going on ? Why suddenly, where I can't remember having done anything special these last
> days. And more importantly, how do I get back to the previous status, where everything was real
> quick ? I just can't work properly anymore if every single click is taking minutes !!!
> Thanks for help.
> Bernard
|||THANK YOU ! I DID turn it on, and did not see any log at all coming up,
so I thought it had not worked and totally forgot about it !
Yes, now my Enterprise Manager is back to normal.
You made my day ! Sometimes, it's so simple...
Ah, what a relief it is...
And what about my <database>_Log.LDF file ? How do I get rid of/truncate
it ?
Regards, and thanks again.
Bernard
Tibor Karaszi wrote:
> Sound like someone has turned on ODBC tracing.
>
|||> And what about my <database>_Log.LDF file ? How do I get rid of/truncate it ?
The ldf file is a part of the database. You can't get rid of it. If you consider it being too large,
then you should read in Books Online about recovery model and decide whether or not you want to do
regular transaction log backups. If you have had the db in full recovery model and not been doing
regular transaction log backups and have a very large ldf file, you can shrink it using DBCC
SHRINKFILE. Also check out http://www.karaszi.com/SQLServer/info_dont_shrink.asp
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"bthouin" <bernard_thouin@.bluewin.com> wrote in message
news:OKNqi36kFHA.2472@.TK2MSFTNGP15.phx.gbl...[vbcol=seagreen]
> THANK YOU ! I DID turn it on, and did not see any log at all coming up, so I thought it had not
> worked and totally forgot about it !
> Yes, now my Enterprise Manager is back to normal.
> You made my day ! Sometimes, it's so simple...
> Ah, what a relief it is...
> And what about my <database>_Log.LDF file ? How do I get rid of/truncate it ?
> Regards, and thanks again.
> Bernard
>
> Tibor Karaszi wrote:

HELP ! Suddenly, terribly slow SQLServer Enterprise Manager

Hi,
I am using SQLServer on my development laptop, and it's running without
any problems since at least 6 or 7 months. Suddenly, since yesterday,
when I start the Entreprise Manager, it takes absolute AGES (minutes,
with a very intensive disk activity) until it shows the console root,
and each click on a table takes again ages until the rows are shown.
Even paging takes now 10 times longer as before. My DB is very snmall,
something like 50,000 rows in total max. A double click on the table
icon of the largest table (20,000 rows) takes 2 MINUTES to complete ! A
click on the "Run" icon in the tool bar takes more than 10 seconds to
complete, to show 40-50 rows !
I have reorganized the DB, but that does not help at all for the
performance.
I noticed that the log file is 76 Megabytes whereas the DB after
shrinking is only 8 Meg. I have done a backup of the log file, but it is
only a ridicule 196 KBytes, and the live log is just as big as before !
The very strange thing is that, if I log as another user on my laptop,
then I have the normal speed in Enterprise Manager. How is that possible ?
What's going on ? Why suddenly, where I can't remember having done
anything special these last days. And more importantly, how do I get
back to the previous status, where everything was real quick ? I just
can't work properly anymore if every single click is taking minutes !!!
Thanks for help.
BernardSound like someone has turned on ODBC tracing.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"bthouin" <bernard_thouin@.bluewin.com> wrote in message
news:%230mAl35kFHA.1416@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I am using SQLServer on my development laptop, and it's running without any problems since at
> least 6 or 7 months. Suddenly, since yesterday, when I start the Entreprise Manager, it takes
> absolute AGES (minutes, with a very intensive disk activity) until it shows the console root, and
> each click on a table takes again ages until the rows are shown. Even paging takes now 10 times
> longer as before. My DB is very snmall, something like 50,000 rows in total max. A double click on
> the table icon of the largest table (20,000 rows) takes 2 MINUTES to complete ! A click on the
> "Run" icon in the tool bar takes more than 10 seconds to complete, to show 40-50 rows !
> I have reorganized the DB, but that does not help at all for the performance.
> I noticed that the log file is 76 Megabytes whereas the DB after shrinking is only 8 Meg. I have
> done a backup of the log file, but it is only a ridicule 196 KBytes, and the live log is just as
> big as before !
> The very strange thing is that, if I log as another user on my laptop, then I have the normal
> speed in Enterprise Manager. How is that possible ?
> What's going on ? Why suddenly, where I can't remember having done anything special these last
> days. And more importantly, how do I get back to the previous status, where everything was real
> quick ? I just can't work properly anymore if every single click is taking minutes !!!
> Thanks for help.
> Bernard|||THANK YOU ! I DID turn it on, and did not see any log at all coming up,
so I thought it had not worked and totally forgot about it !
Yes, now my Enterprise Manager is back to normal.
You made my day ! Sometimes, it's so simple...
Ah, what a relief it is...
And what about my <database>_Log.LDF file ? How do I get rid of/truncate
it ?
Regards, and thanks again.
Bernard
Tibor Karaszi wrote:
> Sound like someone has turned on ODBC tracing.
>|||> And what about my <database>_Log.LDF file ? How do I get rid of/truncate it ?
The ldf file is a part of the database. You can't get rid of it. If you consider it being too large,
then you should read in Books Online about recovery model and decide whether or not you want to do
regular transaction log backups. If you have had the db in full recovery model and not been doing
regular transaction log backups and have a very large ldf file, you can shrink it using DBCC
SHRINKFILE. Also check out http://www.karaszi.com/SQLServer/info_dont_shrink.asp
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"bthouin" <bernard_thouin@.bluewin.com> wrote in message
news:OKNqi36kFHA.2472@.TK2MSFTNGP15.phx.gbl...
> THANK YOU ! I DID turn it on, and did not see any log at all coming up, so I thought it had not
> worked and totally forgot about it !
> Yes, now my Enterprise Manager is back to normal.
> You made my day ! Sometimes, it's so simple...
> Ah, what a relief it is...
> And what about my <database>_Log.LDF file ? How do I get rid of/truncate it ?
> Regards, and thanks again.
> Bernard
>
> Tibor Karaszi wrote:
>> Sound like someone has turned on ODBC tracing.

HELP ! Suddenly, terribly slow SQLServer Enterprise Manager

Hi,
I am using SQLServer on my development laptop, and it's running without
any problems since at least 6 or 7 months. Suddenly, since yesterday,
when I start the Entreprise Manager, it takes absolute AGES (minutes,
with a very intensive disk activity) until it shows the console root,
and each click on a table takes again ages until the rows are shown.
Even paging takes now 10 times longer as before. My DB is very snmall,
something like 50,000 rows in total max. A double click on the table
icon of the largest table (20,000 rows) takes 2 MINUTES to complete ! A
click on the "Run" icon in the tool bar takes more than 10 seconds to
complete, to show 40-50 rows !
I have reorganized the DB, but that does not help at all for the
performance.
I noticed that the log file is 76 Megabytes whereas the DB after
shrinking is only 8 Meg. I have done a backup of the log file, but it is
only a ridicule 196 KBytes, and the live log is just as big as before !
The very strange thing is that, if I log as another user on my laptop,
then I have the normal speed in Enterprise Manager. How is that possible ?
What's going on ? Why suddenly, where I can't remember having done
anything special these last days. And more importantly, how do I get
back to the previous status, where everything was real quick ? I just
can't work properly anymore if every single click is taking minutes !!!
Thanks for help.
BernardSound like someone has turned on ODBC tracing.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"bthouin" <bernard_thouin@.bluewin.com> wrote in message
news:%230mAl35kFHA.1416@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I am using SQLServer on my development laptop, and it's running without an
y problems since at
> least 6 or 7 months. Suddenly, since yesterday, when I start the Entrepris
e Manager, it takes
> absolute AGES (minutes, with a very intensive disk activity) until it show
s the console root, and
> each click on a table takes again ages until the rows are shown. Even pagi
ng takes now 10 times
> longer as before. My DB is very snmall, something like 50,000 rows in tota
l max. A double click on
> the table icon of the largest table (20,000 rows) takes 2 MINUTES to compl
ete ! A click on the
> "Run" icon in the tool bar takes more than 10 seconds to complete, to show
40-50 rows !
> I have reorganized the DB, but that does not help at all for the performan
ce.
> I noticed that the log file is 76 Megabytes whereas the DB after shrinking
is only 8 Meg. I have
> done a backup of the log file, but it is only a ridicule 196 KBytes, and t
he live log is just as
> big as before !
> The very strange thing is that, if I log as another user on my laptop, the
n I have the normal
> speed in Enterprise Manager. How is that possible ?
> What's going on ? Why suddenly, where I can't remember having done anythin
g special these last
> days. And more importantly, how do I get back to the previous status, wher
e everything was real
> quick ? I just can't work properly anymore if every single click is taking
minutes !!!
> Thanks for help.
> Bernard|||THANK YOU ! I DID turn it on, and did not see any log at all coming up,
so I thought it had not worked and totally forgot about it !
Yes, now my Enterprise Manager is back to normal.
You made my day ! Sometimes, it's so simple...
Ah, what a relief it is...
And what about my <database>_Log.LDF file ? How do I get rid of/truncate
it ?
Regards, and thanks again.
Bernard
Tibor Karaszi wrote:
> Sound like someone has turned on ODBC tracing.
>|||> And what about my <database>_Log.LDF file ? How do I get rid of/truncate i
t ?
The ldf file is a part of the database. You can't get rid of it. If you cons
ider it being too large,
then you should read in Books Online about recovery model and decide whether
or not you want to do
regular transaction log backups. If you have had the db in full recovery mod
el and not been doing
regular transaction log backups and have a very large ldf file, you can shri
nk it using DBCC
SHRINKFILE. Also check out http://www.karaszi.com/SQLServer/in...ver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"bthouin" <bernard_thouin@.bluewin.com> wrote in message
news:OKNqi36kFHA.2472@.TK2MSFTNGP15.phx.gbl...[vbcol=seagreen]
> THANK YOU ! I DID turn it on, and did not see any log at all coming up, so
I thought it had not
> worked and totally forgot about it !
> Yes, now my Enterprise Manager is back to normal.
> You made my day ! Sometimes, it's so simple...
> Ah, what a relief it is...
> And what about my <database>_Log.LDF file ? How do I get rid of/truncate i
t ?
> Regards, and thanks again.
> Bernard
>
> Tibor Karaszi wrote:

Friday, March 9, 2012

HELP - Slow Connection establishment on Windows XP

Hi All,

Just bought a new laptop, everything fine EXCEPT when a java program I have written tries to get a connection to an SQL server database. It gets the connection no problem but its about three times slower than on my desktop machine to the same server.

The laptop is running windows XP Home, and I am connecting to an SQL server database.

I have absolutely no IDEA why it takes three times longer on a machine which is 10 times faster than my desktop. My desktop is running windows NT.

Any hints would be most appreciated.

thanks.Those 56k modems can be a dog...

;-)

How are you connecting to sql server..can you show us the connection string?|||its ok, the problem was that I had to put the sql server machine in the hosts file in windows\system32\drivers\etc

i.e. 123.123.123.123 servername.

thanks anyway.