We are developing advertisement scheduling system. Now, we want to calculate prize details for that. Right now, database is like, we have 2 tables city and daypart. city contains 30+ million records, and daypart contains 6 records like 6am to 10pm.etc. Now we want to calculate prize for advertisement. i.e if any user has given advertise to Mumbai city for 3 dayparts then how to calculate prize for that. One way is that create one more table and in that kept all the combinations of city and daypart and its prize. but then this table contains 60+ millions records, and if new daypart is added then we have to update this table again which is more problematic.
ex. city contains 1 record and daypart contains 6 records, then new table contains total 6 records and its prize.
is there any other way to calculate prize for above scenario?
We are developing advertisement scheduling system. Now, we want to calculate prize details for
Share
As you’ve mentioned, prize amounts can differ based on city or daypart, and it doesn’t sound like there’s any standard algorithm or calculation to calculate a prize based on city and daypart (prize amount seems proprietary information to your system) – so some sort of lookup table would probably be your best bet.
I’d imagine your table columns would look something like this:
Some notes:
Rather than store ‘dayparts’ as a time range (3pm-6pm), store it in the lookup table as a price per hour that starts at a specific time. For example:
If CityA (id=1) costs $15 for 6am-9am, and $30 for 9am-12pm, (and 0 otherwise, for simplicity) then this table would contain these entries:
If this doesn’t meet your needs, another alternative (as you mentioned) is just a straight-up lookup table, in which case you’d have a table of dayparts, and prizes table would become
cityId | daypartId | amount.The size of your tables isn’t that bad if you’re worried about performance – especially if you properly use your primary key columns and have table indexes.