Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database design: one huge table or separate tables?

Currently I am designing a database for use in our company. We are using SQL Server 2008. The database will hold data gathered from several customers. The goal of the database is to acquire aggregate benchmark numbers over several customers.

Recently, I have become worried with the fact that one table in particular will be getting very big. Each customer has approximately 20.000.000 rows of data, and there will soon be 30 customers in the database (if not more). A lot of queries will be done on this table. I am already noticing performance issues and users being temporarily locked out.

My question, will we be able to handle this table in the future, or is it better to split this table up into smaller tables for each customer?


Update: It has now been about half a year since we first created the tables. Following the advices below, I created a handful of huge tables. Since then, I have been experimenting with indexes and decided on a clustered index on the first two columns (Hospital code and Department code) on which we would have partitioned the table had we had Enterprise Edition. This setup worked fine until recently, as Galwegian predicted, performance issues are springing up. Rebuilding an index takes ages, users lock each other out, queries frequently take longer than they should, and for most queries it pays off to first copy the relevant part of the data into a temp table, create indices on the temp table and run the query. This is not how it should be. Therefore, we are considering to buy Enterprise Edition for use of partitioned tables. If the purchase cannot go through I plan to use a workaround to accomplish partitioning in Standard Edition.

like image 568
littlegreen Avatar asked May 04 '10 14:05

littlegreen


People also ask

Why is it better to have multiple separate tables?

Storing all data in one single table will be confusing, may have security issues and there will be duplication in recording. Multiple table helps in recording the data in more organized manner when there are multiple users.

Is it good to have many tables in a database?

In general, though, you should keep your number of tables small since MySQL can handle very large number of rows in the table. A large number of tables can make a huge difference if your application makes use of 'information_schema'. Nothing in 'information_schema' is cached.

How big is too big for a database table?

You can't have more than 1000 columns. Your records can't be bigger than 8k each. These limits change depending on database engine. (The ones here are for InnoDB.)

Is it used to combine more than one table?

Joins are used to combine the rows from multiple tables using mutual columns.


2 Answers

Start out with one large table, and then apply 2008's table partitioning capabilities where appropriate, if performance becomes an issue.

like image 78
Galwegian Avatar answered Sep 27 '22 17:09

Galwegian


Datawarehouses are supposed to be big (the clue is in the name). Twenty million rows is about medium by warehousing standards, although six hundred million can be considered large.

The thing to bear in mind is that such large tables have a different physics, like black holes. So tuning them takes a different set of techniques. The other thing is, users of a datawarehouse must understand that they are dealing with huge amounts of data, and so they must not expect sub-second response (or indeed sub-minute) for every query.

Partitioning can be useful, especially if you have clear demarcations such as, as in your case, CUSTOMER. You have to be aware that partitioning can degrade the performance of queries which cut across the grain of the partitioning key. So it is not a silver bullet.

like image 25
APC Avatar answered Sep 27 '22 18:09

APC