RANDOM_BYTES function is not random
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
This is the easiest SQL to reproduce:
```sql
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`col1` varbinary(1024) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY (`col1`)
);
INSERT INTO t1
SELECT NULL, RANDOM_BYTES(1024) FROM dual;
INSERT INTO t1
SELECT NULL, RANDOM_BYTES(1024) FROM t1;
INSERT INTO t1
SELECT NULL, RANDOM_BYTES(1024) FROM t1;
```
The value is cached incorrectly. See `SELECT RANDOM_BYTES(n)` for another example: every row always has the same value.
### 2. What did you expect to see? (Required)
All inserts should succeed
### 3. What did you see instead (Required)
```sql
mysql> INSERT INTO t1
-> SELECT NULL, RANDOM_BYTES(1024) FROM dual;
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> INSERT INTO t1
-> SELECT NULL, RANDOM_BYTES(1024) FROM t1;
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> INSERT INTO t1
-> SELECT NULL, RANDOM_BYTES(1024) FROM t1;
ERROR 1062 (23000): Duplicate entry 't��Gt�IgN��C5
```
### 4. What is your TiDB version? (Required)
```sql
mysql> SELECT tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v6.3.0-alpha-85-ga8f524b31
Edition: Community
Git Commit Hash: a8f524b31b26cfa4073f2c687bc6ffe55eade37c
Git Branch: master
UTC Build Time: 2022-08-26 15:29:13
GoVersion: go1.19
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: unistore
1 row in set (0.00 sec)
```
Contributor guide
Assessment
This issue has not been assessed yet.