I am trying to do time series product database that tracks a product stock quantities (100k+ products). It will be updated from a CSV file every 30 min and I only want to insert a new record if the AvailQuant or the AvailNextQuant has changed. Every new source CSV file has a new date and a time on every row. Some stock quantities might change only once per month so no point to insert a new duplicate row every 30 min when only the time is different. There must be some easy obvious way to do this as I would think that this is quite a common thing to do (price history tracking sites etc, update only when price change).
Columns are as follows: ProductID, AvailQuant, AvailDate, AvailTime, AvailNextQuant, AvailNextDate.
I first thought to use 3 separate tables: tmp1, tmp2 and final time series table. First LOAD DATA INFILE REPLACE into tmp1 table and then INSERT only new products and UPDATE the existing products if stock value change into tmp2 and after that from tmp2 table INSERT IGNORE into final time series table where unique index is: ProductID + Date + Time. Not sure how to archive this or is it even anyway near a correct approach? Now I also think that with the LOAD DATA INFILE I should only need one tmp table?
PS. I’m totally newbie with the MySQL so if someone knows how to do this, a little explanation with the example code would be highly appreciated.