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: azure-sql/managed-instance/transact-sql-tsql-differences-sql-server.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ description: This article discusses the Transact-SQL (T-SQL) differences between
4
4
author: danimir
5
5
ms.author: danil
6
6
ms.reviewer: mathoma, bonova, danil, randolphwest
7
-
ms.date: 11/22/2024
7
+
ms.date: 11/27/2024
8
8
ms.service: azure-sql-managed-instance
9
9
ms.subservice: service-overview
10
10
ms.topic: reference
@@ -471,7 +471,7 @@ Transport security is supported, dialog security isn't:
471
471
472
472
-`CREATE REMOTE SERVICE BINDING`isn't supported.
473
473
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:
title: "Performance tuning with ordered columnstore indexes"
2
+
title: "Performance Tuning With Ordered Columnstore Indexes"
3
3
description: "Learn more about how ordered columnstore indexes can benefit your query performance."
4
4
author: WilliamDAssafMSFT
5
5
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
8
8
ms.service: sql
9
9
ms.subservice: performance
10
10
ms.topic: conceptual
@@ -26,65 +26,74 @@ For ordered columnstore index availability, see [Ordered column index availabili
26
26
27
27
## Ordered vs. non-ordered clustered columnstore index
28
28
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.
30
30
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.
32
32
33
33
To check the segment ranges for a column, run the following command with your table name and column name:
34
34
35
35
```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_idas difference
43
-
36
+
SELECTo.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_idAS difference
44
45
FROMsys.partitionsAS pnp
45
-
INNER JOINsys.tablesAS t ONpnp.object_id=t.object_id
46
-
INNER JOINsys.objectsAS o ONt.object_id=o.object_id
> 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.
55
62
56
63
## Query performance
57
64
58
65
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.
59
66
60
-
Queries with all these patterns typically run faster with ordered CCI.
67
+
Queries with all these patterns typically run faster with ordered CCI.
61
68
62
69
- The queries have equality, inequality, or range predicates
63
70
- The predicate columns and the ordered CCI columns are the same.
64
71
65
72
In this example, table `T1` has a clustered columnstore index ordered in the sequence of `Col_C`, `Col_B`, and `Col_A`.
66
73
67
74
```sql
68
-
CREATE CLUSTERED COLUMNSTORE INDEX MyOrderedCCION 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);
70
77
```
71
78
72
79
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.
73
80
74
81
```sql
75
82
-- 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';
78
85
79
86
-- 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';
82
89
83
90
-- 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';
85
93
86
94
-- 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';
88
97
```
89
98
90
99
## Data loading performance
@@ -95,41 +104,50 @@ The performance of data loading into an ordered CCI table is similar to a partit
95
104
96
105
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.
97
106
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:
99
108
100
109
```sql
101
-
CREATETABLETable1 WITH (DISTRIBUTION = HASH(c1), CLUSTERED COLUMNSTORE INDEX ORDER(c1) )
102
-
ASSELECT*FROM ExampleTable
110
+
CREATETABLETable1 WITH (
111
+
DISTRIBUTION = HASH(c1), CLUSTERED COLUMNSTORE INDEX ORDER(c1)
112
+
) AS
113
+
SELECT*
114
+
FROM ExampleTable
103
115
OPTION (MAXDOP 1);
104
116
```
105
117
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.
107
119
108
120
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.
109
121
110
122
:::image type="content" source="media/ordered-columnstore-indexes/perfect-sorting-example.png" alt-text="Screenshot of text data showing no segment overlapping.":::
111
123
112
124
## Create ordered CCI on large tables
113
125
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:
115
127
116
128
1. Create partitions on the target large table (called `Table_A`).
129
+
117
130
1. Create an empty ordered CCI table (called `Table_B`) with the same table and partition schema as `Table_A`.
131
+
118
132
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
+
120
136
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`.
122
139
123
140
## SQL Server 2022 capabilities
124
141
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.
126
145
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'`.
129
147
130
148
For ordered columnstore index availability, see [Ordered column index availability](columnstore-indexes-overview.md#ordered-columnstore-index-availability).
131
149
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).
133
151
134
152
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).
135
153
@@ -138,27 +156,31 @@ For information on ordered columnstore indexes in dedicated SQL pools in Azure S
138
156
**A. To check for ordered columns and order ordinal:**
0 commit comments