pingcap/tidb

RANDOM_BYTES function is not random

Open

#37,412 opened on Aug 26, 2022

View on GitHub
 (2 comments) (0 reactions) (1 assignee)Go (6,186 forks)batch import
affects-4.0affects-5.0affects-5.1affects-5.2affects-5.3affects-5.4affects-6.0affects-6.1affects-6.2affects-6.3affects-6.4affects-6.5affects-6.6affects-7.0affects-7.1affects-7.5help wantedseverity/majorsig/executiontype/bug

Repository metrics

Stars
 (40,090 stars)
PR merge metrics
 (Avg merge 14d 4h) (346 merged PRs in 30d)

Description

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

This is the easiest SQL to reproduce:

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)

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)

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