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/t-sql/statements/merge-transact-sql.md
+26-10Lines changed: 26 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -277,27 +277,43 @@ Specifies the graph match pattern. For more information about the arguments for
277
277
>[!IMPORTANT]
278
278
> Preview features are meant for testing only and should not be used on production instances or production data. Please also keep a copy of your test data if the data is important.
279
279
>
280
-
> In Azure Synapse Analytics the MERGE command, currently in preview, may, under certain conditions, leave the target table in an inconsistent state, with rows placed in the wrong distribution, causing later queries to return wrong results in some cases. This problem may happen when these two conditions are met:
281
-
>
280
+
> In Azure Synapse Analytics the MERGE command, currently in preview, may, under certain conditions, leave the target table in an inconsistent state, with rows placed in the wrong distribution, causing later queries to return wrong results in some cases. This problem may happen in 2 cases:
281
+
>
282
+
> **Case 1**
282
283
> - The MERGE T-SQL statement was executed on a HASH distributed TARGET table in Azure Synapse SQL database AND
283
284
> - The TARGET table of the MERGE has secondary indices or a UNIQUE constraint.
284
285
>
285
-
> The problem has been fixed in Synapse SQL version ***10.0.15563.0*** and higher.
286
+
> **Case 2**
287
+
> - The MERGE T-SQL statement updated a distribution key column of a HASH distributed table.
288
+
>
289
+
> **Case 1** has been fixed in Synapse SQL version ***10.0.15563.0*** and higher.
286
290
> - To check, connect to the Synapse SQL database via SQL Server Management Studio (SSMS) and run ```SELECT @@VERSION```. If the fix has not been applied, manually pause and resume your Synapse SQL pool to get the fix.
287
291
> - Until the fix has been verified applied to your Synapse SQL pool, avoid using the MERGE command on HASH distributed TARGET tables that have secondary indices or UNIQUE constraints.
288
292
> - This fix doesn't repair tables already affected by the MERGE problem. Use scripts below to identify and repair any affected tables manually.
289
293
>
290
-
> To check which hash distributed tables in a database cannot work with MERGE due to this issue, run this statement
294
+
> **Case 2** is pending fix.
295
+
> - Until further notice, avoid using the MERGE command to update distribution key columns in HASH distributed tables.
296
+
> - Use the scripts below to identify and repair any affected tables manually.
297
+
>
298
+
> To check which hash distributed tables in a database may be of concern (if used in the Cases above), run this statement
291
299
>```sql
300
+
>-- Case 1
292
301
>selecta.name, c.distribution_policy_desc, b.typefromsys.tables a joinsys.indexes b
>-- Subject to Case 2, if distribution key value is updated in MERGE statement
309
+
>selecta.name, c.distribution_policy_descfromsys.tables a
310
+
>join
311
+
>sys.pdw_table_distribution_properties c
312
+
>ona.object_id=c.object_id
313
+
>wherec.distribution_policy_desc='HASH';
298
314
>```
299
315
>
300
-
> To check if a hash distributed TARGET table for MERGE is affected by this issue, follow these steps to examine if the tables have rows landed in wrong distribution. If 'no need for repair' is returned, this table is not affected.
316
+
> To check if a hash distributed table for MERGE is affected by either Case 1 or Case 2, follow these steps to examine if the tables have rows landed in wrong distribution. If 'no need for repair' is returned, this table is not affected.
301
317
>
302
318
>```sql
303
319
> if object_id('[check_table_1]', 'U') is not null
@@ -308,14 +324,14 @@ Specifies the graph match pattern. For more information about the arguments for
308
324
> go
309
325
>
310
326
> create table [check_table_1] with(distribution = round_robin) as
311
-
>select<DISTRIBUTION_COLUMN>as x from<MERGE_TARGET_TABLE>group by<DISTRIBUTION_COLUMN>;
327
+
>select<DISTRIBUTION_COLUMN>as x from<MERGE_TABLE>group by<DISTRIBUTION_COLUMN>;
312
328
> go
313
329
>
314
330
> create table [check_table_2] with(distribution = hash(x)) as
315
331
>select x from [check_table_1];
316
332
>go
317
333
>
318
-
> if not exists(select top 1*from (select<DISTRIBUTION_COLUMN>as x from<MERGE_TARGET_TABLE> except select x from
334
+
> if not exists(select top 1*from (select<DISTRIBUTION_COLUMN>as x from<MERGE_TABLE> except select x from
319
335
> [check_table_2]) as tmp)
320
336
>select'no need for repair'as result
321
337
> else select'needs repair'as result
@@ -336,10 +352,10 @@ Specifies the graph match pattern. For more information about the arguments for
0 commit comments