5

Our company has many different entities, but a good chunk of those database entities are people. So we have customers, and employees, and potential clients, and contractors, and providers and all of them have certain attributes in common, namely names and contact phone numbers.

I may have gone overboard with object-oriented thinking but now I am looking at making one "Person" table that contains all of the people, with flags/subtables "extending" that model and adding role-based attributes to junction tables as necessary. If we grow to say 250.000 people (on MySQL and ISAM) will this so greatly impact performance that future DBAs will curse me forever? Our single most common search is on name/surname combinations.

For, e.g. a company like Salesforce, are Clients/Leads/Employees all in a centralised table with sub-views (for want of a better term) or are they separated into different tables?

Caveat: this question is to do with "we found it better to do this in the real world" as opposed to theoretical design. I like the above solution, and am confident that with views, proper sizing and accurate indexing, that performance won't suffer. I also feel that the above doesn't count as a MUCK, just a pretty big table.

5 Answers 5

1

One 'person' table is the most flexible, efficient, and trouble-free approach.

It will be easy for you to do limited searches - find all people with this last name and who are customers, for example. But you may also find you have to look up someone when you don't know what they are - that will be easiest when you have one 'person' table.

However, you must consider the possibility that one person is multiple things to you - a customer because the bought something and a contractor because you hired them for a job. It would be better, therefore, to have a 'join' table that gives you a many to many relationship.

create person_type (
   person_id int unsigned,
   person_type_id int unsigned,
   date_started datetime,
   date_ended datetime,
   [ ... ]
)

(You'll want to add indexes and foreign keys, of course. person_id is a FK to 'person' table; 'person_type_id' is a FK to your reference table for all possible person types. I've added two date fields so you can establish when someone was what to you.)

1
  • All the answers were exactly what I was looking for, but you nailed the one thing that I hadn't thought of - what if I don't know where that person is. The reason for the one main table is precisely because we have people in multiple roles, old customers who work for us and in different roles. Makes sense to centralise what's common. Thanks! Commented Mar 22, 2012 at 15:36
1

Since you have many different "types" of Persons, in order to have normalized design, with proper Foreign Key constraints, it's better to use the supertype/subtype pattern. One Person table (with the common to all attributes) and many subtype tables (Employee, Contractor, Customer, etc.), all in 1:1 relationship with the main Person table, and with necessary details for every type of Person.

Check this answer by @Branko for an example: Many-to-Many but sourced from multiple tables

0

250.000 records for a database is not very much. If you set your indexes appropriately you will never find any problems with that.

You should probably set a type for a user. Those types should be in a different table, so you can see what the type means (make it an TINYINT or similar). If you need additional fields per user type, you could indeed create a different table for that.

This approach sounds really good to me

1
  • Thanks for your answer, this was what I wanted to hear. I went with D Mac however because he pointed out something I hadn't thought of. Commented Mar 22, 2012 at 15:38
0

Theoretically it would be possible to be a customer for the company you work for.

But if that's not the case here, then you could store people in different tables depending on their role.

However like Topener said, 250.000 isn't much. So I would personally feel safe to store every single person in one table.

And then have a column for each role (employee, customer, etc.)

0

Even if you end up with a one table solution (for core person attributes), you are going to want to abstract it with views and put on some constraints.

The last thing you want to do is send confidential information to clients which was only supposed to go to employees because someone didn't join correctly. Or an accidental cross join which results in income being doubled on a report (but only for particular clients which also had an employee linked somehow).

It really depends on how you want the layers to look and which components are going to access which layers and how.

Also, I would think you want to revisit your choice of MyISAM over InnoDB.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.