Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
wombel
Starting Member
14 Posts |
Posted - 2002-03-01 : 15:42:52
|
| Hi,I had some problem with one of my SPs. I found out, that it had a very high recompile rate. It's task was to select some id into a temp table with an identity on it. After that, I selected/joined the data I needed for each id.The reason why I did that was, that I neede to ouput the data pagewise on an ASP-page.Now I thought it would be a good idea to break up the sttatements and I put the creation of the (temp)-table into an UDF that returned the table.The stored procedure then just had the task to join the need information.Does that make sense? Is that one of the ways to optimize SPs?Thanks in advance for your opinion.Thomas WrobelSenior IT Manager |
|
|
Jay99
468 Posts |
Posted - 2002-03-01 : 16:03:06
|
| My guess is the UDF isn't gonna help you much (performance wise) . . . Could you post some code? Maybe you don't need the temp table to do the paging . . .Depending on the amount of data, you might look at handling the paging on the web server rather than in the proc.Jay |
 |
|
|
wombel
Starting Member
14 Posts |
Posted - 2002-03-05 : 05:40:57
|
Hi Jay,thanks fro your reply. We wanted to keep the amount of data being transfered from the db-server to the webserver as small as possible. That was why we decided to prepare the page on the db-server.I enclose the could, I was talking about before and after my changes.Before:ALTER PROCEDURE usr_dtl_gbookselect_new(@intUserid int,@intPage int,@intRecordcount smallint output,@intPagecount smallint output,@intLastRecord int = 0,@intGbArchiv int output,@intGbArchivShowallUsers int output,@strVorname varchar(100) output,@strNachname varchar(100) output,@intGbAktiv int output,@intGbookNoHTML int output,@intUbAktiv int output)ASSET NOCOUNT ONDECLARE @intIDTop int, @intIDLow int, @intSelRec int, @intSelRecNext int, @intRemainder smallintSELECT @strVorname = vorname, @strNachname = name, @intUbAktiv = userbase, @intGbAktiv = gbook, @intGbookNoHTML = gbookhtml, @intGBArchiv = gbook_archiv, @intGbArchivShowallUsers = gbook_archiv_allusersFROM member_user WITH(NOLOCK)WHERE id = @intUserIDcreate table #tmpGbook ( rankid int IDENTITY NOT NULL PRIMARY KEY, gbid int )INSERT INTO #tmpGbook(gbid)SELECT mg.id FROM member_gbook mg WITH (NOLOCK)WHEREmg.userid = @intUseridorder by mg.zeit desccreate index [tmpidx] on #tmpGbook(rankid)SELECT @intRecordcount = @@rowcountSELECT @intPageCount = dbo.fn_runden(@intRecordCount,10)IF @intLastRecord IN (0,1)BEGIN SELECT TOP 10 mg.id, mg.sender, mg.zeit, 'name'= mu.vorname + ' ' + mu.name, mg.eintrag, mu.aktiv FROM #tmpGbook tgb WITH (NOLOCK) JOIN member_gbook mg WITH (NOLOCK) ON tgb.gbid = mg.id JOIN member_user mu WITH (NOLOCK) ON mg.sender = mu.id WHERE rankid >= 0 ORDER BY rankidENDELSEBEGIN SELECT TOP 10 mg.id, mg.sender, mg.zeit, 'name'= mu.vorname + ' ' + mu.name, mg.eintrag, mu.aktiv FROM #tmpGbook tgb WITH (NOLOCK) JOIN member_gbook mg WITH (NOLOCK) ON tgb.gbid = mg.id JOIN member_user mu WITH (NOLOCK) ON mg.sender = mu.id WHERE rankid > @intLastRecord ORDER BY rankidENDAFTER:ALTER PROCEDURE usr_dtl_gbookselect_new_thomas(@intUserid int,@intCurrentPage int,@intRecordcount smallint output,@intPagecount smallint output,@intLastRecord int = 0,@intGbArchiv int output,@intGbArchivShowallUsers int output,@strVorname varchar(100) output,@strNachname varchar(100) output,@intGbAktiv int output,@intGbookNoHTML int output,@intUbAktiv int output)ASSET NOCOUNT ONDECLARE @intIDTop int, @intIDLow int, @intSelRec int, @intSelRecNext int, @intRemainder smallint, @intMinId intSELECT @strVorname = vorname, @strNachname = name, @intUbAktiv = userbase, @intGbAktiv = gbook, @intGbookNoHTML = gbookhtml, @intGBArchiv = gbook_archiv, @intGbArchivShowallUsers = gbook_archiv_allusersFROM member_user WITH(NOLOCK)WHERE id = @intUserIDSET @intRecordCount = dbo.fn_usr_dtl_gbookselect_new_anzahl(@intUserid)SELECT @intPageCount = dbo.fn_runden(@intRecordCount,10)SET @intMinId = (@intCurrentPage - 1) * 10SELECT TOP 10 mg.id, mg.sender, mg.zeit, 'name'= mu.vorname + ' ' + mu.name, mg.eintrag, mu.aktivFROM dbo.fn_usr_dtl_gbookselect_new_temp(@intUserid) as tgb JOIN member_gbook mg WITH (NOLOCK) ON tgb.gbid = mg.idJOIN member_user mu WITH (NOLOCK) ON mg.sender = mu.idWHERE rankid >= @intMinIdORDER BY rankidquote: My guess is the UDF isn't gonna help you much (performance wise) . . . Could you post some code? Maybe you don't need the temp table to do the paging . . .Depending on the amount of data, you might look at handling the paging on the web server rather than in the proc.Jay
quote:
quote:
Thomas WrobelSenior IT Manager |
 |
|
|
|
|
|
|
|