开发者

How significant is the performance difference when joining on nvarchar versus on int

开发者 https://www.devze.com 2023-03-15 23:06 出处:网络
I understand that join on nvarchar is slower because index is bigger as nvarchar using 2 bytes for each character but int is 4 bytes all the time. Is the join performance difference signifi开发者_Stac

I understand that join on nvarchar is slower because index is bigger as nvarchar using 2 bytes for each character but int is 4 bytes all the time. Is the join performance difference signifi开发者_StackOverflow中文版cant? Is there any strong reason to avoid join on nvarchar? I couldn't find any MSDN article about the topic.


At least 8x CPU. This is the measurable increase in comparing nvarchar over varchar: unicode sorting and comparison rules are more complex that straight varchar.

  • What are the main performance differences between varchar and nvarchar SQL Server data types?
  • SQL Server uses high CPU when searching inside nvarchar strings

So, assuming varchar and int are equal (they aren't) nvarchar will have overhead compared to int

Then, byte for byte ('1234' vs 1234) you're comparing 10 bytes vs 4 bytes. This also means a wider key for less index and data entries per page = more IO.

Finally, if your nvarchar is more then 450 characters, you can't index it because index key is max 900 bytes wide.

0

精彩评论

暂无评论...
验证码 换一张
取 消