![c06d2dc3c82672c38d5d06237e377fb1.png](https://img-blog.csdnimg.cn/img_convert/c06d2dc3c82672c38d5d06237e377fb1.png)
我们知道postgresql数据库通过数据多版本实现mvcc,pg又没有undo段,老版本的数据元组直接存放在数据页面中,这样带来的问题就是旧元组需要不断地进行清理以释放空间,这也是数据库膨胀的根本原因。本文简单介绍一下postgresql数据库的元组、页面的结构以及索引查找流程。
![8d4f9fa7be591eaf9451d790204ae0b2.png](https://img-blog.csdnimg.cn/img_convert/8d4f9fa7be591eaf9451d790204ae0b2.png)
![2ff902f8bfc7da321c00b732e94d5954.gif](https://img-blog.csdnimg.cn/img_convert/2ff902f8bfc7da321c00b732e94d5954.gif)
元组结构
![c06d2dc3c82672c38d5d06237e377fb1.png](https://img-blog.csdnimg.cn/img_convert/c06d2dc3c82672c38d5d06237e377fb1.png)
元组,也叫tuple,这个叫法是很学术的叫法,但是现在数据库中一般叫行或者记录。下面是元组的结构:
typedef struct HeapTupleFields{
TransactionId t_xmin; /* inserting xact ID */ TransactionId t_xmax; /* deleting or locking xact ID */ union {
CommandId t_cid; /* inserting or deleting command ID, or both */ TransactionId t_xvac; /* old-style VACUUM FULL xact ID */ } t_field3;} HeapTupleFields;struct HeapTupleHeaderData{
union {
HeapTupleFields t_heap; DatumTupleFields t_datum; } t_choice; ItemPointerData t_ctid; /* current TID of this or newer tuple (or a