I have a database table with 5 million rows. The clustered index is auto-increment identity column. There PK is a code generated 256 byte VARCHAR
which is a SHA
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
autoIncID
imageSHAID
to be a standalone unique index (not constraint) and add an INCLUDE for showCount
. Unique constraints can't have INCLUDEsMore observations:
nvarchar
for the hash or URL columns. These are not unicode.char(64)
(for SHA2-512).