Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Update takes too long and freezes the server


Update takes too long and freezes the server

Author
Message
Eshika
Eshika
Valued Member
Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)

Group: General Forum Members
Points: 74 Visits: 314
I selected the data, it took micro seconds. But, when running an update statement (two columns) it takes too long. The server is going to a 'NOT RESPONDING' state and freezes for about 15 - 20 mins.

Below is the query and details of my research -

UPDATE Table
SET col1='C'
,DATE = '2012-01-10 00:00:00.000'
where NAME in ('A','B')


The table contains of over 2000 records.There is no specific activity on the server, there is a trigger associated with one of the columns which I am trying to update.

Can you get me some inputs on nailing down the cause of the issue. As I am new to be a DBA.

Eshika
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24206 Visits: 37971
Need the ddl (CREATE TABLE script) for the table including the definition for the trigger. If the trigger affects any other tables we will need those also.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21075 Visits: 18259
2000 records should take very little time at all to update.

Please provide the trigger definition.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Eshika
Eshika
Valued Member
Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)

Group: General Forum Members
Points: 74 Visits: 314
An overview of the trigger - There are two databases DB1-Transactional and DB2-Archive. There are two tables from each database, Tables1 & 2 from DB1 and Tables 3&4 from DB2.

The trigger involves both databases and 4 tables.
As stats column = A from table1 ;
1. updates the date column ;
2. The data will be moved to from TB1 -->Tb3 DB2
3. The corresponding data will be moved to from TB2 -->Tb4 DB2

And all the data from Tb1 & TB2 will be deleted after insert.


Table definition -
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO

