I did quite good research and went through some information on this regard. But I am not satisfied yet, so preferred to ask directly about it.
I'm designing the schema of an application database, which is assumed to have tins of millions of records.
Some of these are frequently updated, and some are very rarely updated.
Hence, I decided to spread data on different tables according to the nature, and JOIN
them in queries.
So, is this better or.. going with the one table (no JOIN
s)?
Assume it is a Rent-A-Car management system..
Here are the tables:
DESC cars
+-----------------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+---------------------+------+-----+---------+-------+
| id | bigint(20) unsigned | NO | PRI | NULL | ai |
| brand | varchar(40) | NO | | NULL | |
| engine_capacity | tinyint(4) | NO | | NULL | |
| model | tinyint(4) | NO | | NULL | |
| serialnumber | bigint(20) | NO | UNI | NULL | |
+-----------------+---------------------+------+-----+---------+-------+
AND
DESC cars_data;
+---------------+----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+----------------------+------+-----+---------+-------+
| carid | bigint(20) unsigned | NO | PRI | NULL | ai |
| car_status | enum('1','2','3') | NO | MUL | 1 | |
| base_location | point | NO | MUL | NULL | |
| driver_id | bigint(20) unsigned | NO | MUL | NULL | |
+---------------+----------------------+------+-----+---------+-------+
Both those tables, are assumed to be very rarely updated, thus I used for them MyISAM for next reasons:
- Need to store Point data and use Spatial Index on them.
- Saving disk space (since MyISAM tables are smaller in size).
- Easier to maintain (as per my experience, is that right?).
Here is the very frequently updated table:
DESC cars_extra;
+---------------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+---------------------+------+-----+---------+-------+
| carid | bigint(20) unsigned | NO | PRI | NULL | ai |
| odometer_km | tinyint(6) unsigned | NO | | NULL | |
| last_maint | bigint(20) unsigned | NO | | NULL | |
| last_update | bigint(20) unsigned | NO | | NULL | |
+---------------+---------------------+------+-----+---------+-------+
I used for last table InnoDB for one single main reason:
- Avoid table-level locks during updates.
Advises, and general notes would be more than appreciated :-)
Also, are joins usually a con or pros (surly with the use of proper indexed keys).