主键id达到bigint数据类型的限制 [英] Primary key id reaching limit of bigint data type

查看:1844
本文介绍了主键id达到bigint数据类型的限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表定期暴露于大型插入和删除(因此,主id列的数字序列中存在大的间隙)。它有一个'int'类型的主id列,它被改为'bigint'。尽管有这种变化,但在未来的某个时间点也不可避免地会超出此数据类型的限制(当前使用情况将表明在未来一年内会出现这种情况)。

I have a table that is exposed to large inserts and deletes on a regular basis (and because of this there are large gaps in the number sequence of the primary id column). It had a primary id column of type 'int' that was changed to 'bigint'. Despite this change, the limit of this datatype will also inevitably be exceeded at some point in the future (current usage would indicate this to be the case within the next year or so).

您如何处理这种情况?我想知道(震惊恐怖)我是否甚至需要主键列,因为它在任何查询中都没有以任何明显的方式使用或被其他表引用等等。删除列是一个解决方案吗?或者那种行为会让你厌恶地从mysql社区中被驱逐出去?!

How do you handle this scenario? I'm wondering (shock horror) whether I even need the primary key column as it's not used in any obvious way in any queries or referenced by other tables etc. Would removing the column be a solution? Or would that sort of action see you expelled from the mysql community in disgust?!

我们已经接近自动增量ID的5亿大关。该表在单独的表中保存与文件数据相关联的关键字。每个文件数据行在关键字表中可以有多达30个与之关联的关键字,因此在您不断插入和删除数万个文件后,它们真正开始堆叠。目前关键字表包含关键字及其关联的文件的ID,因此如果我删除了当前的主要id列,除了关键字(varchar)和文件id(int)字段之外,没有唯一的标识符,这将是一个可怕的主键。

We're already nearly at the 500 million mark for the auto increment id. The table holds keywords associated with file data in a separate table. Each file data row could have as many as 30 keywords associated with it in the keywords table, so they really start to stack up after you've got tens of thousands of files constantly being inserted and deleted. Currently the keyword table contains the keyword and the id of the file it's associated with, so if I got rid of the current primary id column, there would be no unique identifier other than the keyword (varchar) and file id (int) fields combined, which would be a terrible primary key.

非常感谢所有的想法/答案/经验/解决方案。

All thoughts/answers/experiences/solutions very gratefully received.

推荐答案

如果您不需要该列,因为您有另一个唯一的记录标识符。像提供的measurement_id或任何甚至组合键一样:measurement_id + location_id不需要使用自动增量键。如果有可能你没有唯一的钥匙而不是肯定的。

If you don't need that column because you have another identifier for a record which is unique. Like a supplied measurement_id or whatever or even a combined key: measurement_id + location_id it should not be needed to use an auto increment key. If there is any chance you won't have a unique key than make one for sure.

如果我需要一个非常大的自动增量ID怎么办?

你真的确定你有这么多的插入和删除你会达到极限吗?

Are you really sure you have so many inserts and deletes you will get to the limit?

这篇关于主键id达到bigint数据类型的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