Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 43ed11e

Browse files
authored
Merge pull request #32516 from MicrosoftDocs/main
11/27/2024 AM Publish
2 parents 3420d1d + 0eea751 commit 43ed11e

2 files changed

Lines changed: 73 additions & 51 deletions

File tree

azure-sql/managed-instance/transact-sql-tsql-differences-sql-server.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: This article discusses the Transact-SQL (T-SQL) differences between
44
author: danimir
55
ms.author: danil
66
ms.reviewer: mathoma, bonova, danil, randolphwest
7-
ms.date: 11/22/2024
7+
ms.date: 11/27/2024
88
ms.service: azure-sql-managed-instance
99
ms.subservice: service-overview
1010
ms.topic: reference
@@ -471,7 +471,7 @@ Transport security is supported, dialog security isn't:
471471

472472
- `CREATE REMOTE SERVICE BINDING`isn't supported.
473473

474-
Service broker is enabled by default and can't be disabled. The following ALTER DATABASE options aren't supported:
474+
Service broker is enabled by default for newly created databases and can't be disabled. Service broker state for restored/migrated databases is inherited from the source database and can't be changed. The following ALTER DATABASE options aren't supported:
475475

476476
- `ENABLE_BROKER`
477477
- `DISABLE_BROKER`
Lines changed: 71 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
title: "Performance tuning with ordered columnstore indexes"
2+
title: "Performance Tuning With Ordered Columnstore Indexes"
33
description: "Learn more about how ordered columnstore indexes can benefit your query performance."
44
author: WilliamDAssafMSFT
55
ms.author: wiassaf
6-
ms.reviewer: nibruno; xiaoyul
7-
ms.date: 10/23/2024
6+
ms.reviewer: nibruno; xiaoyul, randolphwest
7+
ms.date: 11/25/2024
88
ms.service: sql
99
ms.subservice: performance
1010
ms.topic: conceptual
@@ -26,65 +26,74 @@ For ordered columnstore index availability, see [Ordered column index availabili
2626

2727
## Ordered vs. non-ordered clustered columnstore index
2828

29-
By default, for each table created without an index option, an internal component (index builder) creates a non-ordered clustered columnstore index (CCI) on it. Data in each column is compressed into a separate CCI rowgroup segment. There's metadata on each segment's value range, so segments that are outside the bounds of the query predicate aren't read from disk during query execution. CCI offers the highest level of data compression and reduces the size of segments to read so queries can run faster. However, because the index builder doesn't sort data before compressing them into segments, segments with overlapping value ranges could occur, causing queries to read more segments from disk and take longer to finish.
29+
By default, for each table created without an index option, an internal component (index builder) creates a non-ordered clustered columnstore index (CCI) on it. Data in each column is compressed into a separate CCI rowgroup segment. There's metadata on each segment's value range, so segments that are outside the bounds of the query predicate aren't read from disk during query execution. CCI offers the highest level of data compression and reduces the size of segments to read so queries can run faster. However, because the index builder doesn't sort data before compressing them into segments, segments with overlapping value ranges could occur, causing queries to read more segments from disk and take longer to finish.
3030

31-
When creating an ordered CCI, the SQL Database Engine sorts the existing data in memory by the order key(s) before the index builder compresses them into index segments. With sorted data, segment overlapping is reduced allowing queries to have a more efficient segment elimination and thus faster performance because the number of segments to read from disk is smaller. If all data can be sorted in memory at once, then segment overlapping can be avoided. Due to large tables in data warehouses, this scenario doesn't happen often.
31+
When you create an ordered CCI, the SQL Database Engine sorts the existing data in memory by the order keys before the index builder compresses them into index segments. With sorted data, segment overlapping is reduced allowing queries to have a more efficient segment elimination and thus faster performance because the number of segments to read from disk is smaller. If all data can be sorted in memory at once, then segment overlapping can be avoided. Due to large tables in data warehouses, this scenario doesn't happen often.
3232

3333
To check the segment ranges for a column, run the following command with your table name and column name:
3434

3535
```sql
36-
SELECT
37-
o.name, pnp.index_id,
38-
cls.row_count, pnp.data_compression_desc,
39-
cls.segment_id,
40-
cls.column_id,
41-
cls.min_data_id, cls.max_data_id,
42-
cls.max_data_id-cls.min_data_id as difference
43-
36+
SELECT o.name,
37+
pnp.index_id,
38+
cls.row_count,
39+
pnp.data_compression_desc,
40+
cls.segment_id,
41+
cls.column_id,
42+
cls.min_data_id,
43+
cls.max_data_id,
44+
cls.max_data_id - cls.min_data_id AS difference
4445
FROM sys.partitions AS pnp
45-
INNER JOIN sys.tables AS t ON pnp.object_id = t.object_id
46-
INNER JOIN sys.objects AS o ON t.object_id = o.object_id
47-
INNER JOIN sys.column_store_segments AS cls ON pnp.partition_id = cls.partition_id
48-
INNER JOIN sys.columns as cols ON o.object_id = cols.object_id AND cls.column_id = cols.column_id
49-
WHERE o.name = '<Table Name>' and cols.name = '<Column Name>'
46+
INNER JOIN sys.tables AS t
47+
ON pnp.object_id = t.object_id
48+
INNER JOIN sys.objects AS o
49+
ON t.object_id = o.object_id
50+
INNER JOIN sys.column_store_segments AS cls
51+
ON pnp.partition_id = cls.partition_id
52+
INNER JOIN sys.columns AS cols
53+
ON o.object_id = cols.object_id
54+
AND cls.column_id = cols.column_id
55+
WHERE o.name = '<Table Name>'
56+
AND cols.name = '<Column Name>'
5057
ORDER BY o.name, pnp.index_id, cls.min_data_id;
5158
```
5259

5360
> [!NOTE]
54-
> In an ordered CCI table, the new data resulting from the same batch of DML or data loading operations are sorted within that batch, there is no global sorting across all data in the table. Users can REBUILD the ordered CCI to sort all data in the table. For a partitioned table, the REBUILD is done one partition at a time. Data in the partition that is being rebuilt is "offline" and unavailable until the REBUILD is complete for that partition.
61+
> In an ordered CCI table, the new data resulting from the same batch of DML or data loading operations are sorted within that batch, there's no global sorting across all data in the table. Users can REBUILD the ordered CCI to sort all data in the table. For a partitioned table, the REBUILD is done one partition at a time. Data in the partition that is being rebuilt is "offline" and unavailable until the REBUILD is complete for that partition.
5562
5663
## Query performance
5764

5865
A query's performance gain from an ordered CCI depends on the query patterns, the size of data, how well the data is sorted, the physical structure of segments, and the DWU and resource class chosen for the query execution. Users should review all these factors before choosing the ordering columns when designing an ordered CCI table.
5966

60-
Queries with all these patterns typically run faster with ordered CCI.
67+
Queries with all these patterns typically run faster with ordered CCI.
6168

6269
- The queries have equality, inequality, or range predicates
6370
- The predicate columns and the ordered CCI columns are the same.
6471

6572
In this example, table `T1` has a clustered columnstore index ordered in the sequence of `Col_C`, `Col_B`, and `Col_A`.
6673

6774
```sql
68-
CREATE CLUSTERED COLUMNSTORE INDEX MyOrderedCCI ON T1
69-
ORDER (Col_C, Col_B, Col_A);
75+
CREATE CLUSTERED COLUMNSTORE INDEX MyOrderedCCI
76+
ON T1 ORDER(Col_C, Col_B, Col_A);
7077
```
7178

7279
The performance of query 1 and query 2 can benefit more from ordered CCI than the other queries, as they reference all the ordered CCI columns.
7380

7481
```sql
7582
-- Query #1:
76-
77-
SELECT * FROM T1 WHERE Col_C = 'c' AND Col_B = 'b' AND Col_A = 'a';
83+
SELECT * FROM T1
84+
WHERE Col_C = 'c' AND Col_B = 'b' AND Col_A = 'a';
7885

7986
-- Query #2
80-
81-
SELECT * FROM T1 WHERE Col_B = 'b' AND Col_C = 'c' AND Col_A = 'a';
87+
SELECT * FROM T1
88+
WHERE Col_B = 'b' AND Col_C = 'c' AND Col_A = 'a';
8289

8390
-- Query #3
84-
SELECT * FROM T1 WHERE Col_B = 'b' AND Col_A = 'a';
91+
SELECT * FROM T1
92+
WHERE Col_B = 'b' AND Col_A = 'a';
8593

8694
-- Query #4
87-
SELECT * FROM T1 WHERE Col_A = 'a' AND Col_C = 'c';
95+
SELECT * FROM T1
96+
WHERE Col_A = 'a' AND Col_C = 'c';
8897
```
8998

9099
## Data loading performance
@@ -95,41 +104,50 @@ The performance of data loading into an ordered CCI table is similar to a partit
95104

96105
The number of overlapping segments depends on the size of data to sort, the available memory, and the maximum degree of parallelism (MAXDOP) setting during ordered CCI creation. The following strategies reduce segment overlapping when creating ordered CCI.
97106

98-
- Create ordered CCI with `OPTION (MAXDOP = 1)`. Each thread used for ordered CCI creation works on a subset of data and sorts it locally. There's no global sorting across data sorted by different threads. Using parallel threads can reduce the time to create an ordered CCI but will generate more overlapping segments than using a single thread. Using a single threaded operation delivers the highest compression quality. You can specify MAXDOP with the `CREATE INDEX` or `CREATE TABLE` commands. For example:
107+
- Create ordered CCI with `OPTION (MAXDOP = 1)`. Each thread used for ordered CCI creation works on a subset of data and sorts it locally. There's no global sorting across data sorted by different threads. Using parallel threads can reduce the time to create an ordered CCI but generate more overlapping segments than using a single thread. Using a single threaded operation delivers the highest compression quality. You can specify MAXDOP with the `CREATE INDEX` or `CREATE TABLE` commands. For example:
99108

100109
```sql
101-
CREATE TABLE Table1 WITH (DISTRIBUTION = HASH(c1), CLUSTERED COLUMNSTORE INDEX ORDER(c1) )
102-
AS SELECT * FROM ExampleTable
110+
CREATE TABLE Table1 WITH (
111+
DISTRIBUTION = HASH(c1), CLUSTERED COLUMNSTORE INDEX ORDER(c1)
112+
) AS
113+
SELECT *
114+
FROM ExampleTable
103115
OPTION (MAXDOP 1);
104116
```
105117

106-
- Pre-sort the data by the sort key(s) before loading them into tables.
118+
- Pre-sort the data by the sort keys before loading them into tables.
107119

108120
Here's an example of an ordered CCI table distribution that has zero segment overlapping following above recommendations. The ordered CCI is ordered on a **bigint** column with no duplicates.
109121

110122
:::image type="content" source="media/ordered-columnstore-indexes/perfect-sorting-example.png" alt-text="Screenshot of text data showing no segment overlapping.":::
111123

112124
## Create ordered CCI on large tables
113125

114-
Creating an ordered CCI is an offline operation. For tables with no partitions, the data won't be accessible to users until the ordered CCI creation process completes. For partitioned tables, since the engine creates the ordered CCI partition by partition, users can still access the data in partitions where ordered CCI creation isn't in process. You can use this option to minimize the downtime during ordered CCI creation on large tables:
126+
Creating an ordered CCI is an offline operation. For tables with no partitions, the data isn't accessible to users until the ordered CCI creation process completes. For partitioned tables, since the engine creates the ordered CCI partition by partition, users can still access the data in partitions where ordered CCI creation isn't in process. You can use this option to minimize the downtime during ordered CCI creation on large tables:
115127

116128
1. Create partitions on the target large table (called `Table_A`).
129+
117130
1. Create an empty ordered CCI table (called `Table_B`) with the same table and partition schema as `Table_A`.
131+
118132
1. Switch one partition from `Table_A` to `Table_B`.
119-
1. Run `ALTER INDEX <Ordered_CCI_Index> ON <Table_B> REBUILD PARTITION = <Partition_ID>` to rebuild the switched-in partition on `Table_B`.
133+
134+
1. Run `ALTER INDEX <Ordered_CCI_Index> ON <Table_B> REBUILD PARTITION = <Partition_ID>` to rebuild the switched-in partition on `Table_B`.
135+
120136
1. Repeat step 3 and 4 for each partition in `Table_A`.
121-
1. Once all partitions are switched from `Table_A` to `Table_B` and have been rebuilt, drop `Table_A`, and rename `Table_B` to `Table_A`.
137+
138+
1. Once all partitions are switched from `Table_A` to `Table_B` and rebuilt, drop `Table_A`, and rename `Table_B` to `Table_A`.
122139

123140
## SQL Server 2022 capabilities
124141

125-
SQL Server 2022 (16.x) introduced ordered clustered columnstore indexes similar to the feature in Azure Synapse dedicated SQL pools.
142+
[!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] introduced ordered clustered columnstore indexes similar to the feature in Azure Synapse dedicated SQL pools.
143+
144+
- [!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] and later versions and other SQL platforms support clustered columnstore enhanced [segment elimination](columnstore-indexes-design-guidance.md) capabilities for string, binary, and GUID data types, and the **datetimeoffset** data type for scale greater than two. Previously, this segment elimination applies to numeric, date, and time data types, and the **datetimeoffset** data type with scale less than or equal to two.
126145

127-
- SQL Server 2022 (16.x) and later versions and other SQL platforms support clustered columnstore enhanced [segment elimination](/sql/relational-databases/indexes/columnstore-indexes-design-guidance) capabilities for string, binary, and guid data types, and the **datetimeoffset** data type for scale greater than two. Previously, this segment elimination applies to numeric, date, and time data types, and the **datetimeoffset** data type with scale less than or equal to two.
128-
- Currently, only SQL Server 2022 (16.x) and later versions and other SQL platforms support clustered columnstore rowgroup elimination for the prefix of `LIKE` predicates, for example `column LIKE 'string%'`. Segment elimination is not supported for non-prefix use of LIKE such as `column LIKE '%string'`.
146+
- Currently, only [!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] and later versions, and other SQL platforms, support clustered columnstore rowgroup elimination for the prefix of `LIKE` predicates, for example `column LIKE 'string%'`. Segment elimination isn't supported for non-prefix use of `LIKE` such as `column LIKE '%string'`.
129147

130148
For ordered columnstore index availability, see [Ordered column index availability](columnstore-indexes-overview.md#ordered-columnstore-index-availability).
131149

132-
For more information, see [What's New in Columnstore Indexes](/sql/relational-databases/indexes/columnstore-indexes-what-s-new).
150+
For more information, see [What's new in columnstore indexes](columnstore-indexes-what-s-new.md).
133151

134152
For information on ordered columnstore indexes in dedicated SQL pools in Azure Synapse Analytics, see [Performance tuning with ordered clustered columnstore indexes](ordered-columnstore-indexes.md).
135153

@@ -138,27 +156,31 @@ For information on ordered columnstore indexes in dedicated SQL pools in Azure S
138156
**A. To check for ordered columns and order ordinal:**
139157

140158
```sql
141-
SELECT object_name(c.object_id) table_name, c.name column_name, i.column_store_order_ordinal
142-
FROM sys.index_columns i
143-
JOIN sys.columns c ON i.object_id = c.object_id AND c.column_id = i.column_id
144-
WHERE column_store_order_ordinal <>0;
159+
SELECT object_name(c.object_id) AS table_name,
160+
c.name AS column_name,
161+
i.column_store_order_ordinal
162+
FROM sys.index_columns AS i
163+
INNER JOIN sys.columns AS c
164+
ON i.object_id = c.object_id
165+
AND c.column_id = i.column_id
166+
WHERE column_store_order_ordinal <> 0;
145167
```
146168

147169
**B. To change column ordinal, add or remove columns from the order list, or to change from CCI to ordered CCI:**
148170

149171
```sql
150-
CREATE CLUSTERED COLUMNSTORE INDEX InternetSales ON dbo.InternetSales
151-
ORDER (ProductKey, SalesAmount)
152-
WITH (DROP_EXISTING = ON);
172+
CREATE CLUSTERED COLUMNSTORE INDEX InternetSales
173+
ON dbo.InternetSales ORDER(ProductKey, SalesAmount)
174+
WITH (DROP_EXISTING = ON);
153175
```
154176

155177
## Related content
156178

157-
- [Columnstore Index Design Guidelines](../../relational-databases/sql-server-index-design-guide.md#columnstore_index)
179+
- [Columnstore Index Design Guidelines](../sql-server-index-design-guide.md#columnstore_index)
158180
- [Columnstore indexes - Data loading guidance](columnstore-indexes-data-loading-guidance.md)
159-
- [Get started with Columnstore for real-time operational analytics](get-started-with-columnstore-for-real-time-operational-analytics.md)
181+
- [Get started with columnstore indexes for real-time operational analytics](get-started-with-columnstore-for-real-time-operational-analytics.md)
160182
- [Columnstore indexes in data warehousing](columnstore-indexes-data-warehouse.md)
161183
- [Optimize index maintenance to improve query performance and reduce resource consumption](reorganize-and-rebuild-indexes.md)
162-
- [Columnstore Index Architecture](../../relational-databases/sql-server-index-design-guide.md#columnstore_index)
184+
- [Columnstore Index Architecture](../sql-server-index-design-guide.md#columnstore_index)
163185
- [CREATE INDEX (Transact-SQL)](../../t-sql/statements/create-index-transact-sql.md)
164186
- [ALTER INDEX (Transact-SQL)](../../t-sql/statements/alter-index-transact-sql.md)

0 commit comments

Comments
 (0)