SQL Server Storage Engine

Estimating the space savings with vardecimal storage format

Before enabling Vardecimal storage format, you may want to know the potential reduction in the size of the table. Clearly, if the table has no decimal/numeric columns, there will be no savings. Note, that even if you have a table with decimal/numeric column types, there is no guarantee that you will be able to reduce the size of the table by enabling Vardecimal storage format. Again, this issue is similar to VARCHAR (17) vs. CHAR(17). If all the values in the column type has 17 characters, then average row length will be larger with VARCHAR(17) because it will be stored in the variable portion of the record structure. Recall, you need 2 bytes to store the offset of the variable length column. Also, if VARCAHR(17)  is the only variable length column in the table, there is another overhead of 2 bytes to store number of variable length columns in the row.  So in this case, the worst case, declaring column type as VARCAHR(17) may cost you 4 bytes more for each row than CHAR(17). 

 

SQL Server 2005/SP2 provides you a tool, a stored procedure, to estimate the ‘reduction in row size’ with Vardecimal storage format. The following example illustrates the reduction in row size for two tables that have same scheme but different data, t_decimal being the best case and t_decimal2 being the worst case (where each decimal value has max 38 digits as allowed by the declared precision)

 

create table t_decimal (c1 int, c2 decimal(10,2), c3 decimal (38,2), c4 varchar(10))

go

 

create table t_decimal2 (c1 int, c2 decimal(10,2), c3 decimal (38,2), c4 varchar(10))

go

 

-- insert rows into these tables.

declare @i int

select @i = 0

while (@i < 1000)

begin

        insert into t_decimal values (1, 0.0,0.0, 'hello')

        insert into t_decimal2 values

                (1,12345678.99,123456789012345678901234567890123499.99, 'hello')

         set @i = @i + 1

end

 

-- Now let us find the potential space savings for each of these tables

-- This is the best case

exec sys.sp_estimated_rowsize_reduction_for_vardecimal 't_decimal'

 

Here is the output. Note, in this case, you can reduce the size of the row by almost 50%. Also, if you have more decimal/numeric columns, the savings will be proportionally larger.

 

avg_rowlen_fixed_format  avg_rowlen_vardecimal_format    row_count

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

46.00                      24.00                         1000

 

 

 

-- this is worst case. Note in this case, the average row length actually increases

-- with Vardecimal storage format.

--

exec sys.sp_estimated_rowsize_reduction_for_vardecimal 't_decimal2'

 

avg_rowlen_fixed_format  avg_rowlen_vardecimal_format   row_count

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

46.00                                 48.00                                       1000

 

 

In the next blog

http://blogs.msdn.com/sqlserverstorageengine/archive/2006/11/13/enabling-vardecimal-storage-format.aspx , I will discuss how to enable vardecimal storage format on the table

Published Monday, November 13, 2006 2:33 AM by Sunil Agarwal

Comments

 

SQL Server Storage Engine said:

An exciting new feature in SQL Server 2005/SP2 is Vardecimal Storage Format. This storage format lets

November 13, 2006 11:48 AM
 

河端善博の .TEXT でウェブログ said:

SQL Server 2005 SP2 では、decimal, numeric データ型利用時のディスクスペースが減る !? vardecimal とは.

February 7, 2007 7:42 AM
Anonymous comments are disabled

About Sunil Agarwal

Sunil Agarwal is a program manager in the SQL Server Storage Engine Group at Microsoft. He is responsible for concurrency, indexes, tempdb, LOBS, supportability, and bulk import/export. Prior to joining Microsoft, Sunil worked at DEC, Sybase, BMC Software and DigitalThink, focusing primarily on core database engine technologies and related applications.

© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker