views:

129

answers:

7

I have a table with 30 columns and about 3.4 million records. Is it reasonable for SELECT * FROM [Table]; to take 8 to 12 minutes to return all 3.4 million results?

If not, where's a good place/resource to begin diagnosing my problem?

+1  A: 

It's most likely that SQL server is doing its best to get the data you asked for. It's not unreasonable to assume at least 1K/record for 30 columns. 3.4M x 1K = 3.4Gb.

Just reading 3.4Gb from the disk could take minutes on an average machine (do not forget that this is not just reading, there's obviously some SQL processing overhead in it.

But of course in a real world scenario you don't want to retrieve all the data...

Dan Cristoloveanu
+5  A: 

Yes, is reasonable. For a system that finely tunned and runing optimally can deliver 3.4 mil rows in about 12 minutes, this is exactly the expected result...

None the less, some places to look for to improve performance:

  • Does the table fit in the buffer pool? Ie. do you have enough RAM to store your entire database? If no, then you're going to hit the disk for IO. Page life expectancy counter is a good indicator.
  • How fast is your disk I/O subsystem? Are we talking about a 5000 RPM second hand IDE drive or a RamSAN-500? What is the throughput reported by sqliosim ? How about perf counters, Avg. Disk Queue Length, Avg. Disk Sec/Transfer on the physical disks? Is it different for Reads vs. Writes?
  • How fragmented is the table? A scan performance is affected first and foremost by read-ahead efficiency and read-ahead size is determined by hobt fragment size. Perhaps you need to optimize the ETL of the table, follow the FastTrack methodology.
  • any contention going on? Have you measured lock wait times? Perhaps snasphot isolation can aleviate the problem.
  • Can the client receive the 3.4 mil rows in time? Does the server block on client buffers availability? Again, wait stats can indicate this.

Another good place to start is to follow the Wait and Queues methodology.

Remus Rusanu
What? finely tuned and running optimally can deliver 3.4 in about 12 minutes? Are you serious? Try less than 12 seconds. -1
keithwarren7
Lol, you really didn't get it, did you, keith?
Remus Rusanu
I must be missing a /sarcasm tag or something
keithwarren7
Yeap. How are we supposed to guess if the performance is reasonable w/o even the slightest information about the system? This result would be perfectly reasonable on a netbook...
Remus Rusanu
@keithwarren7 - I think the point Remus is trying to make is that the question is relative "is this reasonable?" with no way of making a qualitative decision as to whether it is or not. So on a system that is capable of delivering that performance, then yes it is a reasonable performance for that system.
Greg Beech
And besides, the actual perf troublshooting advice I give is serious and not that bad, says I.
Remus Rusanu
OK, I agree but SO wont let me give you back the vote down. Sorry.
keithwarren7
No worries. A /tag would had been usefull indeed :)
Remus Rusanu
A: 

There are so many questions that could be asked relating to disk IO, size of the columns and other setup related things. Bottom line unless you are on a really really slow disk and slow network it should not take 12 minutes.

The first place to look is at the Execution plan. This should give you an idea of how SQL Server is handling things.

Couple things I would ask to better troubleshoot? Is there a primary key? Is it clustered? Is there an order by?

keithwarren7
+1  A: 

The best place to start diagnosing your problem is to determine whether you have a problem at all. Set a specific, measurable, business-oriented performance goal, and define exactly how long you think is reasonable for returning the data.

If your answer is 8-12 minutes, then you don't have a problem, which is always a good thing.

If your answer is less than that, then you now know that you have a problem, and how big the problem is (if you said 5 minutes then it's maybe not such a big problem, if you said 10 seconds then it's a much bigger issue). In this case, you'll probably want to start looking at the database performance counters to see whether it's got CPU/IO/memory/network bottlenecks, and looking at the execution plan for the query to see whether it could be improved by indexes (though this is unlikely for a SELECT *).

Greg Beech
A: 

It might be more interesting to asses the queries your system is actually running. The Profiler tool that comes with SQL Server can make a log of all the queries your system is running. Let it run over a given period (assuming you have a good amount of extra disk space) and it will record what queries are being run, and the parameters given. It will also tell you how long they all took to execute.

Looking at this and figuring out what queries are using up your CPU time will help you figure out where to go for performance tuning - for instance, If Query A takes 60 seconds to run, and runs only once a day, it might have big impact on that specific app to tune it, but tuning that one query wont make your SQL Server faster. But if Query B takes 2 seconds to run and runs 4,000 times per day, tuning it may have a bigger overall impact.

Often adding relevant indexes and performance tuning your "big offender" queries can make a very serious positive impact on performance. What the profiler shows you about who those queries are might surprise you.

Kyle Hodgson
A: 

Reasonable compared to what?

  1. How wide are the rows?
  2. How fast is your CPU?
  3. How much RAM do you have?
  4. Is the table already in RAM when you start the query?
  5. Are you delivering the results over a network? If so, how fast is it?
  6. How fast is the client that's retrieving the rows?
  7. How fast are your disks?
  8. How fragmented is the table?
  9. Is the DB machine doing anything else at the same time?
RickNZ
A: 

I agree with you, I just brought back 20 million rows of data from a SQL 2008 server in less than 3 minutes - the hardware cost less than the SQL license.

Unless your hardware / network really sucks then there is a performance gain to be made somewhere.

How large are your rows? I can bring back a single column in about 3 minutes, but to bring back the whole table (about 4.3GB of data) takes roughly 12 minutes.
CodeChef