I have an application where performance is very critical issue. The application has 50.000 users with a lot of searches. Currently I store country code as char(2) in users table and then I retrieve country from countries php array.
$countries = array("AF"=>"Afghanistan","AL"=>"Albania",...)
I do similar with about 6 more attributes and all of them has similar number of values. This is helpful because no join is needed.
Speaking only about performance, what would be faster, to keep storing country names and other attributes in array or making for each attribute join with another table where names for each code would be stored?
It really depends on where your performance bottleneck is. If you have nice tables in your database with proper indexes, your DB will return the data nice and quick. If it is your DB that is being smashed though, that might make a difference that isnt good.
On the other hand, if your server is very heavy on the CPU cycles and is maxing out constantly, let the DB handle the join. The other thing to consider is memory use – an array with country codes isn’t a big thing, but an array with a list of products in it, that might suck up some ram – and if you have a lot of concurrent users, that might not be a good thing for performance.