473,398 Members | 2,380 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,398 software developers and data experts.

Update Takes Long Time to Complete!?

Hi There,

I have an update statement to update a field of a table (~15,000,000
records). It took me around 3 hours to finish 2 weeks ago. After that
no one touched the server and no configuration changed. Until
yesterday, I re-ran it again and it took me more than 18hrs and still
not yet finished!!!

What's wrong with it? I can ran it successfully before. I have tried
two times but the result was still the same.

My SQL statement is:

update [all_sales] a
set a.accounting_month = b.accounting_month
from date_map b
where a.sales_date >= b.start_date and a.sales_date < b.end_date;

An index on [all_sales].sales_date is built successfully.
A composite index on ([date_map].start_date, [date_map].end_date) is
built successfully.

My server config is:

SQL Server 2000 with Service Pack 3
Windows 2000 with Service Pack 4
DELL PowerEdge 6650 Server
DUAL XEON 1900MHz Processors
2G RAM
2G Page File on Drive C
2G Page File on Drive D
DELL Diagnostics on all SCSI harddisks were all PASSED.

Any experts could simly give me a help????

Thanks x 1,000,000,000
Jul 20 '05 #1
4 18148
Where is your clustered index? It might help to have it on sales date
(in this scenario, don't know if it fits the business use)

First of all make sure your statistics are up to date, you also want to
make sure the tables are not fragmented by reindexing if needed. (in
case you don't know, rebuilding the clustered index alone will
automatically rebuild all non-clustered indexes on that table)

I would try changing that composite index to two different non-clustered
indexes as the composite index could not be used in the second part of
your where condition. When you have an index on columns (a,b) you can
use the index when you say "where a = N" but the index will not be used
when you say "where b = N"

HTH

Ray Higdon MCSE, MCDBA, CCNA

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #2
[posted and mailed, please reply in news]

Karaoke Prince (ka************@hotmail.com) writes:
I have an update statement to update a field of a table (~15,000,000
records). It took me around 3 hours to finish 2 weeks ago. After that
no one touched the server and no configuration changed. Until
yesterday, I re-ran it again and it took me more than 18hrs and still
not yet finished!!!
The first thing to check for is blocking. It might simply be that
some other process is holding a lock on the [all sales] table, preventing
you from continue. Use sp_who to check this. If you see a non-zero value
in the Blk column, this spid is blocking the spid on this line.

The second thing to check for is triggers. A trigger on a 15-million-
row table could be fatal.

Not that these are the most likely reasons, but they are easy to check.
What's wrong with it? I can ran it successfully before. I have tried
two times but the result was still the same.

My SQL statement is:

update [all_sales] a
set a.accounting_month = b.accounting_month
from date_map b
where a.sales_date >= b.start_date and a.sales_date < b.end_date;


If that is your SQL, you are not running SQL Server, but some other
product. When I run the above, I get a syntax error:

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'a'.

In lieu of other information, I have to assume that the real query is

update [all_sales]
set accounting_month = b.accounting_month
from [all sales] a, date_map b
where a.sales_date >= b.start_date and a.sales_date < b.end_date;

I would recommend that you add this condition to this query:

and a.accounting_month <> b.accounting_month

This may or may not improve the query plan, but at least it reduces
the number of rows. (Since you ran this statement a couple of
months ago, I guess that most rows already have the correct
accounting_month.)

Note that the query is such that SQL Server will have to read all rows
in the table. (I assume that all values of [all sales].sales_date
are covered by date_map.)

If there were clustered indexes on a.sales_date and b.start_date,
SQL Server could use a merge join. But this would only give a minor
improvement over the case where there are no indexes at all, in
which case I would expect SQL Server to hash date_map (I guess
this table has < 1000 rows).

Really, what is going on I don't know, but if you have a powerful machine,
SQL Server may be doing some sort of a loop join, invoking parallellism.

You could type the query into Query Analyzer, and then press Ctrl-L to
see the estimated execution plan. If the plan involves loop join, I
would try this:

update [all_sales]
set accounting_month = b.accounting_month
from [all sales] a
inner hash join date_map b
on a.sales_date >= b.start_date and a.sales_date < b.end_date
where a.accounting_month <> b.accounting_month

SQL Server will issue a warning when you use join hint, but as long as
the query executes well, that's OK.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3
Erland Sommarskog <so****@algonet.se> wrote in message news:<Xn**********************@127.0.0.1>...
[posted and mailed, please reply in news]

Karaoke Prince (ka************@hotmail.com) writes:
I have an update statement to update a field of a table (~15,000,000
records). It took me around 3 hours to finish 2 weeks ago. After that
no one touched the server and no configuration changed. Until
yesterday, I re-ran it again and it took me more than 18hrs and still
not yet finished!!!


The first thing to check for is blocking. It might simply be that
some other process is holding a lock on the [all sales] table, preventing
you from continue. Use sp_who to check this. If you see a non-zero value
in the Blk column, this spid is blocking the spid on this line.

The second thing to check for is triggers. A trigger on a 15-million-
row table could be fatal.

Not that these are the most likely reasons, but they are easy to check.
What's wrong with it? I can ran it successfully before. I have tried
two times but the result was still the same.

My SQL statement is:

update [all_sales] a
set a.accounting_month = b.accounting_month
from date_map b
where a.sales_date >= b.start_date and a.sales_date < b.end_date;


If that is your SQL, you are not running SQL Server, but some other
product. When I run the above, I get a syntax error:

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'a'.

In lieu of other information, I have to assume that the real query is

update [all_sales]
set accounting_month = b.accounting_month
from [all sales] a, date_map b
where a.sales_date >= b.start_date and a.sales_date < b.end_date;

I would recommend that you add this condition to this query:

and a.accounting_month <> b.accounting_month

This may or may not improve the query plan, but at least it reduces
the number of rows. (Since you ran this statement a couple of
months ago, I guess that most rows already have the correct
accounting_month.)

Note that the query is such that SQL Server will have to read all rows
in the table. (I assume that all values of [all sales].sales_date
are covered by date_map.)

If there were clustered indexes on a.sales_date and b.start_date,
SQL Server could use a merge join. But this would only give a minor
improvement over the case where there are no indexes at all, in
which case I would expect SQL Server to hash date_map (I guess
this table has < 1000 rows).

Really, what is going on I don't know, but if you have a powerful machine,
SQL Server may be doing some sort of a loop join, invoking parallellism.

You could type the query into Query Analyzer, and then press Ctrl-L to
see the estimated execution plan. If the plan involves loop join, I
would try this:

update [all_sales]
set accounting_month = b.accounting_month
from [all sales] a
inner hash join date_map b
on a.sales_date >= b.start_date and a.sales_date < b.end_date
where a.accounting_month <> b.accounting_month

SQL Server will issue a warning when you use join hint, but as long as
the query executes well, that's OK.

Dear Erland -

these are just guesses..... If queries run for such a long time I
normally
use the stored procedure track_waitstats
see :(www.microsoft.com/australia/resources/ distribution_slides.ppt )

during the long run i sample the waits with the dbcc
sqlperf(waitstats)
and then I know exactly what SQL Server is waiting for, with that
knowledge one quickly can determine what is wrong.
In fact - in the oracle community the wait events have been along a
long
time - for several years this is also possible on SQL Server with the
dbcc sqlperf(waitstats), though on ehas to take into consideration
that
the waitstats on SQL Server are server-wide - one can not
(unfortuanality not yet) trace the wait events on a single user or
process.

For an exact description of waits and DBMS systems I also refer to
http//www.hotsos.com - one can always learn someting (good and bsad)
from oracle:))
Jul 20 '05 #4
Bjarke/Erland,

