Re: 100% CPU Util on Simple Update Query
From: Hugo Kornelis (hugo_at_pe_NO_rFact.in_SPAM_fo)
Date: 02/15/05
- Next message: Adrian Parker: "Triggers Vs RI"
- Previous message: Alejandro Mesa: "RE: Update Rows from other Rows"
- In reply to: Joel H: "Re: 100% CPU Util on Simple Update Query"
- Next in thread: Joel H: "Re: 100% CPU Util on Simple Update Query"
- Reply: Joel H: "Re: 100% CPU Util on Simple Update Query"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 15 Feb 2005 17:07:23 +0100
On Tue, 15 Feb 2005 06:55:08 -0800, Joel H wrote:
>ITS BAACK. Yesterday, I had the same problem.
>The query in full looks like this:
(snip)
Hi Joel,
If I read your query correctly, you are updating each column with the
value from a different column if switch is -1 for that row, and setting
each column to the value of that column itself if switch is unequal to -1.
That means you are wasting a lot of time, updating rows with the original
values. It's better to exclude the rows with a value for switch other than
-1 from the update process.
UPDATE IMPT_ZACKS_01
SET DATEOFFISCALQUARTER1END = DATEOFFISCALQUARTER0END,
Q1MEDIAN = Q0MEDIANCURRENT,
Q1NBROFESTIMATES = Q0NBROFESTIMATES,
(.....)
WHERE SWITCH = -1
Depending on the amount of rows with switch unequal to -1, this will speed
up execution either a bit or a whole lot.
Another thing: judging by the column names, your table is not properly
normalized. Consider changing your design to follow at least third normal
form. If the task you're trying to solve is what I think it is, you'll
probably find it much easier to do in a properly normalized database.
>Each row only works on that row.
Yes, but your update statement works on the whole table. That means that
all rows need to be locked until the transaction finishes.
>I took the table, and tried to remove the key, then replace the key, then
>save - hoping to rebuild the key.
If you don't have a WHERE clause, each row needs to be processed. That
means that SQL Server will never use an index; it will always perform a
table scan (if the table has a clustered index, this is called a clustered
index scan - but the name is the only thing that changes).
>I took the table, and tried to remove the key, then replace the key, then
>save - hoping to rebuild the key. I got the following error message:
>'IMPT_ZACKS_01' table
>- Unable to create index 'PK_IMPT_ZACKS_01'.
>ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]
>[Microsoft][ODBC SQL Server Driver][SQL Server]Location: statisti.cpp:3222
>Expression: cbStmtTxtLen/sizeof(WCHAR) <= cwchStmtTxtLen
>SPID: 53
>Process ID: 5576
>Maybe thats a clue?
I have no idea. What tool were you using when you dropped and recreated
the key? Could you try it from QA (Query Analyzer) - that's the tool that
will give the most "vanilla" version of any error messages.
Also, what output do you get when you run the following command in QA:
sp_help IMPT_ZACKS_01
Best, Hugo
-- (Remove _NO_ and _SPAM_ to get my e-mail address)
- Next message: Adrian Parker: "Triggers Vs RI"
- Previous message: Alejandro Mesa: "RE: Update Rows from other Rows"
- In reply to: Joel H: "Re: 100% CPU Util on Simple Update Query"
- Next in thread: Joel H: "Re: 100% CPU Util on Simple Update Query"
- Reply: Joel H: "Re: 100% CPU Util on Simple Update Query"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|