Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

Query expands tempdb in SQL Server

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
McLeanIS
Asked:
McLeanIS
1 Solution
 
Steve WalesSenior Database AdministratorCommented:
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
 
Anthony PerkinsCommented:
Why is your Tempdb so small?  It should be at least 1 GB.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now