Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

Use Caution with SQL Server's MERGE Statement

$
0
0
Problem SQL Server 2008 introduced the MERGE statement, which promised to be a simpler way to combine insert/update/delete
statements, such as those used during ETL (extract, transform and load) operations.
However, MERGE originally shipped with several "wrong results" and other bugs -
some of which have been addressed, and some of which continue to exist in current
versions. People also tend to make some leaps of faith regarding atomicity - they
don't realize that the single statement actually performs different operations separately,
and thus can suffer from issues due to concurrency and race conditions just like
separate statements can. Solution I have been recommending that - for now - people stick to their tried and true
methods of separate statements. Here are the major reasons: Bugs with the SQL Server Merge Statement It can be quite difficult to validate and guarantee that you are immune from
any of the bugs that still exist. A few Connect items that you should be aware of,
that are either still active, closed as "Won't Fix"/"By Design", or have only been
fixed in specific versions (often requiring a cumulative update or on-demand hotfix): Connect issue Current / last known status #773895 : MERGE Incorrectly Reports Unique Key Violations Won't Fix #771336 : Indexed view is not updated on data changes in base table Fixed only in 2012+ #766165 : MERGE evaluates filtered index per row, not post operation, which
causes filtered index violation Won't Fix #723696 : Basic MERGE upsert causing deadlocks By Design #713699 : A system assertion check has failed ("cxrowset.cpp":1528) Won't Fix #699055 : MERGE query plans allow FK and CHECK constraint violations Active #685800 : Parameterized DELETE and MERGE Allow Foreign Key Constraint Violations Won't Fix #654746 : merge in SQL2008 SP2 still suffers from "Attempting to set a non-NULL-able
column's value to NULL" Active #635778 : NOT MATCHED and MATCHED parts of a SQL MERGE statement are not
optimized Won't Fix #633132 : MERGE INTO WITH FILTERED SOURCE does not work properly Won't Fix #596086 : MERGE statement bug when INSERT/DELETE used and filtered index Won't Fix #583719 : MERGE statement treats non-nullable computed columns incorrectly
in some scenarios Won't Fix #581548 : SQL2008 R2 Merge statement with only table variables fails Fixed only in 2012+ #539084 : Search condition on a non-key column and an ORDER BY in source
derived table breaks MERGE completely Won't Fix #357419 : MERGE statement bypasses Referential Integrity Fixed only in 2012+ Merge statement fails when running db in Simple recovery model (2016) Fixed only with trace flag 692 MERGE statement assertion error when database is in simple recovery model
(2017) Fixed only with trace flag 692 MERGE and INSERT with COLUMNSTORE index creates crash dump Unacknowledged SupportMERGEINTO target for memory optimized tables Under Review

Viewing all articles
Browse latest Browse all 3160

Latest Images

Trending Articles