4

I am weighing up between Concrete and Class Table Inheritance (see example below). Class Table certainly has a lot of benefits, in particular for my scenario, super table columns are guaranteed consistent across the full data set. However I have next to no need to query every subclass at once, instead all queries will be on one subclass at a time (of which there are at least 9 subclasses).

Thus with my row count looking like it will be very large, would it be much sizable quicker to query one Concrete table with less rows ie: (as per example below)

SELECT property_address
FROM policies_property
ORDER BY date_issued DESC;

Or would the foreign key relationships be effectively quick enough that any query speed difference in looking up the very large super table is negligible in Class Table Inheritance: (as per example below)

SELECT property_address
FROM policies_property INNER JOIN policies_super ON policies_property.id = policies_super.id
ORDER BY policies_super.date_issued DESC;

An Example of Concrete Inheritance: A completely seperate table for each type with columns in common repeated in each table>

--// Table: policies_motor
+------+---------------------+----------------+
| id   | date_issued         | vehicle_reg_no |
+------+---------------------+----------------+
|    1 | 2010-08-20 12:00:00 | 01-A-04004     |
|    2 | 2010-08-20 13:00:00 | 02-B-01010     |
|    3 | 2010-08-20 15:00:00 | 03-C-02020     |
+------+---------------------+----------------+

--// Table: policies_property    
+------+---------------------+------------------+
| id   | date_issued         | property_address |
+------+---------------------+------------------+
|    1 | 2010-08-20 14:00:00 | Oxford Street    |   
+------+---------------------+------------------+

An Example of Class Table Inheritance: One super class, many sub classes. Each subclass id references a superclass id.

--// Table: policies_super
+------+---------------------+
| id   | date_issued         |
+------+---------------------+
|    1 | 2010-08-20 12:00:00 |
|    2 | 2010-08-20 13:00:00 |
|    3 | 2010-08-20 14:00:00 | 
|    4 | 2010-08-20 15:00:00 |
+------+---------------------+

--// Table: policies_motor
+------+----------------+
| id   | vehicle_reg_no |
+------+----------------+
|    1 | 01-A-04004     |
|    2 | 02-B-01010     |
|    4 | 03-C-02020     |
+------+----------------+

--// Table: policies_property    
+------+------------------+
| id   | property_address |
+------+------------------+
|    3 | Oxford Street    |   
+------+------------------+
4

1 回答 1

2

我几乎不需要一次查询每个子类,而是一次所有查询都在一个子类上(其中至少有 9 个子类)。

对我来说,这听起来是一个让他们分开的令人信服的理由。不要认为“超类”方法是“更好的规范化”或“更相关”等。它们只是理论上同样有效的两种设计选择;选择在实践中最有意义的那个。

于 2016-10-25T08:06:06.120 回答