環境:三地 (美國/荷蘭/深圳) SQL Server 異動複寫,Web 升級後頻繁報錯:
The query processor could not produce a query plan from the optimizer
because a query cannot update a text, ntext, or image column and a clustering key at the same time.
XXX_article 含 ntext 欄位 (文章內容)。ntext 欄位與叢集索引鍵 (如 ArticleID 或 CategoryID)。單一 UPDATE 陳述式不支援同時更新 LOB 型別 (text/ntext/image/varchar(max)/varbinary(max)) 與叢集索引鍵欄位。需拆分為兩個 UPDATE。
XXX_article。快照複寫不透過交易記錄逐筆重播,而是整表覆寫,繞過單一 UPDATE 限制。
-- 原寫法 (失敗)
UPDATE XXX_article SET Content = @Content, CategoryID = @CatID WHERE ArticleID = @ID;
-- 拆分為兩步 (成功)
UPDATE XXX_article SET CategoryID = @CatID WHERE ArticleID = @ID;
UPDATE XXX_article SET Content = @Content WHERE ArticleID = @ID;
優點:保留異動複寫即時性。
缺點:需修改應用程式碼、部署協調成本高。
此案例說明資料型別、索引設計與複寫機制的深度耦合,架構階段即應考量複寫相容性。