i read the "High performance MySQL", it has a text about MVCC,and i try to understand it by example,so here is first
examle one:
============================================================
session A time start
.........
session B
update t1 set id=2 where id=1
......... ............
select * from t1 where id=1 select * from t1 where id=1
1 2
here is my understand about example one
first ,B update the row ,make a copy about the row(is the row's copy can see by other session?) ,and set the copy row's DB_TRX_ID = trx_num of B,and also set the original row's DEL_ID = trx_num of B ,and when A select the row,it will see the copy of row's DB_TRX_ID = trx_num of B ,because Session B is later than Session A ,so the B's trx_num is great than A's,so A think the copy of row has been created after A,A will discard the row's copy ,next A will check the DEL_ID's value,and find the original row's DEL_ID is set ,and the values is trx_num of B ,that is great than A, so A think the original row is not been delete when A begin,so accept it,that is the result show in example one
but i have problem to understand example two
example two
============================================================
session A time start
select * from t1
empty set
session B
.......... insert into t1 values(1);
select * from t1
empty set
select * from t1 for update or lock in share mode
1
i do not understand why the select...for update/lock in share mode can see the B's change,is it passby the MVCC?
i want to see the innobase code about MVCC,anyone can tell me where the code located?is it in storage/innobase directory?
examle one:
============================================================
session A time start
.........
session B
update t1 set id=2 where id=1
......... ............
select * from t1 where id=1 select * from t1 where id=1
1 2
here is my understand about example one
first ,B update the row ,make a copy about the row(is the row's copy can see by other session?) ,and set the copy row's DB_TRX_ID = trx_num of B,and also set the original row's DEL_ID = trx_num of B ,and when A select the row,it will see the copy of row's DB_TRX_ID = trx_num of B ,because Session B is later than Session A ,so the B's trx_num is great than A's,so A think the copy of row has been created after A,A will discard the row's copy ,next A will check the DEL_ID's value,and find the original row's DEL_ID is set ,and the values is trx_num of B ,that is great than A, so A think the original row is not been delete when A begin,so accept it,that is the result show in example one
but i have problem to understand example two
example two
============================================================
session A time start
select * from t1
empty set
session B
.......... insert into t1 values(1);
select * from t1
empty set
select * from t1 for update or lock in share mode
1
i do not understand why the select...for update/lock in share mode can see the B's change,is it passby the MVCC?
i want to see the innobase code about MVCC,anyone can tell me where the code located?is it in storage/innobase directory?