sql server - SQL Query get a lot of timeouts -



sql server - SQL Query get a lot of timeouts -

i have big database table (sql server 2008) have forum messages beingness stored (the table have more 4.5 1000000 entries).

this table schema:

create table [dbo].[forummessage]( [messageid] [int] identity(1,1) not replication not null, [forumid] [int] not null, [memberid] [int] not null, [type] [tinyint] not null, [status] [tinyint] not null, [subject] [nvarchar](500) not null, [body] [text] not null, [posted] [datetime] not null, [confirmed] [datetime] null, [replytomessage] [int] not null, [totalanswers] [int] not null, [avgrateing] [decimal](18, 2) not null, [totalrated] [int] not null, [readcounter] [int] not null, constraint [pk_groupmessage] primary key clustered ( [messageid] asc )with (pad_index = off, statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary] ) on [primary] textimage_on [primary]

one issue see maintain coming when i'm running stored procedure select message , replies, sometime time-outs errors sql server.

this stored procedure:

select fm1.[messageid] ,fm1.[forumid] ,fm1.[memberid] ,fm1.[type] ,fm1.[status] ,fm1.[subject] ,fm1.[body] ,fm1.[posted] ,fm1.[confirmed] ,fm1.[replytomessage] ,fm1.[totalanswers] ,fm1.[avgrateing] ,fm1.[totalrated] ,fm1.[readcounter], member.nickname membernickname, forum.name forumname forummessage fm1 left outer bring together fellow member on fm1.memberid = member.memberid inner bring together forum on fm1.forumid = forum.forumid messageid = @messageid or replytomessage=@messageid order messageid

the error this: "timeout expired. timeout period elapsed prior completion of operation or server not responding"

i looking on execution plan, , suspicious is see query has cost of 75%-87% (it varies) on key lookup in forummessage table (which don't understand why, because set clustered, hoping much more efficient). under assumption when search on clustered index, query should efficient.

is there has thought how can improve issue , query message , replies?

thanks.

two suggestions come mind:

remove ugly or , add together union status (code below) you must have non-clustered index on replytomessage

as lastly resort, create non-clustered index , set messageid , replytomessage in there. (see reply question here why sql statement (with 2 table joins) takes 5 mins complete?)

code: select fm1.[messageid] ,fm1.[forumid] ,fm1.[memberid] ,fm1.[type] ,fm1.[status] ,fm1.[subject] ,fm1.[body] ,fm1.[posted] ,fm1.[confirmed] ,fm1.[replytomessage] ,fm1.[totalanswers] ,fm1.[avgrateing] ,fm1.[totalrated] ,fm1.[readcounter], member.nickname membernickname, forum.name forumname forummessage fm1 left outer bring together fellow member on fm1.memberid = member.memberid inner bring together forum on fm1.forumid = forum.forumid messageid = @messageid union select fm1.[messageid] ,fm1.[forumid] ,fm1.[memberid] ,fm1.[type] ,fm1.[status] ,fm1.[subject] ,fm1.[body] ,fm1.[posted] ,fm1.[confirmed] ,fm1.[replytomessage] ,fm1.[totalanswers] ,fm1.[avgrateing] ,fm1.[totalrated] ,fm1.[readcounter], member.nickname membernickname, forum.name forumname forummessage fm1 left outer bring together fellow member on fm1.memberid = member.memberid inner bring together forum on fm1.forumid = forum.forumid messageid = @messageid order messageid

sql sql-server stored-procedures timeout

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -