I try new table structure for our new eccomemrce website like WordPress tables. But I am not sure whether it’s really good idea for performance.
We’ve just 2 tables for products and other contents (such us pages, attachments, or even orders). Their ordinary fields kept first table (such as ID, title,date), but their special fields kept second table (such as price, quantity, options, features). That means all special fields of a product are in the just one table.
We thought if we use cache cleverly, it doesn’t matter.
What do you think?
(Please if you really have good experience, just answer this question)
Table Structure:
contents: (TABLE 1)
CONTENT_ID TITLE DESCRIPTION DATE
content_fields: (TABLE 2)
FIELD_ID CONTENT_ID KEY_NAME VALUE
Example (Get product that has 1 ID and its shipping is FREE):
SELECT * FROM `contents` as c LEFT JOIN `content_fields` as cf ON c.content_id = cf.content_id WHERE c.content_id = 1 AND cf.key_name = 'free_shipping' AND cf.value = 'yes'
I have really bad experience with this model, do I qualify? 😉
This kind of abstraction can make sense, but up to a point – you have to weigh the similarities and differences between various objects: for example, grouping CMS templates and e-mail templates together makes sense (as many important parts would be shared), grouping CMS pages and delivery orders doesn’t make much sense (as they only have a few, relatively unimportant, shared pieces of data).
The decision “what is similar enough”, will be subjective; but it needs to be done. Otherwise, you may fall into the trap of “everything is an object”.
True Story: one company I’ve worked with had a similar idea: everything (a CMS page, an order, a customer, an e-mail) is an Entity and is stored in the
entitiestable; properties specific to the object go toentity_propertiesandentity_property_valuestables. It was a Huge Unholy Mess (TM), as the objects had almost nothing in common, so 99% of the data was stored as entity_properties and/or various references to other Entities. (In other words, abstracting everything to a common base object has left us with many useless base objects).