Solved

Query expands tempdb in SQL Server

Posted on 2013-01-25
2
249 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
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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