给业务添加唯一索引之前,必须核对当前的数据是否违反唯一索引约束:

 

检测:


select
count( distinct app_id,count_date,cluster,priority) from events ; select count( *) from events ; select app_id,count_date,cluster,priority ,count(*) from events group by app_id,count_date,cluster,priority having count(*) >1 limit 20;

 

 

违反约束:

alter table events  add unique index uk_app(app_id,count_date,cluster,priority);       

ERROR 1062 (23000): Duplicate entry '2882303761517233197-2020-09-21-ALL-1' for key 'uk_id'

 

相关文章:

  • 2022-12-23
  • 2021-07-11
  • 2022-12-23
  • 2021-09-24
猜你喜欢
  • 2021-07-13
  • 2022-12-23
  • 2021-11-04
  • 2021-04-19
  • 2022-01-04
相关资源
相似解决方案