SQL Server 2008 row data and page data compression decryption

Source: Internet
Author: User

The performance of SQL Server depends primarily on disk I/O efficiency, and improving I/O efficiency some program means improved performance. SQL Server 2008 provides data compression capabilities to improve disk I/O.

Data compression means reducing the disk footprint of the data, so data compression can be used in tables, clustered indexes, nonclustered indexes, view indexes, or partitioned tables, partitioned indexes.

Data compression can be implemented at two levels: row level and Page level. Page-level compression includes row-level compression. Tables and indexes can be compressed at the same time they are created, or you can use ALTER TABLE Rebuild with or ALTER index Rebuild with syntax to compress existing tables or indexes. When the compression state on the heap changes, all nonclustered indexes are rebuilt.

Let's look at what the compression process is doing.

Row compression:

    • 1. Reduce metadata header record data.
    • 2. All numeric types (integer,decimal,float) or types based on numeric types are compressed (Datetime,money). For example, 100 is present in an INT field, accounting for 4 bits, but only 1 bits are required from 0~255, and after compression, 3byte space is saved.
    • Both 3.Char and nchar are stored in variable-length types. The reason is ditto. For example, CSDN is present in char (10), but it requires only char (4) space, so it releases char (6) space after compression.
    • 4. All types of NULL and 0 do not account for bytes.

Page compression:

    • 1. Do row compression.
    • 2. Pre-Standard compression: All columns on each page, below the row header, each row is stored with a row definition value, and after compression, all row definition values are replaced by a reference to the header value.
    • 3. Dictionary compression: Dictionary compression is similar to pre-label compression. In pre-standard compression, a value that differs from other normal values is defined on each column. However, in dictionary compression, the normal value of all columns in each page is preceded by the next line of the wardrobe. These values are then replaced with the reference values of the new row.

Let's look at an example:

USE tempdb
GO
CREATE TABLE TestCompression (col1 INT, col2 CHAR(50))
GO
INSERT INTO TestCompression VALUES (10, ‘compression testing‘)
GO 5000
-- Original
EXEC sp_spaceused TestCompression
GO
-- DATA_COMPRESSION = ROW
ALTER TABLE TestCompression
REBUILD WITH (DATA_COMPRESSION = ROW);
GO
EXEC sp_spaceused TestCompression
GO
-- DATA_COMPRESSION = PAGE
ALTER TABLE TestCompression
REBUILD WITH (DATA_COMPRESSION = PAGE);
GO
EXEC sp_spaceused TestCompression
GO
-- DATA_COMPRESSION = NONE
ALTER TABLE TestCompression
REBUILD WITH (DATA_COMPRESSION = NONE);
GO
EXEC sp_spaceused TestCompression
GO

SQL Server 2008 row data and page data compression decryption

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.