Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

joins on ints vs joins on chars (or varchars)

Tags:

sql

join

Are there any performance drawbacks in SQL to joining a table on a char (or varchar) value, as opposed to say joining on an integer value?

like image 748
Aaron Fi Avatar asked Feb 25 '09 21:02

Aaron Fi


1 Answers

Joining on a char or var char will normally have an overhead as opposed to joining on an int. There are two factors I'm aware of when comparing chars:
- collation has to be taken account of
- char fields have more data to be compared*

*(each character is represented by 8 bits, a 10 char value is thus 80 bits long, compared to 32 bits for an int)

*(this is 16 bits per character if using NCHAR or NVARCHAR)

like image 90
MatBailie Avatar answered Oct 20 '22 07:10

MatBailie