Search code examples
mysqldatabasedatabase-designrelational-databasedatabase-management

Storing users data efficiently in mysql database


I am developing a recommendation engine, so that requires storing lots of data and keeping track of every move made by the user. So, basically my website is a product search engine and will be having sets of queries as users data. Following are some examples of the data set

Example

User1 :
1. Apple Ipod tOuch
2. Samsung Galaxy Ace Plus
3. HArry Porter 

User2 :
1. Product1
2. Product2

and so on.

One way(naive) could be having an ID associated with each of my users and then having a string corresponding to that ID which will be of this form(strings separated with ~) :-

Unique ID - Apple IPod TOuch~Samsung Galaxy Ace Plus~HArry Porter 

But this method won't be efficient considering how I would be playing with those data later on.

Can any one come up with a very efficient model fairly easily implementable in mysql ?

Comment if I am unclear in asking my doubt.


Solution

  • The classic design is a table for users :

    Users(user_id,user_name,reg_date....)
    

    table for products :

    Products(prod_id,prod_name,prod_cost....)
    

    table with mapping user-->products :

    User_products(user_id,prod_id ....)
    

    Example :

    Users :

    user_id|user_name
    1200   | User1 
    7856   | User2
    

    Products :

    prod_id | prod_name
    12900   | Apple Ipod tOuch
    45673   | Samsung Galaxy Ace Plus
    99876   | HArry Porter 
    34590   | Product1
    56283   | Product2
    

    User_products :

    user_id | prod_id
    1200    |12900
    1200    |45673
    1200    |99876
    7856    |34590
    7856    |56283