Mysql – Is it better to have large tables or many tables (MySQL)

MySQLscalability

In terms of performance, is it advisable to have only a few tables with a lot of rows or a lot of tables with only a few rows? In my instance, I have groups that I am keeping data separately for. Is it better to create a new table for every group or keep all the information for the groups in one table (that will get very, very large) and have a column that identifies which group it belongs to? Which version would be better in terms of scalability? I am using PHP to access the data and I only need to get data for one or two groups per page load. I am mainly concerned with the speed of the system when there is a lot of data being stored. Thanks.

Best Answer

In my instance, I have groups that I am keeping data separately for. Is it better to create a new table for every group or keep all the information for the groups in one table (that will get very, very large) and have a column that identifies which group it belongs to?

Define "very, very large".
Millions of rows? That's large[-ish]. Anything less than that really isn't.

If you went with multiple tables, how would you identify them?
You don't want to use Group Names as Table Names, because someone will create a Group containing a character that can't be used as such and break everything. So you'd wind up with another table that links each table name to its Group name using some other, arbitrary identifier.

Assuming you did this; how would you then write any sort of query that goes across all of those tables, which you might need to do for Administrative purposes. Let's assume that the database is powerful enough to be able to join or union that many tables in one query? (MySQL, for example, used to be limited to 61 such tables).

Basically, the table-per-thing model is generally a Bad Idea and should be avoided.

Create a single Groups table, with a unique identifier for each Group and index it sensibly for the queries that you intend to run against it.