Using Multi Column Unique Indexes vs Single Hashed Column

孤人 提交于 2019-12-11 10:29:15

问题


I've a table which I need to give unique constraint to multiple columns. But instead of creating multi column unique index, I can also introduce an extra column based on hashing of all the required fields. So which one will be more effective in terms of database performance?

MySQL suggests the hashed column method but I couldn't find any information regarding SqlServer.


回答1:


The link you give states:

If this column is short, reasonably unique, and indexed, it might be faster than a “wide” index on many columns.

So the performance improvement really relies on the indexed hash being quite a bit smaller than the combined multiple columns. This could easily not be the case, given that an MD5 is 16 bytes. I'd consider how much wider the average index key would be for the multi-columnindex, and to be honest I'd probably not bother with the hash anyway.

You could, if you feel inclined, benchmark your system with both approaches. And if the potential benefits don't tempt you into trying that, again I'd not bother.

I've used the technique more often for change detection, where checking for a change in 100 separate columns of a table row is much more compute intensive than comparing two hashes.



来源:https://stackoverflow.com/questions/34029921/using-multi-column-unique-indexes-vs-single-hashed-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!