Изначально я пытался использовать это
Код: Выделить всё
Update t1 SET
field1=(select t2.field1 from t2 order by rand() limit 1),
field2=(select t2.field2 from t2 order by rand() limit 1)
+----+----------------------+------------+------------+-------+---------------+---------+---------+------+--------+----------+---------------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+----------------------+------------+------------+-------+---------------+---------+---------+------+--------+----------+---------------------------------+
| 1 | UPDATE | t1| NULL | index | NULL | PRIMARY | 4 | NULL | 932170| 100.00 | NULL |
| 3 | UNCACHEABLE SUBQUERY | t2| NULL | ALL | NULL | NULL | NULL | NULL | 49717 | 100.00 | Using temporary; Using filesort |
| 2 | UNCACHEABLE SUBQUERY | t2| NULL | ALL | NULL | NULL | NULL | NULL | 49717| 100.00 | Using temporary; Using filesort |
+----+----------------------+------------+------------+-------+---------------+---------+---------+------+--------+----------+---------------------------------+
Код: Выделить всё
Update t1 SET
field1=(select t2.field1 from t2 where id=FLOOR(1+rand()*50000) limit 1),
field2=(select t2.field2 from t2 where id=FLOOR(1+rand()*50000) limit 1)
+----+----------------------+------------+------------+-------+---------------+---------+---------+------+--------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+----------------------+------------+------------+-------+---------------+---------+---------+------+--------+----------+-------------+
| 1 | UPDATE | t1| NULL | index | NULL | PRIMARY | 4 | NULL | 932170| 100.00 | NULL |
| 3 | UNCACHEABLE SUBQUERY | t2| NULL | ALL | NULL | NULL | NULL | NULL | 49717| 10.00 | Using where |
| 2 | UNCACHEABLE SUBQUERY | t2| NULL | ALL | NULL | NULL | NULL | NULL | 49717| 10.00 | Using where |
+----+----------------------+------------+------------+-------+---------------+---------+---------+------+--------+----------+-------------+
Изменить: информация о таблице и планы
Код: Выделить всё
CREATE TABLE t1 (
id int,
field1 varchar(400),
field2 varchar(400)
PRIMARY KEY(id))
CREATE TABLE t2 (
id int,
field1 varchar(400),
field2 varchar(400)
PRIMARY KEY(id))
Подробнее здесь: https://stackoverflow.com/questions/793 ... ther-table
Мобильная версия