clear markdown compare help donate or buy diddy dollings comments/suggestions/bugs a leap of faith? bible365
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 818520 fiddles created (9180 in the last week).

CREATE TABLE remote_users ( id bigint(20), user_id bigint(20), PRIMARY KEY (id), KEY userId (user_Id) ); INSERT INTO remote_users VALUES (1,11), (2,12), (3,13), (4,14), (5,15), (6,16), (7,17), (8,18), (9,19); SELECT * FROM remote_users; CREATE TABLE users_ids_mapping ( current_user_id bigint(20), new_user_id bigint(20), UNIQUE KEY current_user_id (current_user_id), KEY new_user_id (new_user_id) ); INSERT INTO users_ids_mapping VALUES (11,21), (12,22), (13,23), (14,24), (16,26), (17,27), (18,28), (19,29);
id user_id
1 11
2 12
3 13
4 14
5 15
6 16
7 17
8 18
9 19
 hidden batch(es)


explain UPDATE remote_users u SET user_id = ( SELECT new_user_id FROM users_ids_mapping WHERE u.user_id = current_user_id ) WHERE EXISTS ( SELECT new_user_id FROM users_ids_mapping WHERE u.user_id = current_user_id ) LIMIT 3;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 UPDATE u index PRIMARY 8 9 100.00 Using where
3 DEPENDENT SUBQUERY users_ids_mapping eq_ref current_user_id current_user_id 9 fiddle_PZIAQDTCPDICWUPOUJCC.u.user_id 1 100.00
2 DEPENDENT SUBQUERY users_ids_mapping eq_ref current_user_id current_user_id 9 fiddle_PZIAQDTCPDICWUPOUJCC.u.user_id 1 100.00
 hidden batch(es)


UPDATE remote_users u SET user_id = ( SELECT new_user_id FROM users_ids_mapping WHERE u.user_id = current_user_id ) WHERE EXISTS ( SELECT new_user_id FROM users_ids_mapping WHERE u.user_id = current_user_id ) LIMIT 3; SELECT * FROM remote_users;
id user_id
4 14
5 15
6 16
7 17
8 18
9 19
1 21
2 22
3 23
 hidden batch(es)


UPDATE remote_users u SET user_id = ( SELECT new_user_id FROM users_ids_mapping WHERE u.user_id = current_user_id ) WHERE EXISTS ( SELECT new_user_id FROM users_ids_mapping WHERE u.user_id = current_user_id ) LIMIT 3; SELECT * FROM remote_users;
id user_id
5 15
8 18
9 19
1 21
2 22
3 23
4 24
6 26
7 27
 hidden batch(es)


UPDATE remote_users u SET user_id = ( SELECT new_user_id FROM users_ids_mapping WHERE u.user_id = current_user_id ) WHERE EXISTS ( SELECT new_user_id FROM users_ids_mapping WHERE u.user_id = current_user_id ) LIMIT 3; SELECT * FROM remote_users;
id user_id
5 15
1 21
2 22
3 23
4 24
6 26
7 27
8 28
9 29
 hidden batch(es)