I read a lot of different things on the Internet about optimizing MySQL.
I have a table about friends. And I distinct 2 kinds of friends : The professional and the “social” (not professional) friends.
My question is :
Let’s say I have over 10 millions rows (5 millions professional and 5 millions social) of friends.
Is it better to have them all in a table with 3 columns
-idFriend1, -idFriend2, -isProfessional
Or is it better to have 2 tables (professional and non-professional friends) with only 2 columns (and only half the number of rows) ?
By the way, I will have to do some joining on this table so which is best with and without joining process ?
The evaluation of “best” depends on how you use these entities in the rest of your model, and what kind of queries you’d like to write.
If professional and social friends are really the same (other than their professional or social status), then I’d make just one table. If it turns out that professional friends have some different attributes — like job title, worked with at, company name — distinct from social friends (which might have things like favorite drink, favorite sport, and so on) you might find that two different subset tables are in order.
You might find, in fact, that three tables are in order: a friends table which lists the FriendID and all the common attributes (name, age, address); a professional friends table (which lists professional attributes for a FriendID); and a social friends table (which lists social attributes for a FriendID). This way, you have a super set for validation as an entity with all the common attributes, plus subset tables. You can also then decide if a friend could be both a social and a professional friend at the same time, with that flexibility.
As it stands, though, “best” is a tall order since we don’t know anything about how you plan to utilize the tables or how they will relate to the rest of your data model.