Skip to content

Commit fc00ecf

Browse files
authored
Merge pull request #27747 from WilliamDAssafMSFT/20230716-set-recommendations-tsql
20230716 add SET RECOMMENDATIONS TSQL syntax
2 parents 0e70d43 + 9413331 commit fc00ecf

4 files changed

Lines changed: 101 additions & 6 deletions

File tree

docs/t-sql/statements/create-table-as-select-azure-sql-data-warehouse.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ Distributes the rows based on the hash values of up to eight columns, allowing f
116116
For details and to understand how to choose the best distribution column, see the [Table distribution options](create-table-azure-sql-data-warehouse.md#TableDistributionOptions) section in CREATE TABLE.
117117

118118

119+
For recommendations on the best distribution do to use based on your workloads, see the [Synapse SQL Distribution Advisor (Preview)](/azure/synapse-analytics/sql/distribution-advisor).
120+
119121
<a name="table-partition-options-bk"></a>
120122

121123
### Table partition options

docs/t-sql/statements/create-table-azure-sql-data-warehouse.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ title: CREATE TABLE
33
description: "CREATE TABLE creates a new table in Azure Synapse Analytics, Analytics Platform System (PDW), and Microsoft Fabric."
44
author: WilliamDAssafMSFT
55
ms.author: wiassaf
6-
ms.reviewer: vanto, xiaoyul, wiassaf, mariyaali, maghan, kecona
7-
ms.date: 07/12/2023
6+
ms.reviewer: vanto, xiaoyul, mariyaali, maghan, kecona
7+
ms.date: 07/16/2023
88
ms.service: sql
99
ms.topic: reference
1010
dev_langs:
@@ -158,13 +158,12 @@ Assigns each row to one distribution by hashing the value stored in *distributio
158158
`DISTRIBUTION = HASH ( [distribution_column_name [, ...n]] )`
159159
Distributes the rows based on the hash values of up to eight columns, allowing for more even distribution of the base table data, reducing the data skew over time and improving query performance.
160160

161-
>[!NOTE]
162-
>
163-
> - To enable the Multi-Column Distribution (MCD) feature, change the database's compatibility level to 50 with this command. For more information on setting the database compatibility level, see [ALTER DATABASE SCOPED CONFIGURATION](./alter-database-scoped-configuration-transact-sql.md). For example: `ALTER DATABASE SCOPED CONFIGURATION SET DW_COMPATIBILITY_LEVEL = 50;`
161+
> [!NOTE]
162+
> - To enable the multi-column distribution (MCD) feature, change the database's compatibility level to 50 with this command. For more information on setting the database compatibility level, see [ALTER DATABASE SCOPED CONFIGURATION](./alter-database-scoped-configuration-transact-sql.md). For example: `ALTER DATABASE SCOPED CONFIGURATION SET DW_COMPATIBILITY_LEVEL = 50;`
164163
> - To disable the Multi-Column distribution (MCD) feature, run this command to change the database's compatibility level to AUTO. For example: `ALTER DATABASE SCOPED CONFIGURATION SET DW_COMPATIBILITY_LEVEL = AUTO;` Existing MCD tables will stay but become unreadable. Queries over MCD tables will return this error: `Related table/view is not readable because it distributes data on multiple columns and multi-column distribution is not supported by this product version or this feature is disabled.`
165164
> - To regain access to MCD tables, enable the feature again.
166165
> - To load data into a MCD table, use CTAS statement and the data source needs be Synapse SQL tables.
167-
> - Using SSMS for [generating a script](../../ssms/scripting/generate-scripts-sql-server-management-studio.md) to create MCD tables is currently supported beyond SSMS version 19.
166+
> - [Generating a script](../../ssms/scripting/generate-scripts-sql-server-management-studio.md) to create MCD tables is currently supported SSMS version 19 and later versions.
168167
169168
`DISTRIBUTION = ROUND_ROBIN`
170169
Distributes the rows evenly across all the distributions in a round-robin fashion. This behavior is the default for [!INCLUDE[ssazuresynapse-md](../../includes/ssazuresynapse-md.md)].
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
title: "SET RECOMMENDATIONS (Transact-SQL)"
3+
description: "SET RECOMMENDATIONS enables or disables the Azure Synapse distribution advisor for the current session."
4+
author: mariyaali
5+
ms.author: mariyaali
6+
ms.reviewer: xiaoyul, wiassaf
7+
ms.date: 07/16/2023
8+
ms.service: synapse-analytics
9+
ms.topic: reference
10+
f1_keywords:
11+
- "SET RECOMMENDATIONS"
12+
- "RECOMMENDATIONS"
13+
helpviewer_keywords:
14+
- "SET RECOMMENDATIONS"
15+
- "RECOMMENDATIONS"
16+
dev_langs:
17+
- "TSQL"
18+
monikerRange: "=azure-sqldw-latest"
19+
---
20+
# SET RECOMMENDATIONS (Transact-SQL)
21+
22+
[!INCLUDE [asa](../../includes/applies-to-version/asa-dedicated-sqlpool-only.md)]
23+
24+
Enables or disables the Azure Synapse distribution advisor for the current session. For instructions and samples on the use of the distribution advisor, see [Distribution Advisor in Azure Synapse SQL](/azure/synapse-analytics/sql/distribution-advisor).
25+
26+
> [!NOTE]
27+
> Distribution Advisor is currently in preview for Azure Synapse Analytics. Preview features are meant for testing only and should not be used on production instances or production data. As a preview feature, Distribution Advisor is subject to undergo changes in behavior or functionality. Please also keep a copy of your test data if the data is important.
28+
29+
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
30+
31+
## Syntax
32+
33+
```syntaxsql
34+
SET RECOMMENDATIONS { ON | OFF };
35+
```
36+
37+
## Arguments
38+
39+
#### ON
40+
Enables Distribution Advisor for the current client session. Subsequently run queries will be taken into consideration for distribution strategy recommendations.
41+
42+
#### OFF
43+
Turns Distribution Advisor OFF for the current client session. Returns advice as a string.
44+
45+
## Remarks
46+
47+
Applies to [!INCLUDE [ssSDW](../../includes/ssazuresynapse_sqlpool_only.md)] only.
48+
49+
Run this command when connected to a user database.
50+
51+
## Permissions
52+
53+
Requires membership in the public role.
54+
55+
## Examples
56+
57+
Following example will return distribution recommendation on selected TPC-DS queries. TPC-DS is an industry standard benchmark for analytical decision support workloads.
58+
59+
First, begin the distribution advisor recommendation collection and run sample queries.
60+
61+
```sql
62+
-- Step 1: Turn the distribution advisor ON for the current client session
63+
SET RECOMMENDATIONS ON;
64+
GO
65+
66+
-- <insert your queries here, up to 100>
67+
SELECT ss_store_sk, COUNT(*) FROM store_sales, store WHERE ss_store_sk = s_store_sk GROUP BY ss_store_sk;
68+
69+
SELECT cs_item_sk, COUNT(*) FROM catalog_sales, item WHERE cs_item_sk = i_item_sk AND i_manufact_id > 100 GROUP BY cs_item_sk;
70+
71+
SELECT * FROM dbo.reason;
72+
73+
-- Turn the distribution advisor OFF for the current client session.
74+
SET RECOMMENDATIONS OFF;
75+
GO
76+
```
77+
78+
Collect recommendations from the dynamic management view `sys.dm_pdw_distrib_advisor_results` for the current session. For example:
79+
80+
```sql
81+
82+
-- Step 2: view advice generated for the above workload
83+
DECLARE @sessionid nvarchar(100), @recommendation nvarchar(max);
84+
SELECT @sessionid = SESSION_ID();
85+
SELECT @recommendation = recommendation FROM sys.dm_pdw_distrib_advisor_results WHERE session_id = @sessionid;
86+
SELECT @recommendation;
87+
GO
88+
```
89+
90+
## Next steps
91+
92+
- [Distribution Advisor in Azure Synapse SQL](/azure/synapse-analytics/sql/distribution-advisor)

docs/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18725,6 +18725,8 @@ items:
1872518725
href: t-sql/statements/set-query-governor-cost-limit-transact-sql.md
1872618726
- name: QUOTED_IDENTIFIER
1872718727
href: t-sql/statements/set-quoted-identifier-transact-sql.md
18728+
- name: RECOMMENDATIONS
18729+
href: t-sql/statements/set-recommendations-sql.md
1872818730
- name: REMOTE_PROC_TRANSACTIONS
1872918731
href: t-sql/statements/set-remote-proc-transactions-transact-sql.md
1873018732
- name: RESULT SET CACHING

0 commit comments

Comments
 (0)