Replacing uuid_short

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

Original topic: uuid_short替换

| username: TiDBer_wTKU9jv6

【TiDB Usage Environment】Testing

【TiDB Version】6.1.0

【Encountered Problem】
In MySQL, the uuid_short function can be replaced with what function or solution in TiDB?

| username: ddhe9527 | Original post link

It seems not yet

| username: 长安是只喵 | Original post link

You can refer to the source code to create one~

ulonglong uuid_value;

void uuid_short_init()
{
    uuid_value = ((((ulonglong) server_id) << 56) + (((ulonglong) server_start_time) << 24));
}

longlong Item_func_uuid_short::val_int()
{
    ulonglong val;
    mysql_mutex_lock(&LOCK_uuid_generator);
    val = uuid_value++;
    mysql_mutex_unlock(&LOCK_uuid_generator);
    return (longlong) val;
}
| username: ShawnYan | Original post link

This function is not supported in TiDB, you can try this:

mysql> begin; select @@tidb_current_ts; rollback;
Query OK, 0 rows affected (0.001 sec)

+--------------------+
| @@tidb_current_ts  |
+--------------------+
| 434832859614150657 |
+--------------------+
1 row in set (0.001 sec)

| username: ti-tiger | Original post link

Adding a timestamp or something similar should be about right.

| username: Kongdom | Original post link

Do we need to add a rollback for this? Very meticulous!

| username: system | Original post link

This topic will be automatically closed 60 days after the last reply. No new replies are allowed.