mvcc

http://my.oschina.net/Kenyon/blog/108850
update tuple时会新增一个tuple然后将其隐藏。
delete tuple时会隐藏tuple。
postgres=# truncate table mm
postgres-# ;
TRUNCATE TABLE
postgres=# insert into mm values(1999);
INSERT 0 1
postgres=# insert into mm values(1999);
INSERT 0 1
postgres=# select * from mm;
  a   
------
 1999
 1999
(2 rows)
postgres=# select * from heap_page_items(get_raw_page('mm', 'main',0));
 lp | lp_off | lp_flags | lp_len | t_xmin | t_xmax | t_field3 | t_ctid | t_infomask2 | t_infomask | t_hoff | t_bits | t_oid 
----+--------+----------+--------+--------+--------+----------+--------+-------------+------------+--------+--------+-------
  1 |   8160 |        1 |     32 |   1844 |      0 |        0 | (0,1)  |           1 |       2048 |     24 |        |      
  2 |   8128 |        1 |     32 |   1845 |      0 |        0 | (0,2)  |           1 |       2048 |     24 |        |      
(2 rows)

postgres=# update mm set a=2000 where ctid='(0,1)';
UPDATE 1
postgres=# select * from mm;                       
  a   
------
 1999
 2000
(2 rows)
postgres=# select * from heap_page_items(get_raw_page('mm', 'main',0));
 lp | lp_off | lp_flags | lp_len | t_xmin | t_xmax | t_field3 | t_ctid | t_infomask2 | t_infomask | t_hoff | t_bits | t_oid 
----+--------+----------+--------+--------+--------+----------+--------+-------------+------------+--------+--------+-------
  1 |   8160 |        1 |     32 |   1844 |   1846 |        0 | (0,3)  |       16385 |        256 |     24 |        |      
  2 |   8128 |        1 |     32 |   1845 |      0 |        0 | (0,2)  |           1 |       2048 |     24 |        |      
  3 |   8096 |        1 |     32 |   1846 |      0 |        0 | (0,3)  |       32769 |      10240 |     24 |        |      
(3 rows)

postgres=# delete from mm where ctid='(0,2)';
DELETE 1
postgres=# select * from mm;
  a   
------
 2000
(1 row)




 

posted @ 2014-05-30 10:33  bielidefeng  阅读(193)  评论(0编辑  收藏  举报