Back track/update old data

I’ve had 6 months worth of data with custom dimensions. Recently we have added a new custom dimension, but want to set values for the past data also. What would be the best way to do this?

I have access to the piwik database itself, and know my way round. It means Updating the rows in piwik_log_link_visit_action, by using a temp table with the data we want to add to the new dimension. This works, but we have millions of rows to go through piwik_log_link_visit_action so it ends up in a timeout.

Right now, thinking of limiting the update statement to only update into increments of 10,000 and even that takes a couple of minutes to do. Is there a good way of back tracking data?!