Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

columnar database

I have a sales database where I want to get customer details based on these categories selection. I have around 15 categories and my customer database is 5 million records. Each product may fall under more than one category. I need to retrieve customer name based on the category selected. Is it a better approach to put all these categories as columns or create separate table for product and category and then inner join? I want in terms of performance which one is a better approach.

Approach 1:

option1 here 1 says that the product is under that category.

Approach 2:

approach2

like image 676
aditya Avatar asked Oct 31 '22 08:10

aditya


1 Answers

Second Approach (Approach 2) is much better solution rather than creating single table because it is not necessary that every product may have all categories in approach one you are reserving space by creating separate columns even though category exist or not, and what if in future if one category is increased you will have to alter the current structure of the table and it will be tough task.

Yes Join will be bit slow but if you create index properly it will perform much better.

like image 111
Moolshanker Kothari Avatar answered Nov 13 '22 05:11

Moolshanker Kothari