I am working on a project which uses a table for storing all restaurant data in same table.
There is a separate table for area containing area_id and area_name
There are six field which are source of problem to me.
They are:
delivery_area_1 , delivery_area_2, delivery_area_3
minimum_order_1, minimum_order_2 and minimum_order_3
delivery_area_1 field contain a coma(‘,’) separated list of all area_id ‘s in which the restaurant delivers at minimum order 1 and so on for delivery area 2 and 3.
When a user search by area_id and the result contains all the restaurants which deliver in that area_id and the corresponding minimum order is to be displayed in the result along with other details.
I propose to move this delivery area data to a separate mapping table which will contain:
restaurant_id, area_id and the minimum order.
But doing so will cause the number of entries in the mapping table to crosss 1000,000 for 20,000 restaurants. Currently there are 1000 restaurants but the number will increase rapidly from now on. Each restaurant delivers in about 30-80 areas.
Is this a good move? It would be a big decision. So please help me with the approach.
Is there a better way to simplify and optimize search ?
Its a PHP website.
short and simple: yes, change that (this is called database normalization).
a million rows in a table just containing 3 colums isn’t a big deal. you could choose to add two tables instead of just one:
this will give you the advantage that is the amount for a group of areas changes, just the amount at
minimum_orderneeds to be updated instead of multiple rows (one per area) atminimum_order.