Solved

Query expands tempdb in SQL Server

Posted on 2013-01-25
2
250 Views
Last Modified: 2013-01-28
I have a view that I am running through Management Studio in the query widow. I am selecting 1000 records. When I run it, the tempdb table grows very quickly and the query takes several minutes to run.  Tempdb can go from 1 mb to 1 gb in a few minutes.  The query uses COUNT(*) ,  GROUP BY and HAVING. All tables (6) are indexed and I reoganized all of the indexes while testing.  A web page that calls the view runs with no affect on tempdb.  No other views in this database have the problem.  Any idea why this would happen?

Thanks,

Steve
0
Comment
Question by:McLeanIS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 22

Accepted Solution

by:
Steve Wales earned 225 total points
ID: 38820774
First you need to understand what tempdb is used for - among other things, sorts.

See: http://msdn.microsoft.com/en-us/library/ms190768.aspx 

If you're doing a group by, there's some implicit sorting in there in order to group the same items.

A 1GB tempdb doesn't seem terribly out of the ordinary to me (but then that's based upon my particular servers - I have no idea about how large your data set is).

However, a 1 MB tempfile seems terribly small, there's no room for it to do anything.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 38823388
Why is your Tempdb so small?  It should be at least 1 GB.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question