CREATE TABLE [Schema1].[Table1](
[ROWID] [bigint] IDENTITY(1,1) NOT NULL,
[LID] [varchar](100) NOT NULL,
[NAME] [varchar](100) NULL,
[TOTALCOUNT] [int] NULL,
[PID] [int] NULL,
[CID] [int] NULL,
[OID] [int] NULL,
[ADATE] [datetime] NULL,
[RDATE] [datetime] NULL,
[CDATE] [date] NULL,
[STAT] [varchar](10) NULL,
[NOTE] [nvarchar](max) NULL,
[REACH] [varchar](4) NULL,
[SA] [varchar](4) NULL,
[RED] [char](1) NULL,
[DK] [varchar](4) NULL,
[DATEINDB] [datetime] NULL,
[MODDATE] [datetime] NULL,
[TID] [varchar](100) NULL,
CONSTRAINT [PK_Table1] PRIMARY KEY NONCLUSTERED
(
[ROWID] ASC,
[LID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [Schema1].[Table1] ADD CONSTRAINT [DF_Table1_STAT] DEFAULT ('A') FOR [STAT]
GO

ALTER TABLE [Schema1].[Table1] ADD CONSTRAINT [DF_Table1_DATEINDB] DEFAULT (getdate()) FOR [DATEINDB]
GO

Trigger Statement -

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [Schema1].[Table1_STAT]
ON [Schema1].[Table1]
FOR UPDATE ,INSERT , DELETE
AS
BEGIN
IF NOT UPDATE(MODDATE)
UPDATE [Schema1].[Table1]
SET MODDATE=GETDATE()
WHERE LID IN (SELECT LID FROM inserted WHERE STATUS in ('C','X'))

---Insert the C or X lead sheet to arch
INSERT INTO [DB2].[dbo].[ArchTable2]
([ROWID] ,[LID],[NAME],[TOTALCOUNT],[PID],[CID],[OID],[ADATE],[RDATE]
[CDATE],[STAT] ,[NOTE] ,[REACH] ,[SA] ,[RED], [DK] , [DATEINDB],[MODDATE],[TID])
SELECT [ROWID] ,[LID],[NAME],[TOTALCOUNT],[PID],[CID],[OID],[ADATE],[RDATE]
[CDATE],[STAT] ,[NOTE] ,[REACH] ,[SA] ,[RED], [DK] , [DATEINDB],[MODDATE],[TID]
FROM inserted
WHERE LID IN (SELECT LID FROM inserted WHERE STAT in ('C','X'))

-- Insert the closed or disabled lead sheet associated leads to arch
INSERT INTO [DB2].[dbo].[ARCHTable3]
(80 Columns)

SELECT 80 columns
FROM [DB1].[Schema1].[Table2] A INNER JOIN inserted I
ON A. [LID] = I.LID
WHERE I.STAT in ('C','X')

-- Delete all the closed or disabled lead sheets and leads after archiving

DELETE [DB1].[Schema1].[Table2] WHERE LID IN (SELECT LID FROM inserted WHERE STAT in ('C','X'))
DELETE [DB1].[Schema1].[Table1] WHERE LID IN (SELECT LID FROM inserted WHERE STATUS in ('C','X'))

END
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24206 Visits: 37971
Eshika (1/10/2012)
An overview of the trigger - There are two databases DB1-Transactional and DB2-Archive. There are two tables from each database, Tables1 & 2 from DB1 and Tables 3&4 from DB2.

The trigger involves both databases and 4 tables.
As stats column = A from table1 ;
1. updates the date column ;
2. The data will be moved to from TB1 -->Tb3 DB2
3. The corresponding data will be moved to from TB2 -->Tb4 DB2

And all the data from Tb1 & TB2 will be deleted after insert.


Table definition -
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO

CREATE TABLE [Schema1].[Table1](
[ROWID] [bigint] IDENTITY(1,1) NOT NULL,
[LID] [varchar](100) NOT NULL,
[NAME] [varchar](100) NULL,
[TOTALCOUNT] [int] NULL,
[PID] [int] NULL,
[CID] [int] NULL,
[OID] [int] NULL,
[ADATE] [datetime] NULL,
[RDATE] [datetime] NULL,
[CDATE] [date] NULL,
[STAT] [varchar](10) NULL,
[NOTE] [nvarchar](max) NULL,
[REACH] [varchar](4) NULL,
[SA] [varchar](4) NULL,
[RED] [char](1) NULL,
[DK] [varchar](4) NULL,
[DATEINDB] [datetime] NULL,
[MODDATE] [datetime] NULL,
[TID] [varchar](100) NULL,
CONSTRAINT [PK_Table1] PRIMARY KEY NONCLUSTERED
(
[ROWID] ASC,
[LID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [Schema1].[Table1] ADD CONSTRAINT [DF_Table1_STAT] DEFAULT ('A') FOR [STAT]
GO

ALTER TABLE [Schema1].[Table1] ADD CONSTRAINT [DF_Table1_DATEINDB] DEFAULT (getdate()) FOR [DATEINDB]
GO

Trigger Statement -

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [Schema1].[Table1_STAT]
ON [Schema1].[Table1]
FOR UPDATE ,INSERT , DELETE
AS
BEGIN
IF NOT UPDATE(MODDATE)
UPDATE [Schema1].[Table1]
SET MODDATE=GETDATE()
WHERE LID IN (SELECT LID FROM inserted WHERE STATUS in ('C','X'))

---Insert the C or X lead sheet to arch
INSERT INTO [DB2].[dbo].[ArchTable2]
([ROWID] ,[LID],[NAME],[TOTALCOUNT],[PID],[CID],[OID],[ADATE],[RDATE]
[CDATE],[STAT] ,[NOTE] ,[REACH] ,[SA] ,[RED], [DK] , [DATEINDB],[MODDATE],[TID])
SELECT [ROWID] ,[LID],[NAME],[TOTALCOUNT],[PID],[CID],[OID],[ADATE],[RDATE]
[CDATE],[STAT] ,[NOTE] ,[REACH] ,[SA] ,[RED], [DK] , [DATEINDB],[MODDATE],[TID]
FROM inserted
WHERE LID IN (SELECT LID FROM inserted WHERE STAT in ('C','X'))

-- Insert the closed or disabled lead sheet associated leads to arch
INSERT INTO [DB2].[dbo].[ARCHTable3]
(80 Columns)

SELECT 80 columns
FROM [DB1].[Schema1].[Table2] A INNER JOIN inserted I
ON A. [LID] = I.LID
WHERE I.STAT in ('C','X')

-- Delete all the closed or disabled lead sheets and leads after archiving

DELETE [DB1].[Schema1].[Table2] WHERE LID IN (SELECT LID FROM inserted WHERE STAT in ('C','X'))
DELETE [DB1].[Schema1].[Table1] WHERE LID IN (SELECT LID FROM inserted WHERE STATUS in ('C','X'))

END






Several things jump out at me:

1) The trigger is defined to be fired on INSERT, UPDATE, or DELETE on the table [Schema1].[Table1].
2) It appears, based on the logic, that perhaps this trigger should only be fired on UPDATE. Question, can data being INSERTed be immediately archived?
3) Do you have recursive triggers enabled on the database. I wouldn't be surprised if this trigger is blocking itself when fired.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21075 Visits: 18259
Based on this being related to leads, how large are the tables involved?

Please provide the execution plan too!



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24206 Visits: 37971
SQLRNNR (1/10/2012)
Based on this being related to leads, how large are the tables involved?

Please provide the execution plan too!


Agreed, and it should be the Actual execute plan if possible (but based on my assumption, the estimated may have to do).

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Eshika
Eshika
Valued Member
Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)

Group: General Forum Members
Points: 74 Visits: 314
In Tables 1&3 there are over 2000 records,tables 2 & 4 there are over 20 million records.
The trigger should be fired on an update, there are no recursive triggers on the tables. I will post the execution plan soon.


I tried to update after disabling the trigger and it was fast. I suspect the size of the tables involved is causing the issue.

Please let me know your thoughts,Thank you for all your responses.
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21075 Visits: 18259
Eshika (1/11/2012)
In Tables 1&3 there are over 2000 records,tables 2 & 4 there are over 20 million records.
The trigger should be fired on an update, there are no recursive triggers on the tables. I will post the execution plan soon.


I tried to update after disabling the trigger and it was fast. I suspect the size of the tables involved is causing the issue.

Please let me know your thoughts,Thank you for all your responses.


You have the trigger defined for update, insert, delete. Should it only be for update based on what you just said?

Based on the exec plan, your trigger code can likely be optimized so that it will run faster.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

ScottPletcher
ScottPletcher
Hall of Fame
Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)

Group: General Forum Members
Points: 3946 Visits: 6684
On the really large tables, looks like you are using LID, varchar(100), to join / match on them.

Is there an index on LID on the large tables? If so, were you able to check the query plan and verify that SQL will use the index to do those joins / matches?

SQL DBA,SQL Server MVP('07, '08, '09)

Prosecutor James Blackburn, in closing argument in the "Fatal Vision" murders trial: "If in the future, you should cry a tear, cry one for them [the murder victims]. If in the future, you should say a prayer, say one for them. And if in the future, you should light a candle, light one for them."
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search