Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

Finding Forwarded Records SQL Server 2008

From Wiki

Jump to: navigation, search

HEAP tables and forwarded records are a major and overlooked performance problem.

To check for forwarded records in 2005 and 2008

  1. SELECT
  2.     OBJECT_NAME(ps.OBJECT_ID) AS TableName,
  3.     i.name AS IndexName,
  4.     ps.index_type_desc,
  5.     ps.page_count,
  6.     ps.avg_fragmentation_in_percent,
  7.     ps.forwarded_record_count
  8. FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, 'DETAILED') AS ps
  9. INNER JOIN sys.indexes AS i
  10.     ON ps.OBJECT_ID = i.OBJECT_ID
  11.         AND ps.index_id = i.index_id
  12. WHERE ps.forwarded_record_count > 0

For SQL Server 2008 you can REBUILD the table to fix this.

To test first create a table

  1. CREATE TABLE tst (ident INT IDENTITY(1,1),col1 CHAR(20) DEFAULT ('1'),col2 CHAR(10));

Then insert some records

  1. INSERT INTO tst (col2) VALUES ('2')
  2. GO 100

Then force the table to become 'bloated' or grow causing the rows to move to another page while leaving pointers

  1. ALTER TABLE tst ALTER COLUMN col1 CHAR(200);

Running the query above using the sys.dm_db_index_physical_stats DMV will show a forwarded_record_count of 70. To fix this you can simply do the following

  1. ALTER TABLE dbo.tst REBUILD

660 Rating: 4.0/5 (4 votes cast)