SQL Server : MERGE performance

梦想与她 提交于 2019-12-01 08:16:21
gbn

Your UPDATE clause in the MERGE updates showCount. This requires a key lookup on the clustered index.

However, the clustered index is also declared non-unique. This gives information to the optimiser even though the underlying column is unique.

So, I'd make these changes

  • the clustered primary key to be autoIncID
  • the current PK on imageSHAID to be a standalone unique index (not constraint) and add an INCLUDE for showCount. Unique constraints can't have INCLUDEs

More observations:

  • you don't need nvarchar for the hash or URL columns. These are not unicode.
  • A hash is also fixed length so can be char(64) (for SHA2-512).
  • The length of a column defines how much memory to assign to the query. See this for more: is there an advantage to varchar(500) over varchar(8000)?
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!