Skip to content

Instantly share code, notes, and snippets.

@zhangysh1995
Created February 26, 2021 13:01
Show Gist options
  • Save zhangysh1995/415a522d1108a12afe0d1989d9546f6a to your computer and use it in GitHub Desktop.
Save zhangysh1995/415a522d1108a12afe0d1989d9546f6a to your computer and use it in GitHub Desktop.
mvcc_mysql_exmaple
---- create table
drop table if exists t0;
create table t0 (
pk int primary key,
col0 int,
col1 int
);
insert into t0 values (0,1,2), (1,2,3);
---- T1
drop table if exists t0;
create table t0 (
pk int primary key,
col0 int,
col1 int
);
insert into t0 values (0,1,2), (1,2,3);
---- T1
start transaction;
select pk from t0;
insert into t0 value (2,3,5);
commit;
---- T2
start transaction;
select pk from t0;
insert into t0 value (2,3,5);
select pk from t0;
update t0 set col0 = 1 where pk > 0;
select pk from t0; ---- different?
commit;
-- T1 -- -- T2 --
start transaction;
start transaction;
select pk from t0;
insert into t0 value (2,3,5);
select pk from t0; ---- first read
commit;
select pk from t0; ---- second read (same)
update t0 set col0 = 1 where pk > 0; ---- also updated (2,3,5) to (2,1,5)
select pk from t0; ---- third read (different!??)
commit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment