Is the value generated by AUTO_RANDOM a globally unique ID or unique at the table level?

This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: AUTO_RANDOM 生成的值是全局唯一ID还是根据表级别唯一

| username: myTiDBSteel

When designing a table with a primary key set as bigint with AUTO_RANDOM, if multiple tables in a database have this setting, are the generated IDs unique at the table level or globally unique?

| username: 啦啦啦啦啦 | Original post link


| username: tidb菜鸟一只 | Original post link


| username: zhanggame1 | Original post link


| username: 孤君888 | Original post link

It is definitely table-level uniqueness. I suggest not using auto-increment; random is fine.

| username: xingzhenxiang | Original post link

The image you provided is not visible. Please provide the text you need translated.

| username: xfworld | Original post link

Globally unique, referencing the Snowflake algorithm,
Special optimizations have been made to address region hotspot issues, with high bits flipped. The number of high bits flipped can be chosen and is related to sharding. :upside_down_face:

| username: 啦啦啦啦啦 | Original post link

I don’t know what you mean by “global.” In a table, all TiDB nodes are globally unique. If the title refers to the entire cluster, then definitely not.

| username: forever | Original post link

This global refers to the globally unique identifier for all TiDB servers for a single table.

| username: xingzhenxiang | Original post link

I personally understand it as a cluster.

| username: Anna | Original post link

Table-level, table-level

| username: 春风十里 | Original post link

The globally unique column value mentioned in the AUTO_RANDOM official documentation should be for the table, meaning it is globally unique at the table level. Otherwise, if I insert a piece of data and have to consider other tables, wouldn’t that be quite ridiculous?

Explicit insertion requires setting the system parameter allow_auto_random_explicit_insert, which can be proven by the following:

| username: redgame | Original post link