473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Time out

Please help!
We have a table which contains about 10,000,000 rows and has the
following structure:
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[TRANHEADERS](
[StoreNum] [varchar](20) NOT NULL,
[Location] [int] NOT NULL,
[TillID] [int] NOT NULL,
[TranID] [int] NOT NULL,
[DtStamp] [varchar](14) NOT NULL,
[StopTime] [varchar](14) NULL,
[Typet] [int] NULL,
[SubTypet] [int] NULL,
[Customer] [varchar](20) NULL,
[SecondaryCustomer] [varchar](20) NULL,
[HasHoldingTank] [tinyint] NULL
CONSTRAINT [PK_TRANHEADERS_1] PRIMARY KEY CLUSTERED
(
[StoreNum] ASC,
[Location] ASC,
[TillID] ASC,
[TranID] ASC,
[DtStamp] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY =
OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

And has an Index key for DtStamp:

CREATE NONCLUSTERED INDEX [Dates] ON [dbo].[TRANHEADERS]
(
[DtStamp] ASC,
[StoreNum] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB =
OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS
= ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

If we query the table using the following procedure we got time out message
in 3 minutes:
public DataSet LoadHoldingTankItems(string StartDate, string
EndDate, string StoreNum)
{
DataSet WorkDs;
DbCommand dbCommand;
StringBuilder strBuilder = new StringBuilder("");
strBuilder.Append(" set rowcount 1 ");
strBuilder.Append( " Select * from tranheaders with (noLock) where DtStamp
>= @StartDate And DtStamp <= @EndDate And hasholdingtank = 1 ");
if (string.Compare(StoreNum, "", true) != 0)
strBuilder.Append(" And StoreNum = @StoreNum");
strBuilder.Append(" set rowcount 0 ");
string sqlStr = strBuilder.ToString();
dbCommand = db.GetSqlStringCommand(sqlStr);
db.AddInParameter(dbCommand, "StartDate", DbType.String, StartDate);
db.AddInParameter(dbCommand, "EndDate", DbType.String, EndDate);
if (string.Compare(StoreNum, "", true) != 0)
db.AddInParameter(dbCommand, "StoreNum", DbType.String, StoreNum);

dbCommand = db.GetSqlStringCommand(sqlStr);
try
{

WorkDs = db.ExecuteDataSet(dbCommand);

}
catch (Exception ex)
{
StarLinkLibary.LogError("TranHeadersDataLayer", 0,
ex.ToString());
throw;
}
return WorkDs;
}

If we change the procedure to:
public DataSet LoadHoldingTankItems(string StartDate, string
EndDate, string StoreNum)
{
DataSet WorkDs;
DbCommand dbCommand;
//I don't know why the below query have problem with speed We
have to find out
//why before uncomment these section
/* StringBuilder strBuilder = new StringBuilder("");
strBuilder.Append(" set rowcount 1 go ");
strBuilder.Append( " Select * from tranheaders with (noLock)
where DtStamp >= @StartDate And DtStamp <= @EndDate And hasholdingtank = 1
");
if (string.Compare(StoreNum, "", true) != 0)
strBuilder.Append(" And StoreNum = @StoreNum");
strBuilder.Append(" set rowcount 0 go ");
string sqlStr = strBuilder.ToString();
dbCommand = db.GetSqlStringCommand(sqlStr);
db.AddInParameter(dbCommand, "StartDate", DbType.String,
StartDate);
db.AddInParameter(dbCommand, "EndDate", DbType.String, EndDate);
if (string.Compare(StoreNum, "", true) != 0)
db.AddInParameter(dbCommand, "StoreNum", DbType.String,
StoreNum);*/

string sqlStr = "set rowcount 1 ";
sqlStr = sqlStr + " Select * from tranheaders with (noLock)
where DtStamp >= '" + StartDate + "' ";
sqlStr = sqlStr + " And DtStamp <= '" + EndDate + "' And
hasholdingtank = 1 ";
if (string.Compare(StoreNum, "", true) != 0)
sqlStr = sqlStr + " And StoreNum = '" + StoreNum + "'";
sqlStr = sqlStr + " set rowcount 0";
dbCommand = db.GetSqlStringCommand(sqlStr);
try
{

WorkDs = db.ExecuteDataSet(dbCommand);

}
catch (Exception ex)
{
StarLinkLibary.LogError("TranHeadersDataLayer", 0,
ex.ToString());
throw;
}
return WorkDs;
}

The above procedure will return a data set in one second.
I can not see the different between 2 procedures any one run into the same
problem before please help.

Jul 15 '08 #1
4 1521
"Le Hung" <Le Hu**@discussions.microsoft.comwrote in message
news:14**********************************@microsof t.com...
[...]
The above procedure will return a data set in one second.
I can not see the different between 2 procedures any one run into the same
problem before please help.
The only difference that I see between both querys is that the "slow" one
is parameterized while the second one is not. The difference in speed could
be in Sql Server: The parameterized query is optimized once and then stored
in the procedure cache, so that every time you send the same query, even
though the values of the parameters are different, it follows the same
strategy. On the other hand, the non-parameterized version is optimized
every time, which will be a little less efficient, but will always choose
the best index according to the current index statistics.
If your database statistics are not up-to-date, or you first executed the
parameterized query with a set of parameters that happened to provide
optimal performance with a full scan (according to the existing statistics
at that time), the parameterized query might have been optimized for a full
clustered index scan.
I recommend that you UPDATE STATISTICS and then clear the procedure cache
(DBCC FREEPROCCACHE) so that your query will be recompiled.

By the way, your indexing strategy is probably suboptimal, at least for
this query: You have a very wide clustered index, which needs to be appended
to every other index, making those querys slower. You would probably benefit
from changing the primary key to non-clustered.

Jul 15 '08 #2
have you tried the query resulting in both cases?
I mean directly from sql enterprise manager and see the results?

also I remember seeing in MSDN magazine an article about how to detect
missing indices, expensive queriers, etc in a number this year, might
be worth to take a look into it
Jul 15 '08 #3


"Ignacio Machin ( .NET/ C# MVP )" wrote:
have you tried the query resulting in both cases?
I mean directly from sql enterprise manager and see the results?

also I remember seeing in MSDN magazine an article about how to detect
missing indices, expensive queriers, etc in a number this year, might
be worth to take a look into it
Thanks Ignacio:
Both work ok from SQL enterprise. When I removed Clustered Index as
Alberto suggested then both procedures work now(same response time). I am
not sure why the clustered index can slow down the query that much.
Thanks
Jul 15 '08 #4


"Alberto Poblacion" wrote:
"Le Hung" <Le Hu**@discussions.microsoft.comwrote in message
news:14**********************************@microsof t.com...
[...]
The above procedure will return a data set in one second.
I can not see the different between 2 procedures any one run into the same
problem before please help.

The only difference that I see between both querys is that the "slow" one
is parameterized while the second one is not. The difference in speed could
be in Sql Server: The parameterized query is optimized once and then stored
in the procedure cache, so that every time you send the same query, even
though the values of the parameters are different, it follows the same
strategy. On the other hand, the non-parameterized version is optimized
every time, which will be a little less efficient, but will always choose
the best index according to the current index statistics.
If your database statistics are not up-to-date, or you first executed the
parameterized query with a set of parameters that happened to provide
optimal performance with a full scan (according to the existing statistics
at that time), the parameterized query might have been optimized for a full
clustered index scan.
I recommend that you UPDATE STATISTICS and then clear the procedure cache
(DBCC FREEPROCCACHE) so that your query will be recompiled.

By the way, your indexing strategy is probably suboptimal, at least for
this query: You have a very wide clustered index, which needs to be appended
to every other index, making those querys slower. You would probably benefit
from changing the primary key to non-clustered.

Thanks Alberto,
I tried UPDATE STATISTICS and DBCC FREEPROCCACHE but the program still got
time out. When I drop the clustered index then the program works ok.

Thanks again

Le Hung
Jul 15 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Bart Nessux | last post by:
am I doing this wrong: print (time.time() / 60) / 60 #time.time has been running for many hours if time.time() was (21600/60) then that would equal 360/60 which would be 6, but I'm not getting...
5
by: David Stockwell | last post by:
I'm sure this has been asked before, but I wasn't able to find it. First off I know u can't change a tuple but if I wanted to increment a time tuple by one day what is the standard method to do...
6
by: David Graham | last post by:
Hi I have asked this question in alt.php as the time() function as used in setcookie belongs to php - or does it belong equally in the javascript camp - bit confused about that. Anyway, can anyone...
3
by: Szabolcs Nagy | last post by:
I have to measure the time of a while loop, but with time.clock i always get 0.0s, although python manual sais: "this is the function to use for benchmarking Python or timing algorithms" So i...
6
by: Rebecca Smith | last post by:
Today’s question involves two time text boxes each set to a different time zone. Initially txtCurrentTime will be set to Pacific Time or system time. This will change with system time as we travel...
3
by: luscus | last post by:
Thanks for all the responses on my first question. Unfortunately the answers I was given were too complicated for my small brain , and neophite condition to understand. So if you could talk down to...
3
by: cj | last post by:
If I want to check to see if it's after "11:36 pm" what would I write? I'm sure it's easy but I'm getting tired of having to work with dates and times. Sometimes I just want time or date. And...
1
by: davelist | last post by:
I'm guessing there is an easy way to do this but I keep going around in circles in the documentation. I have a time stamp that looks like this (corresponding to UTC time): start_time =...
2
by: Roseanne | last post by:
We are experiencing very slow response time in our web app. We run IIS 6 - windows 2003. I ran iisstate. Here's what I got. Any ideas?? Opened log file 'F:\iisstate\output\IISState-812.log'...
9
by: Ron Adam | last post by:
I'm having some cross platform issues with timing loops. It seems time.time is better for some computers/platforms and time.clock others, but it's not always clear which, so I came up with the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.