none
Large table search performance RRS feed

  • Question

  • I have a large table with 300,000 rows and it will grow in the future
    The table contains member profile details and it has many columns (about 70)
    The stored procedure that do the search use many columns to search the results
    That why the ‘Where’ is very long and the all operation take to many time, some time I get Time out exception form the SQL server.
    I’ll be happy to get some ideas how to do this search.
    I think maybe to divide the table to many tables by State.

     
    Something interesting is that the operation takes long time for the first search and then the second and the third are much faster, and after a few min that I’m not do anything again the first time is very slow

    Thursday, July 19, 2007 11:00 PM

Answers

  • 70 columns in a table is probably too many. It is hard to say. But there are few options to consider:
     
    1. You can partition the table vertically. For example, split the table vertically into two - one with the most frequently accessed columns and another with the infrequent ones. This will make each table smaller in terms of row size and queries will be faster than accessing a single wide table. This of course complicates the data modifications since you have to issue two DMLs as opposed to one but it depends on your application and nature of the table
    2. You can use partitioning (horizontal). But it depends on the choice of your partitioning key whether it is part of every search criteria or at least one of the primary search conditions. You get some manageability benefit also.
     
    Anyway, the approach depends on your needs. You can find whitepapers in MSDN that discuss partitioning for example. Please take a look at that also. You can leave the table as is also and try to optimize the queries by say adding more indexes or creating additional statistics or restricting the search columns. Each has it's pros and cons. For example, adding more indexes will slow down data modification operations.
     
    The reason why the queries are faster after the first time is due to plan caching. Looks like you are generating lot of ad-hoc queries due to variable number of search conditions and this is expected. Of course, the plan might get removed from cache later due to memory pressure or lack of reusability. It is hard to tell without knowing the type of queries and the nature of the workload.
    Thursday, July 19, 2007 11:29 PM

All replies

  • 70 columns in a table is probably too many. It is hard to say. But there are few options to consider:
     
    1. You can partition the table vertically. For example, split the table vertically into two - one with the most frequently accessed columns and another with the infrequent ones. This will make each table smaller in terms of row size and queries will be faster than accessing a single wide table. This of course complicates the data modifications since you have to issue two DMLs as opposed to one but it depends on your application and nature of the table
    2. You can use partitioning (horizontal). But it depends on the choice of your partitioning key whether it is part of every search criteria or at least one of the primary search conditions. You get some manageability benefit also.
     
    Anyway, the approach depends on your needs. You can find whitepapers in MSDN that discuss partitioning for example. Please take a look at that also. You can leave the table as is also and try to optimize the queries by say adding more indexes or creating additional statistics or restricting the search columns. Each has it's pros and cons. For example, adding more indexes will slow down data modification operations.
     
    The reason why the queries are faster after the first time is due to plan caching. Looks like you are generating lot of ad-hoc queries due to variable number of search conditions and this is expected. Of course, the plan might get removed from cache later due to memory pressure or lack of reusability. It is hard to tell without knowing the type of queries and the nature of the workload.
    Thursday, July 19, 2007 11:29 PM
  • What type of partition will give me the best performance vertical or horizontal?

     

    In horizontal partition what is the best way to do it:

    How mane tables?

    Witch column on each table?

     

    The query that do all the problems is the search query and it use 14 columns in the ‘WHERE’ statement, maybe it best to divide the table into 2 table that  one will hold the 14 columns for the search query and the second table will hold the rest of the columns is this will give best performance?

    Wednesday, July 25, 2007 5:35 PM