petehamilton / citier

CITIER (Class Inheritance & Table Inheritance Embeddings for Rails) is a solution for simple Multiple Class Inheritance in Rails.
88 stars 24 forks source link

Opportunity to reduce number of SQL queries #13

Open mhuggins opened 13 years ago

mhuggins commented 13 years ago

In the ChildInstanceMethods::save method, each inherited object's type is set via a SQL UPDATE query after all other data has already been INSERTed. So in a simple example where Driver extends Person, there are two extra UPDATEs that occur after each of these tables has data INSERTed.

It seems that the type could (arguably should) be included in the original INSERT statement since we already know what the type value is, and it's not being generated as a result of the inserts.

Additionally, this would allow non-transactional databases (e.g.: MySQL's MyISAM) to define the type column as non-nullable, which would improve general query performance against the table.