Very large table - performance issues

  • We have a tall table that contains 2.6 billion rows

    Table structure:

    The application which uses this table has been running slow for the last couple of days and it seems to have happened following the addition of about 400 million rows last weekend.

    I think it's because of the index fragmentation although I'm not sure how to check if this the case without affecting the application?

    So my first question is, how do I check to see if the indexes are fragmented and whether the stats need updating on such a large table?

    ---------------------------------------------------------

    It takes a minimal capacity for rational thought to see that the corporate 'free press' is a structurally irrational and biased, and extremely violent, system of elite propaganda.
    David Edwards - Media lens[/url]

    Society has varying and conflicting interests; what is called objectivity is the disguise of one of these interests - that of neutrality. But neutrality is a fiction in an unneutral world. There are victims, there are executioners, and there are bystanders... and the 'objectivity' of the bystander calls for inaction while other heads fall.
    Howard Zinn

  • SELECT

    database_id, object_name(object_id), object_id, index_id, partition_number, index_type_desc,

    alloc_unit_type_desc, index_depth,

    index_level, avg_fragmentation_in_percent, fragment_count, avg_fragment_size_in_pages, page_count,

    avg_page_space_used_in_percent, record_count, ghost_record_count, version_ghost_record_count, min_record_size_in_bytes,

    max_record_size_in_bytes, avg_record_size_in_bytes, forwarded_record_count

    FROM

    sys.dm_db_index_physical_stats

    ( 5, NULL, NULL, NULL, 'DETAILED' )

    where object_name(object_id) = 'TableName'

    Try this , if avg_fragmentation_in_percent is more than 30 then it is index fragmentation.

    Regards
    Durai Nagarajan

  • Index fragmentation is quite unlikely to cause sudden slow performance. Index fragmentation is in fact only a concern when you're doing large range scans from disk.

    Now statistics, that's a lot more likely to be the problem. Try a stats update with fullscan (yes, it'll take a while) and see if that helps.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks to you both.

    Not sure why I said index fragmentation. When my colleague mentioned it to me, the first thing I asked him was about the stats lol.

    Was thinking along the lines of 400 million new rows = out of date stats = inappropriate execution plans for the queries etc...

    ---------------------------------------------------------

    It takes a minimal capacity for rational thought to see that the corporate 'free press' is a structurally irrational and biased, and extremely violent, system of elite propaganda.
    David Edwards - Media lens[/url]

    Society has varying and conflicting interests; what is called objectivity is the disguise of one of these interests - that of neutrality. But neutrality is a fiction in an unneutral world. There are victims, there are executioners, and there are bystanders... and the 'objectivity' of the bystander calls for inaction while other heads fall.
    Howard Zinn

  • yeah i would have thought of statistics as the issue as well;

    ok we know it takes 20% of the rows int he table , + 500 rows to trigger auto updates of statistics.

    so if you insert 400M rows, is that 400M out of 3000M (13.33 % affected?) or is that 400M of 2600M rows that were already there?(15.38 % affected?)

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • The 2.6 billion total is after the insert of the 400 million.

    ---------------------------------------------------------

    It takes a minimal capacity for rational thought to see that the corporate 'free press' is a structurally irrational and biased, and extremely violent, system of elite propaganda.
    David Edwards - Media lens[/url]

    Society has varying and conflicting interests; what is called objectivity is the disguise of one of these interests - that of neutrality. But neutrality is a fiction in an unneutral world. There are victims, there are executioners, and there are bystanders... and the 'objectivity' of the bystander calls for inaction while other heads fall.
    Howard Zinn

  • Abu Dina (5/21/2013)


    The 2.6 billion total is after the insert of the 400 million.

    cool to have such big table, I'm actually a bit jealous, because it presents a lot more opportunities for learning when fiddling with lots of data. lots of chances to increase experience in tuning, maintenance, etc.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Lowell (5/21/2013)


    Abu Dina (5/21/2013)


    The 2.6 billion total is after the insert of the 400 million.

    cool to have such big table, I'm actually a bit jealous, because it presents a lot more opportunities for learning when fiddling with lots of data. lots of chances to increase experience in tuning, maintenance, etc.

    To be honest a lot of the time I feel out of my depth but as you say, it's a great opportunity to learn new skills in the two key areas you mentioned.

    My boss (who owns half the company) and an accomplished developer herself ran a delete statement (this was last month).... It took the whole application down for 5 days!

    Oh and it's the first time I got to use COUNT_BIG 😛

    ---------------------------------------------------------

    It takes a minimal capacity for rational thought to see that the corporate 'free press' is a structurally irrational and biased, and extremely violent, system of elite propaganda.
    David Edwards - Media lens[/url]

    Society has varying and conflicting interests; what is called objectivity is the disguise of one of these interests - that of neutrality. But neutrality is a fiction in an unneutral world. There are victims, there are executioners, and there are bystanders... and the 'objectivity' of the bystander calls for inaction while other heads fall.
    Howard Zinn

  • I have another question. Any implications running DBCC SHOW_STATISTICS on a live system with this big table?

    ---------------------------------------------------------

    It takes a minimal capacity for rational thought to see that the corporate 'free press' is a structurally irrational and biased, and extremely violent, system of elite propaganda.
    David Edwards - Media lens[/url]

    Society has varying and conflicting interests; what is called objectivity is the disguise of one of these interests - that of neutrality. But neutrality is a fiction in an unneutral world. There are victims, there are executioners, and there are bystanders... and the 'objectivity' of the bystander calls for inaction while other heads fall.
    Howard Zinn

  • No. Show statistics doesn't touch the table

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • With 2.6 billion rows, be mindful of those INT datatypes. You have probably already considered that, just throwing it out there.

  • nivek-224024 (5/21/2013)


    With 2.6 billion rows, be mindful of those INT datatypes. You have probably already considered that, just throwing it out there.

    Your comment is referring to the maximum 2,147,483,647 value for Int datatype?

    "Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho

  • Abu Dina (5/21/2013)


    We have a tall table that contains 2.6 billion rows

    Table structure:

    The application which uses this table has been running slow for the last couple of days and it seems to have happened following the addition of about 400 million rows last weekend.

    I think it's because of the index fragmentation although I'm not sure how to check if this the case without affecting the application?

    So my first question is, how do I check to see if the indexes are fragmented and whether the stats need updating on such a large table?

    I notice that your clustered index is on IX_dType. Why was that column chosen to cluster the table. Especially for tables with a large number of rows, you typically want to cluster on a column with unique sequential values. There could very well be fragmentation.

    "Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho

  • Try running below query, will return you tables list with last statistic updated date and rows updated later on, these tables requires a statistics update with FullScan

    SELECT OBJECT_NAME(id),name,STATS_DATE(id, indid),rowmodctr

    FROM sys.sysindexes

    WHERE STATS_DATE(id, indid)<=DATEADD(DAY,-1,GETDATE())

    AND rowmodctr>0

    AND id IN (SELECT object_id FROM sys.tables)

  • I would disagree there, stats that are more than a day old and have a single row change absolutely do not need updating. That's almost as bad as blanket updating everything.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 15 posts - 1 through 15 (of 22 total)

You must be logged in to reply to this topic. Login to reply