SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


tempdb getting full


tempdb getting full

Author
Message
Golfer22
Golfer22
SSC-Enthusiastic
SSC-Enthusiastic (178 reputation)SSC-Enthusiastic (178 reputation)SSC-Enthusiastic (178 reputation)SSC-Enthusiastic (178 reputation)SSC-Enthusiastic (178 reputation)SSC-Enthusiastic (178 reputation)SSC-Enthusiastic (178 reputation)SSC-Enthusiastic (178 reputation)

Group: General Forum Members
Points: 178 Visits: 96
See if the queries don't need to sort all those rows. Re-writing the query to filter out certain rows could help. But I don't know what your needs are.

If you could use table variables instead of temporary tables, that could help. But it requires a large amount of memory. Upgrading memory could help.

Instead of temporary tables you could use permanent tables and have a routine that truncates the permanent table when it is no longer needed.

Some databases have the option SORT_IN_TEMPDB set to on. Maybe you need to set it to off.

If you could increase the size of tempdb by putting it on a different hard drive, that could improve performance too. For more information on optimizing tempdb see this link:
http://msdn.microsoft.com/en-us/library/ms175527%28v=sql.105%29.aspx

For capacity issues, see this link: http://msdn.microsoft.com/en-us/library/ms345368%28v=sql.105%29.aspx

P.S. For the sorting issue, look at the estimated execution plan. See if there is a hash join or merge join. If the sorts are using hash joins to sort, those can use a great deal of space in tempdb. If introducing an ORDER BY clause to the tables could happen before the main sorting, then the optimizer would use a merge join to get the final sorted result. It would be worth re-writing the joining and sorting portions of the stored procedure not just to save space in tempdb, but to save time. Merge sorts have both of these advantages. Merge sorts happen when the different tables being sorted are semi-sorted already. The optimizer chooses this underlying algorithm under certain conditions. If it does, it will save you space in your tempdb. If performance of the stored procedures is currently faster than acceptable and tempdb space is your absolute concern, you could rewrite the queries to use nested loops instead of hash joins. But this could be a considerable development effort and the stored procedure doing the sorting (and presumably joining) would take much longer than it was previously taking.
Lynn Pettis
Lynn Pettis
SSC-Dedicated
SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)

Group: General Forum Members
Points: 39746 Visits: 38563
Golfer22 (5/26/2013)


...
If you could use table variables instead of temporary tables, that could help. But it requires a large amount of memory. Upgrading memory could help.

...



Using table variables is not necessarily the best option. Since there are no statistics on table variables SQL Server assumes 1 row even if there are 100,000 rows. This can easily result in a poor execution plan.

Also, table variables can use tempdb just as temporary tables.

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)
GilaMonster
GilaMonster
SSC Guru
SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)

Group: General Forum Members
Points: 88126 Visits: 45277
Golfer22 (5/26/2013)
If you could use table variables instead of temporary tables, that could help. But it requires a large amount of memory. Upgrading memory could help.


Unlikely, since table variables are, like temp tables, stored in TempDB and do not require a large amount of memory (no more than temp tables do)

Instead of temporary tables you could use permanent tables and have a routine that truncates the permanent table when it is no longer needed.


Personally I would not recommend doing that, it introduces concurrency issues and permanent tables log more than temp tables, so now it's the user database and user database log growing, more than TempDB would have and without all the optimisations that TempDB has for frequent table creation.

If introducing an ORDER BY clause to the tables could happen before the main sorting, then the optimizer would use a merge join to get the final sorted result. It would be worth re-writing the joining and sorting portions of the stored procedure not just to save space in tempdb, but to save time.


Sorts spill to TempDB just as hash tables do, and in fact are more likely to spill because of the memory grants required. Sorts are expensive operations and it's very likely that forcing a merge join instead of the hash that the optimiser chooses will result in a slower query that uses more resources.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


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