I store different elements (notes, articles, figures, files) in one table (for all types of elements there is a lot of metadata - for example, categories, tags, rating, statistics, etc.).
My first construct was this: table Items , as well as another “details” table for each of the item types ( NoteItems , ArticleItems , PictureItems , etc.). To get one item, tables must be joined together (SELECT * FROM Items INNER JOIN PictureItems ON Items.Id = PictureItems.Id WHERE Items.Id = N).
I am sure that this “book-like” design will work beautifully (done several times), however, I begin to wonder if the design is too high. It would be much easier to have one table ( Elements ).
Say that there are about 5% of the elements of an image or file type.
And now, the question is: if I go for a (almost) single table design, would it be better to have detail tables for image fields anyway (for images and files, of course)?
Scenario 1: only one table: Elements (for storing notes, articles, images, files ...)
Scenario 2: two tables: Elements (for storing notes, articles, image files), ImageItems (for storing only the image field of types of image elements, file); one-to-one relationship
(Scenario 3 will be a minor change to Scenario 2, with 3 tables (Items, PictureItems, FileItems))
Scenario 1 Benefits:
- simpler queries (no connections)
- no transactions (only one table is updated in INSERT / UPDATE)
- performance, scalability due to lack of update transactions
Scenario 2 Benefits:
- cleaner design
- lower data consumption (in scenario 1, about 95% of elements of the type other than the image or file will be NULL in the image field, then about 16 bytes will be spent for the pointer)
Which scenario will you choose: 1 (no transaction) or 2 (lower data consumption)? Thank you for your opinion.