Performance issue on simple SELECT?

Discussion in 'Databases' started by mbudney, Feb 9, 2010.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I have a database hosted on SQL 2005 and am having an interesting performance problem.

    I have a table with a little over 10,0000 records in it. This table is basically a flattened, de-normalized view of several tables. Creation of this table on the server side takes 3 to 6 seconds.

    However, selecting from this table with no joins or where clauses (SELECT * FROM tableName) takes over 5 minutes to return the data. If I convert the query to a count query it returns right away.

    I was told by support to index and optimize the database but so far it seems to be more of a bandwidth issue in returning the data. The query I'm executing doesn't need indexes.

    I can also execute a Count() on a more complex query with multiple joins and get a fast response. However, if the same query then returns around 10K rows of data it takes and excessive amount of time.

    Also we have noticed that in SQL Server Management Studio that it can take a considerable amount of time to just expand out the Tables node.

    This time also seems to occur between the Web Server and the Database server which rules out external network/Internet influences.
     
  2. Here are some statistics my DBA just ran:

    Code:
    SET STATISTICS TIME ON;
    GO
    
    SET STATISTICS IO ON;
    GO
    
    SELECT TOP 1000 * FROM dbo.SiteSearch
     
  3. dmitri

    dmitri DiscountASP.NET Staff

    It does not look like it is I/O issue. Can you please try running your query with no lock and see if it helps:

    Code:
    SELECT TOP 1000 * FROM dbo.SiteSearch WITH (nolock)
    
     
  4. Thanks for the response.

    With the nolock on I got 46 seconds on 1000 rows executing the same query as above.

    We're on sql2k505 if that helps any.

     
  5. Here is the same query with a count


    Code:
    SELECT Count(*) FROM dbo.SiteSearch

     
  6. Our DBA thinks the server is either low on memory resources or the network bandwidth on the server is strained. He suggested running perfmon but I assume you guys would have an automatic eye on that already.
     
  7. dmitri

    dmitri DiscountASP.NET Staff

    We run performance monitor 24/7 on all services and I do not see any issues with database servers. There is no complains from other customers on this server. There are customers with serious business websites and they would not tolerate even a slightest glitch in performance.

    I am running out of ideas, but can you try two more things:

    1. Try to list your columns in the query explicitly instead of using (*).

    2. Can you try executing this query with MyLittleAdmin Interface provided to you with your database addon. Please close any connections to your database in Management Studio and stop your web application that might be using it to make sure nothing interrupts your query. If there is no visible timing improvement, I am afraid that the only thing I can suggest is to index your table or tune up and redesign your database structure for better performance.
     
  8. I figured you had automatic monitoring in place.

    Was something just done? Our manager just ran out to say the CMS system, which is in a sepparate DB on the same server, was much faster now than it has been since the start of the project.

    The execution time has been cut in half (25 seconds) on the query I posted above. However, that is still quite long for 1000 rows.

    I'll try the MyLittleAdmin interface.
     
  9. JorgeR

    JorgeR DiscountASP.NET Staff

    please advise on the server where your database is hosted on or create a ticket to see what is the database you are referring too. I am not sure why you may want to (table scan) over 10,0000 records (we do not know how the table is designed - contents of it). Please provide further information.
     
  10. Made some interesting observations. Using named columns didn't cause a performance difference but reducing the number of columns in half reduced the time factor by about 6x ( to 4 seconds). I would have expected a more linear response.

    However, on our SQL servers there is no significant difference in time when experimenting with the row size on the same query.

    I'll try a ticket in the AM but was advised to take the issue to the forum after creating a ticket.
     
  11. Oh, as for why so many records, we don't normally do that. Our application is basically a tower/cellular site search application.

    Typically the app will page the data at 50 records a time as requested by the end user. There are also geographic searches that require a distance calculation in the software that might be over a slightly large group but those can't be paged.

    However, there is also an export to Excel option in which all records of a search could be returned. So the end user might need to export a list of all of our towers within a particular city or geographic location.

    It's not the scanning of the data that seems to be a problem. The servers do an excellent job at that. It's returning the data that seems a bit slow.
     
  12. JorgeR

    JorgeR DiscountASP.NET Staff

    When using the select statement, it is best practice to call the column names instead of using the '*'. It is possible that the server was heavily used during the time of your initial test. I can't confirm this, but its a high possibility from looking at the elapsed time = 46714 ms. This is usually an indicator that SQL resources are being occupied.

    Anyhow, it is best to run the actual query against the SQL server that you will be using. There are a lot of factors that can affect a 'Select' statement on a share hosting environment. It is best to run the query that you are running in your application. If you run the initial statement again, at a different time, I am pretty sure that the SQL Server Execution Times, elapsed time, is a lot different. When you create the ticket with the information, please supply the time you ran the test so that we are able to look at the monitors snapshot of what was happening with the SQL Server at that time.
     
  13. JorgeR

    JorgeR DiscountASP.NET Staff

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page