标签:mysql time-series dst on-duplicate-key
我正在研究时间序列数据,其中关键列是时间戳:时间.
每行还有许多“值”列.
我将把我的整个数据范围移动几个小时(由于夏令时问题).
为此,我将更新几行的密钥,这可能会导致一些重复的密钥.我希望忽略日期范围边缘的重复键.我希望移位范围覆盖旧范围.
我打算做以下事情:
UPDATE IGNORE time_series_table
SET time=time-<some_shift>
WHERE <time in a date-range>
这是describe< table>的输出.对于时间键:
Field Type Null Key Default Extra
TimeMeas datetime NO PRI NULL
我的问题是:它会立即移动所有键,还是会尝试逐行移动每一行,从而在移位范围内产生大量重复键?
你有更好的方法来做到这一点吗?
提前致谢
解决方法:
Will it shift all the keys at once, or will it try to shift each row one by one
它会立刻移动所有键.
resulting in massive duplicate keys wihthin the shifted range itself ?
如果任何主键重复,它就会失败.
随着更新忽略,它只是默默地跳过.
这是我解决这个问题的方法
/* create a temporary table to store matches records*/
create table tmp_table select time-<some_shift>, etc_cols....
from time_series_table
where <time in a date-range>;
然后
/* delete the matches in the original table */
delete from time_series_table where <time in a date-range>;
delete from time_series_table where <time in a date-range - some_shift>;
最后
/* at this point, there won't be any duplicate data */
/* so, insert back into original table */
insert into time_series_table select * from tmp_table;
optmize table time_series_table;
标签:mysql,time-series,dst,on-duplicate-key 来源: https://codeday.me/bug/20190630/1337074.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。