Re: Queries Occasionally Slowing Down
- From: bob laughland <peter.mcclymont@xxxxxxxxx>
- Date: Wed, 19 Nov 2008 22:38:40 -0800 (PST)
On Nov 20, 7:35 pm, bob laughland <peter.mcclym...@xxxxxxxxx> wrote:
On Nov 19, 10:01 am, Erland Sommarskog <esq...@xxxxxxxxxxxxx> wrote:
bob laughland (peter.mcclym...@xxxxxxxxx) writes:
select * from DataStore where dataStoreName = 'name' and rowid in
(select RowId from DataStore where dataStoreName ='name' and name =
'keyname' and value = 'keyvalue') order by rowid
Are those 'name' etc, literals expanded into the query, or are they
parameters?
I ran the profiler to see what I could see and I found something
interesting. The profiler has a number of columns per SQL statement
that is run, CPU, Reads, Writes, Duration.
For the queries that are running fine the stats are like this
CPU - between 0 and 16
Reads - between 20 and 70
Writes - 0
Duration - between 2000 and 60000
But for one of the queries I caught which is running very slow the
stats were this,
CPU - 2574
Reads - 8944
Writes - 24
Duration - 9243528
Are there updates to this table? To me it looks like there are autostats
kicking in, and that would explain increase in reads and duration.
When you ran profiler, did you include StmtCompleted in the events? If you
do, I would expect that you will see a number of "SELECT statman". Those
come from autostats. You can also include Recompile events in the trace..
(There is both SP:Recompile and SQL:StmtRecompile.)
--
Erland Sommarskog, SQL Server MVP, esq...@xxxxxxxxxxxxx
Links for SQL Server Books Online:
SQL 2008:http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005:http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000:http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Thanks for those suggestions.
You mentioned sp_who. That is not really a viable option here because
I have no way to know when the slow query will kick in. Is there any
other way to check the locking?
Someone asked whether the strings were literals or parameters.
Initially they were literals, but I changed it to parameters because I
have a basic understanding as to what difference that can make. It
didn't help overall, but was a good thing to add in anyway.
When I ran profiler I just used the default settings. So I will look
into your suggestion of autostats (it will have to wait till
tomorrow). It does make some sense but perhaps does not suggest why
the same query is affected. As I say I will check this anyway.
Another point asked was whether there were inserts done on this table.
There are a lot of inserts done, using bulk insert. But the parts of
the software which are running the queries are in a single thread, so
the SQL will be sequential. Perhaps an insert like that locks longer
than the time period the software sees as the time to run the bulk
insert?
Thanks.
After giving it another read I think I misunderstood your suggestion
of whether there are lots of inserts. You are saying that lots of
inserts can affect the autostats rather then it affecting locking.
There are stacks of inserts into the table overall.
.
- References:
- Queries Occasionally Slowing Down
- From: bob laughland
- Re: Queries Occasionally Slowing Down
- From: Erland Sommarskog
- Re: Queries Occasionally Slowing Down
- From: bob laughland
- Queries Occasionally Slowing Down
- Prev by Date: Re: Queries Occasionally Slowing Down
- Next by Date: Re: Queries Occasionally Slowing Down
- Previous by thread: Re: Queries Occasionally Slowing Down
- Next by thread: Re: Queries Occasionally Slowing Down
- Index(es):
Relevant Pages
|
Loading