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

Commit fef662d

Browse files
authored
Merge pull request #21962 from mstehrani/patch-7
Suggestion for handling inconsistencies
2 parents 057a96e + 686cda0 commit fef662d

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

docs/t-sql/statements/merge-transact-sql.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -277,27 +277,43 @@ Specifies the graph match pattern. For more information about the arguments for
277277
>[!IMPORTANT]
278278
> 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.
279279
>
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**
282283
> - The MERGE T-SQL statement was executed on a HASH distributed TARGET table in Azure Synapse SQL database AND
283284
> - The TARGET table of the MERGE has secondary indices or a UNIQUE constraint.
284285
>
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.
286290
> - 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.
287291
> - 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.
288292
> - This fix doesn't repair tables already affected by the MERGE problem. Use scripts below to identify and repair any affected tables manually.
289293
>
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
291299
>```sql
300+
> -- Case 1
292301
> select a.name, c.distribution_policy_desc, b.type from sys.tables a join sys.indexes b
293302
> on a.object_id = b.object_id
294303
> join
295304
> sys.pdw_table_distribution_properties c
296305
> on a.object_id = c.object_id
297-
> where b.type = 2 and c.distribution_policy_desc = 'HASH'
306+
> where b.type = 2 and c.distribution_policy_desc = 'HASH';
307+
>
308+
> -- Subject to Case 2, if distribution key value is updated in MERGE statement
309+
> select a.name, c.distribution_policy_desc from sys.tables a
310+
> join
311+
> sys.pdw_table_distribution_properties c
312+
> on a.object_id = c.object_id
313+
> where c.distribution_policy_desc = 'HASH';
298314
> ```
299315
>
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.
301317
>
302318
>```sql
303319
> 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
308324
> go
309325
>
310326
> 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>;
312328
> go
313329
>
314330
> create table [check_table_2] with(distribution = hash(x)) as
315331
> select x from [check_table_1];
316332
>go
317333
>
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
319335
> [check_table_2]) as tmp)
320336
> select 'no need for repair' as result
321337
> else select 'needs repair' as result
@@ -336,10 +352,10 @@ Specifies the graph match pattern. For more information about the arguments for
336352
> if object_id('[repair_table]', 'U') is not null
337353
> drop table [repair_table];
338354
> go
339-
> create table [repair_table_temp] with(distribution = round_robin) as select * from <MERGE_TARGET_TABLE>;
355+
> create table [repair_table_temp] with(distribution = round_robin) as select * from <MERGE_TABLE>;
340356
> go
341357
>
342-
> -- [repair_table] will hold the repaired table generated from <MERGE_TARGET_TABLE>
358+
> -- [repair_table] will hold the repaired table generated from <MERGE_TABLE>
343359
> create table [repair_table] with(distribution = hash(<DISTRIBUTION_COLUMN>)) as select * from [repair_table_temp];
344360
> go
345361
>if object_id('[repair_table_temp]', 'U') is not null

0 commit comments

Comments
 (0)