I have a dataset of values from a MySQL table being returned which are then charted. Each of the data points should have a fixed time period between them, EG:
Data Point 1: 1 –
Date/Time: 2013-02-11 09:00:00
Data Point 2: 2 –
Date/Time: 2013-02-11 09:05:00
Data Point 3: 3 –
Date/Time: 2013-02-11 09:10:00
However, this is not always the case. If we can provide our charting package with a set of data values, a start time and an interval time it can process and display the chart much quicker than if we provide a list of values and a list of dates/times.
What is the most efficient way to either pre-fill or post-fill a MySQL query with 0 values where the data point is missing? For example, using the data above if data point 2 was missing , what query could I use to get MySQL to return the following dataset:
Data Point 1: 1 –
Date/Time: 2013-02-11 09:00:00
Data Point 2: 0 –
Date/Time: 2013-02-11 09:05:00
Data Point 3: 3 –
Date/Time: 2013-02-11 09:10:00
Thanks in advance
i wouldn’t input garbage into the DB, you can do the pre-processing in application layer, it should be faster and more efficient.
If you are performing IO for each insert than the IO will be a huge bottleneck. ordering and inserting dummy points in a application layer , such as Java will probably be faster (you may do it before rendering your charts).
Additionally, assuming you have a file with the data logged in CSV formatted way, the insert using
LOAD DATAwill be very fast (might be 20 times faster then pre-processing each line and inserting line by line )