I did a presentation on this subject (in Lalandia, DK), early October. The
presenation and tools are on www.sqlinternals.com. I also added some tools:
an experimental dll that you can use to collect waitstats per user (and
query them, from an exe or from an xp). Only works on SP3(!)
I also added a little C-program (with source) which looks at the waitstats
of a particular spid. It accesses sqlserver memory directly through
'readprocessmemory', so very low overhead and possible high sample counts
(which you can specify in ms).
The big problem is still documentation on those waitstats: things get more
interesting if you realy know what you are looking at.

--
regards,
Mario

http://www.sqlinternals.com

"Bjarke Wedemeijer" <we********@mail.dk> wrote in message
news:68**************************@posting.google.c om...
Erland Sommarskog <so****@algonet.se> wrote in message

news:<Xn**********************@127.0.0.1>...
[posted and mailed, please reply in news]

Karaoke Prince (ka************@hotmail.com) writes:
I have an update statement to update a field of a table (~15,000,000
records). It took me around 3 hours to finish 2 weeks ago. After that
no one touched the server and no configuration changed. Until
yesterday, I re-ran it again and it took me more than 18hrs and still
not yet finished!!!


The first thing to check for is blocking. It might simply be that
some other process is holding a lock on the [all sales] table, preventing you from continue. Use sp_who to check this. If you see a non-zero value
in the Blk column, this spid is blocking the spid on this line.

