I have 2 tables that their rows have one on one relation..
For you to understand the situation, suppose there is one table with user informations
and there is another table that contains a very specific informations and each user can only link to one these specific kind of informations ( suppose second table as characters )
And that character can only assign to the user who grabs it, Is it against the rules of designing clean databases to hold the relation key in both tables?
User Table: user_id, name, age, character_id
Character Table: character_id, shape, user_id
I have to do it for performance, how do you think about it?
Yes, I’d say it was against the rules of designing clean databases, as the data you have is repeated, therefore you have to actively maintain two sets of data at all times for fear they are out of sync. If you don’t do this, you can’t trust the data. 🙂
As a side note: You say you’re doing this for performance reasons? What benefits have you seen of doing this? As regardless of which table you access the data from, you should find (with proper indexes) that there is very little difference? It might be you are fixing the wrong issue here and maybe there are other things to look at first (like indexes, improving your queries etc).
Edit: Selecting free characters should be easy enough as you would get rid of the
character_idfrom the users table and only haveuser_idin the characters one:Then you would be able to do some queries like these:
Or is there more about your model that I’m maybe missing with this? (As I don’t pretend to know your database layout 😉 ). I’m assuming a one-to-many relationship, as it does appear to be that way (one user can have many characters).