I am need of some advice, opinions, and any other comments people may have on the subject. Any insight into potential costs associated or actual improvement on search filtering speed are going to be helpful.
I am in the process of creating a marketplace app that enables B2B product sales.
My products category data table ( data type ) will look like this
I am using the parent_id and grandparent_id for excluding the need for a sub-categories table.
My products table ( data type ) is related to the categories table which is a data field in the products table.
I want to create a “many to one” or a “many to many” relationship by having the products data type to be a data field on the products categories data type. This is where I am at a cross roads in my decision making and what the possible advantages / disadvantages of the different choices are.
If I were to create a “one to many” relationship I would create a data type as a list of products in the categories data type…like the first image shows and the below
If I were to do this, that would mean I’d have products that would be listed on more than one category because I have parent and grandparent data fields to create the sub categories.
For example, if I have a category set up like below
I would have a list of products that have the category of Cereal and that would naturally have products that are on the list for category Oatmeal and on Wet…
So, on a third tier category such as “wet” the products on that list would be present on three lists of products on three different categories.
My thought and worry is that a relationship between data entries means that the entry is stored multiple times on my database and would therefore add to overall costs of maintaining and operating the platform, since data storage would increase.
Or am I wrong in that thought and the relationship is actually only “pointing” to the data entry in the data table and doesn’t actually create another copy of it, so just “pointing” to the data entry ( ie: having the relationship ) wouldn’t increase the costs of storage as I think.
My thoughts on the benefits of this strategy would be to make filtering and returning search results faster, as I could as the user selects the different category filters narrow down my search by saying “Do a search for selected category’s list of products”.
The drawback of not placing a list of products onto each category is that during search filtering I’d have to create a lot of conditionals to reference the parent id or grandparent id of a category.
Overall, I’m wondering about experiences people have or knowledge of the affects on data storage of using a relationship ( such as those for a products list as data field in categories data type ) and whether or not I’d actually see any kind of performance improvement during filtering search results.