Вы находитесь на странице: 1из 2

Estimating the Size of a Heap

You can use the following steps to estimate the amount of space that is required to store data in a heap: 1. Specify the number of rows that will be present in the table: Num_Rows = number of rows in the table

2.

Specify the number of fixed-length and ariable-length columns and calculate the space that is required for their storage: !alculate the space that each of these groups of columns occupies within the data row. "he si#e of a column depends on the data type and length specification. $or more information% see &ata "ypes '&atabase (ngine). Num_Cols = total number of columns 'fixed-length and ariable-length) Fixed_Data_Size = total byte si#e of all fixed-length columns Num_Variable_Cols = number of ariable-length columns Max_Var_Size = maximum byte si#e of all ariable-length columns

*.

+art of the row% ,nown as the null bitmap% is reser ed to manage column nullability. !alculate its si#e: Null_Bitmap = 2 - ''Num_Cols - .) / 0) 1nly the integer part of this expression should be used. &iscard any remainder.

2.

!alculate the ariable-length data si#e: 3f there are ariable-length columns in the table% determine how much space is used to store the columns within the row: Variable_Data_Size = 2 - 'Num_Variable_Cols x 2) - Max_Var_Size "his formula assumes that all ariable-length columns are 144 percent full. 3f you anticipate that a smaller percentage of the ariable-length column storage space will be used% you can ad5ust the Max_Var_Size alue by that percentage to yield a more accurate estimate of the o erall table si#e. Note S67 Ser er 2448 introduces the ability to combine varchar% nvarchar% varbinary% or sql_variant columns that cause the total defined table width to exceed 0%494 bytes. "he length of each one of these columns must still fall within the limit of 0%444 bytes for a varchar% varbinary% or sql_variant column% and 2%444 bytes for nvarchar columns. :owe er% their combined widths may exceed the 0%494 byte limit in a table. $or more information% see ;ow-1 erflow &ata (xceeding 0 <=. 3f there are no ariable-length columns% set Variable_Data_Size to 4.

8.

!alculate the total row si#e: Row_Size = Fixed_Data_Size - Variable_Data_Size - Null_Bitmap - 2 "he alue 2 in the formula is the row header o erhead of the data row.

9.

!alculate the number of rows per page '04>9 free bytes per page): Rows_Per_Page = 04>9 / 'Row_Size - 2) =ecause rows do not span pages% the number of rows per page should be rounded down to the nearest whole row. "he alue 2 in the formula is for the row?s entry in the slot array of the page.

..

!alculate the number of pages required to store all the rows: Num_Pages = Num_Rows / Rows_Per_Page "he number of pages estimated should be rounded up to the nearest whole page.

0.

!alculate the amount of space that is required to store the data in the heap '01>2 total bytes per page): :eap si#e 'bytes) = 01>2 x Num_Pages

"his calculation does not consider the following: +artitioning "he space o erhead from partitioning is minimal% but complex to calculate. 3t is not important to include. @llocation pages "here is at least one 3@A page used to trac, the pages allocated to a heap% but the space o erhead is minimal and there is no algorithm to deterministically calculate exactly how many 3@A pages will be used. 7arge ob5ect '71=) alues "he algorithm to determine exactly how much space will be used to store the 71= data types varchar(max)% varbinary(max)% nvarchar(max)% text% ntext xml% and image alues is complex. 3t is sufficient to 5ust add the a erage si#e of the 71= alues that are expected and add that to the total heap si#e.

Вам также может понравиться