I would suggest having a hybrid between normalized data and denormalized . Therefore, using the normalized structure provided by eggyal, I would do the following denormalized structure:
CREATE TABLE Items_Tags_Denormalized ( Item_ID BIGINT UNSIGNED REFERENCES Items (Item_ID), Tags BLOB, PRIMARY KEY (Item_ID) ) ENGINE=InnoDB;
In the Tags column, you will have all the tags ( Tag_Title ) for the corresponding Item_ID .
Now you have 2 ways to achieve this:
create a cron that runs periodically, which will build this Items_Tags_Denormalized table using GROUP_CONCAT or whatever suits you (advantage: does not add extra load when inserting or deleting Items_Tags in the table; disadvantage: the denormalized table will not always be relevant (depending on how often do you run cron))
create triggers for the Items_Tags table for insertion and deletion to update the Items_Tags_Denormalized table (advantage: a denormalized table will always be relevant; disadvantage: additional load when inserting or deleting in the Items_Tags table)
Choose any solution that suits your needs, best considering the advantages and disadvantages.
So, at the end you will get the Items_Tags_Denormalized table, from which you will read only without additional operations .
source share