You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/relational-databases/data-compression/data-compression.md
+21-16Lines changed: 21 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,7 @@ For columnstore tables and indexes, all columnstore tables and indexes always us
42
42
- For partitioned columnstore tables and columnstore indexes, you can configure the archival compression option for each partition, and the various partitions do not have to have the same archival compression setting.
43
43
44
44
> [!NOTE]
45
-
> Data can also be compressed using the GZIP algorithm format. This is an additional step and is most suitable for compressing portions of the data when archiving old data for long-term storage. Data compressed using the COMPRESS function cannot be indexed. For more information, see [COMPRESS (Transact-SQL)](../../t-sql/functions/compress-transact-sql.md).
45
+
> Data can also be compressed using the GZIP algorithm format. This is an additional step and is most suitable for compressing portions of the data when archiving old data for long-term storage. Data compressed using the `COMPRESS` function cannot be indexed. For more information, see [COMPRESS (Transact-SQL)](../../t-sql/functions/compress-transact-sql.md).
46
46
47
47
## Considerations for When You Use Row and Page Compression
48
48
When you use row and page compression, be aware the following considerations:
@@ -51,7 +51,7 @@ For columnstore tables and indexes, all columnstore tables and indexes always us
51
51
- Compression is not available in every edition of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)]. For more information, see [Features Supported by the Editions of SQL Server 2016](~/sql-server/editions-and-supported-features-for-sql-server-2016.md).
52
52
- Compression is not available for system tables.
53
53
- Compression can allow more rows to be stored on a page, but does not change the maximum row size of a table or index.
54
-
- A table cannot be enabled for compression when the maximum row size plus the compression overhead exceeds the maximum row size of 8060 bytes. For example, a table that has the columns c1**char(8000)** and c2**char(53)** cannot be compressed because of the additional compression overhead. When the vardecimal storage format is used, the row-size check is performed when the format is enabled. For row and page compression, the row-size check is performed when the object is initially compressed, and then checked as each row is inserted or modified. Compression enforces the following two rules:
54
+
- A table cannot be enabled for compression when the maximum row size plus the compression overhead exceeds the maximum row size of 8060 bytes. For example, a table that has the columns `c1 CHAR(8000)` and `c2 CHAR(53)` cannot be compressed because of the additional compression overhead. When the vardecimal storage format is used, the row-size check is performed when the format is enabled. For row and page compression, the row-size check is performed when the object is initially compressed, and then checked as each row is inserted or modified. Compression enforces the following two rules:
55
55
- An update to a fixed-length type must always succeed.
56
56
- Disabling data compression must always succeed. Even if the compressed row fits on the page, which means that it is less than 8060 bytes; [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] prevents updates that would not fit on the row when it is uncompressed.
57
57
- When a list of partitions is specified, the compression type can be set to ROW, PAGE, or NONE on individual partitions. If the list of partitions is not specified, all partitions are set with the data compression property that is specified in the statement. When a table or index is created, data compression is set to NONE unless otherwise specified. When a table is modified, the existing compression is preserved unless otherwise specified.
@@ -60,8 +60,8 @@ For columnstore tables and indexes, all columnstore tables and indexes always us
60
60
- When a clustered index is created on a heap, the clustered index inherits the compression state of the heap unless an alternative compression state is specified.
61
61
- When a heap is configured for page-level compression, pages receive page-level compression only in the following ways:
62
62
- Data is bulk imported with bulk optimizations enabled.
63
-
- Data is inserted using INSERT INTO ... WITH (TABLOCK) syntax and the table does not have a nonclustered index.
64
-
- A table is rebuilt by executing the ALTER TABLE ... REBUILD statement with the PAGE compression option.
63
+
- Data is inserted using `INSERT INTO ... WITH (TABLOCK)` syntax and the table does not have a nonclustered index.
64
+
- A table is rebuilt by executing the `ALTER TABLE ... REBUILD` statement with the PAGE compression option.
65
65
- New pages allocated in a heap as part of DML operations do not use PAGE compression until the heap is rebuilt. Rebuild the heap by removing and reapplying compression, or by creating and removing a clustered index.
66
66
- Changing the compression setting of a heap requires all nonclustered indexes on the table to be rebuilt so that they have pointers to the new row locations in the heap.
67
67
- You can enable or disable ROW or PAGE compression online or offline. Enabling compression on a heap is single threaded for an online operation.
@@ -72,11 +72,11 @@ For columnstore tables and indexes, all columnstore tables and indexes always us
72
72
- Tables that implemented the vardecimal storage format in [!INCLUDE[ssVersion2005](../../includes/ssversion2005-md.md)], retain that setting when upgraded. You can apply row compression to a table that has the vardecimal storage format. However, because row compression is a superset of the vardecimal storage format, there is no reason to retain the vardecimal storage format. Decimal values gain no additional compression when you combine the vardecimal storage format with row compression. You can apply page compression to a table that has the vardecimal storage format; however, the vardecimal storage format columns probably will not achieve additional compression.
73
73
74
74
> [!NOTE]
75
-
> [!INCLUDE[ssCurrent](../../includes/sscurrent-md.md)] supports the vardecimal storage format; however, because row-level compression achieves the same goals, the vardecimal storage format is deprecated. [!INCLUDE[ssNoteDepFutureAvoid](../../includes/ssnotedepfutureavoid-md.md)]
75
+
> [!INCLUDE[ssCurrent](../../includes/sscurrent-md.md)] supports the vardecimal storage format; however, because row-level compression achieves the same goals, the vardecimal storage format is deprecated. [!INCLUDE[ssNoteDepFutureAvoid](../../includes/ssnotedepfutureavoid-md.md)]
76
76
77
77
## Using Columnstore and Columnstore Archive Compression
78
78
79
-
**Applies to**: [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] ( [!INCLUDE[ssSQL14](../../includes/sssql14-md.md)] through [current version](https://go.microsoft.com/fwlink/p/?LinkId=299658)), [!INCLUDE[ssSDSfull_md](../../includes/sssdsfull-md.md)].
79
+
**Applies to**: [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] ( [!INCLUDE[ssSQL14](../../includes/sssql14-md.md)] through [!INCLUDE[ssCurrent](../../includes/sscurrent-md.md)])), [!INCLUDE[ssSDSfull_md](../../includes/sssdsfull-md.md)].
80
80
81
81
### Basics
82
82
Columnstore tables and indexes are always stored with columnstore compression. You can further reduce the size of columnstore data by configuring an additional compression called archival compression. To perform archival compression, [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] runs the Microsoft XPRESS compression algorithm on the data. Add or remove archival compression by using the following data compression types:
@@ -86,7 +86,8 @@ For columnstore tables and indexes, all columnstore tables and indexes always us
86
86
To add archival compression, use [ALTER TABLE (Transact-SQL)](../../t-sql/statements/alter-table-transact-sql.md) or [ALTER INDEX (Transact-SQL)](../../t-sql/statements/alter-index-transact-sql.md) with the REBUILD option and DATA COMPRESSION = COLUMNSTORE_ARCHIVE.
87
87
88
88
#### Examples:
89
-
```
89
+
90
+
```sql
90
91
ALTERTABLE ColumnstoreTable1
91
92
REBUILD PARTITION =1 WITH (DATA_COMPRESSION = COLUMNSTORE_ARCHIVE) ;
92
93
@@ -101,7 +102,7 @@ To remove archival compression and restore the data to columnstore compression,
101
102
102
103
#### Examples:
103
104
104
-
```
105
+
```sql
105
106
ALTERTABLE ColumnstoreTable1
106
107
REBUILD PARTITION =1 WITH (DATA_COMPRESSION = COLUMNSTORE) ;
107
108
@@ -114,7 +115,7 @@ REBUILD PARTITION = ALL WITH (DATA_COMPRESSION = COLUMNSTORE ON PARTITIONS (2,4
114
115
115
116
This next example sets the data compression to columnstore on some partitions, and to columnstore archival on other partitions.
116
117
117
-
```
118
+
```sql
118
119
ALTERTABLE ColumnstoreTable1
119
120
REBUILD PARTITION = ALL WITH (
120
121
DATA_COMPRESSION = COLUMNSTORE ON PARTITIONS (4,5),
@@ -136,33 +137,37 @@ The procedure [sp_estimate_data_compression_savings (Transact-SQL)](../.
136
137
137
138
## How Compression Affects Partitioned Tables and Indexes
138
139
When you use data compression with partitioned tables and indexes, be aware of the following considerations:
139
-
- When partitions are split by using the ALTER PARTITION statement, both partitions inherit the data compression attribute of the original partition.
140
+
- When partitions are split by using the `ALTER PARTITION` statement, both partitions inherit the data compression attribute of the original partition.
140
141
- When two partitions are merged, the resultant partition inherits the data compression attribute of the destination partition.
141
142
- To switch a partition, the data compression property of the partition must match the compression property of the table.
142
143
- There are two syntax variations that you can use to modify the compression of a partitioned table or index:
143
144
- The following syntax rebuilds only the referenced partition:
144
-
```
145
+
146
+
```sql
145
147
ALTERTABLE<table_name>
146
148
REBUILD PARTITION =1 WITH (DATA_COMPRESSION =<option>)
147
149
```
150
+
148
151
- The following syntax rebuilds the whole table by using the existing compression setting for any partitions that are not referenced:
149
-
```
152
+
153
+
```sql
150
154
ALTER TABLE <table_name>
151
155
REBUILD PARTITION = ALL
152
156
WITH (DATA_COMPRESSION = PAGE ON PARTITIONS(<range>),
153
157
... )
154
158
```
155
159
156
-
Partitioned indexes follow the same principle using ALTER INDEX.
160
+
Partitioned indexes follow the same principle using `ALTER INDEX`.
157
161
158
162
- When a clustered index is dropped, the corresponding heap partitions retain their data compression setting unless the partitioning scheme is modified. If the partitioning scheme is changed, all partitions are rebuilt to an uncompressed state. To drop a clustered index and change the partitioning scheme requires the following steps:
159
163
1. Drop the clustered index.
160
-
2. Modify the table by using the ALTER TABLE ... REBUILD ... option that specifies the compression option.
164
+
2. Modify the table by using the `ALTER TABLE ... REBUILD` option that specifies the compression option.
161
165
162
166
To drop a clustered index OFFLINE is a very fast operation, because only the upper levels of clustered indexes are removed. When a clustered index is dropped ONLINE, [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] must rebuild the heap two times, once for step 1and once for step 2.
163
167
164
168
## How Compression Affects Replication
165
-
**Applies to**: [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] ( [!INCLUDE[ssSQL14](../../includes/sssql14-md.md)] through [current version](https://go.microsoft.com/fwlink/p/?LinkId=299658)).
169
+
**Applies to**: [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] ([!INCLUDE[ssSQL14](../../includes/sssql14-md.md)] through [!INCLUDE[ssCurrent](../../includes/sscurrent-md.md)])).
170
+
166
171
When you are using data compression with replication, be aware of the following considerations:
167
172
- When the Snapshot Agent generates the initial schema script, the new schema uses the same compression settings for both the table and its indexes. Compression cannot be enabled on just the table and not the index.
168
173
- For transactional replication the article schema option determines what dependent objects and properties have to be scripted. For more information, see [sp_addarticle](../../relational-databases/system-stored-procedures/sp-addarticle-transact-sql.md).
@@ -180,7 +185,7 @@ The following table shows replication settings that control compression during r
180
185
|To compress the table on the Subscriber if all the partitions are compressed on the Publisher, but not replicate the partition scheme.|False|True|Checks if all the partitions are enabled for compression.<br /><br /> Scripts out compression at the table level.|
181
186
182
187
## How Compression Affects Other SQL Server Components
183
-
**Applies to**: [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] ([!INCLUDE[ssSQL14](../../includes/sssql14-md.md)] through [current version](https://go.microsoft.com/fwlink/p/?LinkId=299658)).
188
+
**Applies to**: [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] ([!INCLUDE[ssSQL14](../../includes/sssql14-md.md)] through [!INCLUDE[ssCurrent](../../includes/sscurrent-md.md)])).
184
189
185
190
Compression occurs in the storage engine and the data is presented to most of the other components of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] in an uncompressed state. This limits the effects of compression on the other components to the following:
0 commit comments