views:

288

answers:

4

We have a large table that services many different stored procedures on lots of websites, but generally only deal with data in the table that relates to the website using it.

In other words, would it be wrong to split the table by websiteID?

+3  A: 

If it means you are installing multiple databases on multiple servers, then that's one of the recommended ways to scale. If you mean multiple tables on the same server (same database or not), your gain will be little if any; and your administrative overhead will probably increase to keep them in synch. And if there are any cases at all of queries that hit multiple tables, those will be less efficient.

The effect is not likely to be substantial either for good or ill. What would you expect to be the benefit? (This is a typical rdbms antipattern for premature optimization, by the way.)

le dorfier
Yes I recognise it is an anti-pattern. I'm mainly trying to solve performance and locking problems from lots of websites all hitting on this one table. My gut feeling was this wasn't going to be the right way forward.
Hainesy
Right. If you have perfomance and locking problems, then it's best to deal with them directly at the app design level. Throwing hardware at it just defers judgment day (and makes it more spectacular).
le dorfier
This guy seems to think it's worthwhile though ;)http://articles.techrepublic.com.com/5100-10878_11-5794941.html
Hainesy
At some point it *is* worthwhile. But it's better to optimize a simple design (if you can) before you start making the whole situation more complex.
le dorfier
A: 

You mean you want to have BigTableForWebsite1, BigTableForWebsite2, BigTableForWebsite3, etc. instead of a single BigTableForAllWebsites? That makes me feel a little ill in my database-purist stomach...

I don't think it will give you a performance boost, since each access will still be working against a single database (probably stored in a single set of files).

scraimer
Single database would not be of any trouble. Think of single database server on multiple machines.
Adeel Ansari
+1  A: 

Yes, it's wrong. You should keep in one table and index on websiteid. If you really wanted to make them appear separated you might want to use partitioned views but I don't think that's necessary.

In SQL terms you should never break up a table based on its excessive length (ie number of rows) but you might consider breaking up a table based on excessive width (ie number of columns).

Chris Simpson
"In SQL terms you should never break up a table based on its excessive length (ie number of rows)" How do you do range-partitioning then? http://en.wikipedia.org/wiki/Partition_(database)
Adeel Ansari
My own opinions about partitioning aside, a partitioned table is still logically only one table. Creating multiple completely separate tables is quite rather different than partitioning.
Chris Simpson
I tend to agree. Sorry for my immature understanding.
Adeel Ansari
No worries. It was a fair point.
Chris Simpson
+1  A: 

If you want to move the applications to their own tables for isolation you would be better off setting up a database per instance rather than trying to do this in the application. This has the following advantages:

  • The SQL for the queries doesn't change.

  • It is easier to secure the data by database than by table partition. You can give the clients much more flexible access to the data without compromising other clients' data.

  • You can implement independent backup/restore regimes on a per-customer basis if necessary.

  • It is easier to 'scale out' by moving some customers onto another server if you have to.

  • The application architecture is simpler as it doesn't have to be explicitly aware of customer filtering in each query.

Setting up multiple tables on a per-customer basis means you have to maintain a separate build for the application or generate all of the SQL statements that involve those tables. This is messy and harder to scale to a large number of customers.

As a generalisation, if you have a relatively simple application and a large number of customers, a single table with filtering is probably the more appropriate solution. For a more complex application with fewer customers your best approach is to set up multiple databases and have an application instance per customer.

ConcernedOfTunbridgeWells