The second thing to check for is triggers. A trigger on a 15-million-
row table could be fatal.

Not that these are the most likely reasons, but they are easy to check.
What's wrong with it? I can ran it successfully before. I have tried
two times but the result was still the same.

My SQL statement is:

update [all_sales] a
set a.accounting_month = b.accounting_month
from date_map b
where a.sales_date >= b.start_date and a.sales_date < b.end_date;


If that is your SQL, you are not running SQL Server, but some other
product. When I run the above, I get a syntax error:

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'a'.

In lieu of other information, I have to assume that the real query is

update [all_sales]
set accounting_month = b.accounting_month
from [all sales] a, date_map b
where a.sales_date >= b.start_date and a.sales_date < b.end_date;

I would recommend that you add this condition to this query:

and a.accounting_month <> b.accounting_month

This may or may not improve the query plan, but at least it reduces
the number of rows. (Since you ran this statement a couple of
months ago, I guess that most rows already have the correct
accounting_month.)

Note that the query is such that SQL Server will have to read all rows
in the table. (I assume that all values of [all sales].sales_date
are covered by date_map.)

If there were clustered indexes on a.sales_date and b.start_date,
SQL Server could use a merge join. But this would only give a minor
improvement over the case where there are no indexes at all, in
which case I would expect SQL Server to hash date_map (I guess
this table has < 1000 rows).

Really, what is going on I don't know, but if you have a powerful machine, SQL Server may be doing some sort of a loop join, invoking parallellism.

You could type the query into Query Analyzer, and then press Ctrl-L to
see the estimated execution plan. If the plan involves loop join, I
would try this:

update [all_sales]
set accounting_month = b.accounting_month
from [all sales] a
inner hash join date_map b
on a.sales_date >= b.start_date and a.sales_date < b.end_date
where a.accounting_month <> b.accounting_month

SQL Server will issue a warning when you use join hint, but as long as
the query executes well, that's OK.

Dear Erland -

these are just guesses..... If queries run for such a long time I
normally
use the stored procedure track_waitstats
see :(www.microsoft.com/australia/resources/ distribution_slides.ppt )

during the long run i sample the waits with the dbcc
sqlperf(waitstats)
and then I know exactly what SQL Server is waiting for, with that
knowledge one quickly can determine what is wrong.
In fact - in the oracle community the wait events have been along a
long
time - for several years this is also possible on SQL Server with the
dbcc sqlperf(waitstats), though on ehas to take into consideration
that
the waitstats on SQL Server are server-wide - one can not
(unfortuanality not yet) trace the wait events on a single user or
process.

For an exact description of waits and DBMS systems I also refer to
http//www.hotsos.com - one can always learn someting (good and bsad)
from oracle:))

Jul 20 '05 #5

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

Similar topics

0
by: ptouch | last post by:
Hi, I am using Python 2.3.4 with Windows 2000. It is a Pentium Xeon 2GHz with 1GB of RAM. As the title says, importing most modules takes about 2 to 3 seconds. Also, starting the interpreter...
2
by: serge calderara | last post by:
Dear all, I have a simple class in my application whcih create dynamically textbox control to be place on a form When I execute the code : log(time) my control = new myclass() log (time)
0
by: JJ | last post by:
Hi, I'm having a little problem. I use the following code to open a .pdf file from one app. : System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(); string path...
1
by: mike | last post by:
Hi, Starting a debug session used to take about 2-3 seconds. I took the project home and worked on my laptop at home, burned it onto CD then brought it back to work. Now it takes 15-20 seconds...
4
by: Brian | last post by:
Hello, I have a vb.net web app that I am doing reads and adds to a database. Everything works fine and happens instantly. I recently added an update and it takes a long time to finish. I was...
1
by: William Sullivan | last post by:
I've got a website that may, on occasion, display a large list of items in a bulletedlist control. On the client side, it takes about 4 seconds to get a response that weighs in at over 1mb. It...
0
by: John Smith | last post by:
Hello, I have 7 different crystal reports that need to be collated. Since I want to end up with a page of each (which all together make a single report), I created a blank main report and then...
2
by: vpai | last post by:
We have a package in production which has suddenly started consuming greater than normal time to execute. On debugging this further, we found the following: The package takes 5 mins to come out. ...
2
by: Jason Huang | last post by:
Hi, I am wondering why it takes a long time to open an .aspx file at the first time in a browser. Are there some methods to improve that speed? Given that we are using the IIS5+VS2005 C#....
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.