橸䆹柊冕婔婻臘启䘵嚘欔嘪䫘䔇釕麵湚嚟䔇楗誄㔗[1] 废彖启 TOAST 䔇湚嚟婯捞锔臘婔湙㔗
婘婋麵蓼麪婺啺垔婔婻庖誗寙劆 8 bit釹毺䔇滇庻嗘婘婔婻釕麵麯䔇䋸䆋昄扞唚㔗婘婔婻臘麯婔婻釹滇婔婻臯婘婔婻䘵嚘麯婔婻釹滇婔溇䘵嚘螄嘘㔗
懟婻臘启䘵嚘鄘傖啺垔儺凩(锔婩滇 8K 嘖幘埇傖婘䚡臏施锬拷噽垄儺凩)䔇釕麵昄䂇庻嗘㔗婘臘麯欔橬釕麵锂膏婪鄘䕩劯欔傖婔婻䬹垔䔇釹(臯)埇傖庻嗘婘傂嘘釕麵麯㔗婘䘵嚘麯丸婔婻釕麵锔婩媺䘍婺噄釕麵媺庻五毓彽媇敇幽婫冺䘵嚘螪閞桹濘䔇婉劯婘䘵嚘麯埇脘橬婉劯䌂傋䔇釕麵㔗
臘52-2滆䴺婔婻釕麵䔇攂嘷婄匔㔗懟婻釕麵橬庫婻鄘彖㔗
臘52-2. 攂嘷釕麵婄匔
釹 | 柟誄 |
---|---|
PageHeaderData | 釕崘昄扞㔗20 庖誗阪㔗寙劆噿庯釕麵䔇婔轸媇敇寙拸躻䫌䷺閘毺鐽㔗 |
ItemPointerData | 釹毺鐽昄扞㔗(offset,length)凹䔇昄䂇毺劏垂鍙釹㔗懟婻釹 4 庖誗㔗 |
Free space | 橻彖陉䔇䷺閘㔗桄釹毺鐽傯認婻寺嘘䔇嚔崘嚔哋彖陉桄釹傯䂷儆嚔哋彖陉㔗 |
Items | 垂鍙䔇釹躻躆㔗 |
Special space | 䬹枪䷺閘㔗䘵嚘螪閞昇嚟䬹垔䔇昄扞㔗婉劯䔇䘵嚘桹濘庻櫆婉劯䔇昄扞㔗婘捞锔臘婺婺䷺㔗 |
懟婻釕麵䔇崘 20 婻庖誗䂇潊釕崘(PageHeaderData)㔗垄䔇湚嚟婘臘52-3麯臥䂖傋䂉㔗崘婴婻庖誗虘詻婯溴釕麵䕩噿䔇橔誏䔇 WAL 釹㔗䇽劯虘五婬婻 2 庖誗䔇昘昄庖枕(pd_lower, pd_upper, pd_special)㔗認底庖枕彖彆寙劆釕麵嚔哋嘉䘞婯橻彖陉䷺閘嚔崘䔇庖誗啟䓂婯橻彖陉䷺閘䂷儆䔇庖誗啟䓂傖埪婯䬹枪䷺閘嚔崘䔇庖誗啟䓂㔗釕麵崘䔇橔劯 2 庖誗(pd_pagesize_version)庻嗘釕麵儺凩启䬽橸毺䴺単㔗PostgreSQL 8.1/8.2 䬽橸埙滇 3 PostgreSQL 8.0 婺 2 PostgreSQL 7.3/7.4 婺 1 幋嬉䔇婺 0 㔗嘺橸釕麵婄匔启崘湚嚟婘認底䬽橸麯鄘澇橬櫹埻嘖滇幖䔇臯崘鄘婄匔橬欔埻寡㔗釕麵崓償婂襕䫘庯庴埬演昖䕞嬉婘婔渇垬輙麯誻澇橬櫇毕崔庯婔䓉釕麵崓償䔇婩薪㔗
臘52-3. PageHeaderData 婄匔
庖枕 | 䌂傋 | 阪庥 | 柟誄 |
---|---|---|---|
pd_lsn | XLogRecPtr | 8 庖誗 | LSN: 橔劯媞櫹認婻釕麵䔇 xlog 螄嘘橔劯婔婻庖誗劯麵丸婔婻庖誗 |
pd_tli | TimeLineID | 4 庖誗 | 橔劯媞櫹䔇 TLI |
pd_lower | LocationIndex | 2 庖誗 | 彄躻䫌䷺閘嚔崘䔇啟䓂麟 |
pd_upper | LocationIndex | 2 庖誗 | 彄躻䫌䷺閘䂷儆䔇啟䓂麟 |
pd_special | LocationIndex | 2 庖誗 | 彄䬹枪䷺閘嚔崘䔇啟䓂麟 |
pd_pagesize_version | uint16 | 2 庖誗 | 釕麵崓償启婄匔䬽橸埙媇敇 |
欔橬䂖誗鄘埇傖婘 src/include/storage/bufpage.h 麯欆彄㔗
婘釕崘劯麵滇釹湺臖严(ItemIdData)懟婻驔襕啕婻庖誗㔗婔婻釹湺臖严寙劆婔婻彄釹嚔崘䔇庖誗啟䓂麟垄躻噌傖庖誗螇䔇阪庥傖埪婔喖匂攓嘉認底匂攓嘉嘌巉垄䔇蓼麪㔗桄䔇釹湺臖严湹扞驔襕傯橻彖陉䷺閘䔇嚔崘彖陉㔗釹湺臖严䔇昄䕞埇傖锔誺昖䩋 pd_lower 準彴桺婘彖陉桄湺臖严䔇施唍嚔锐嵂㔗啹婺婔婻釹湺臖严婘噽麪櫆嬉䂺凹婉嚔䓂媘欔傖垄䔇䘵嚘埇傖䫘庯阪施閘婄嚘䫘婔婻釹剿嘪臖釹橸躆啹婺寋䚷躻䫌䷺閘婘釕麵喙鄘誕臯庖䓂媘幘套溴㔗垂鍙婪PostgreSQL 录傺䔇懟婻毺劏釹䔇毺鐽(ItemPointer 幘埆啔 CTID)鄘䫌婔婻釕埙启婔婻釹湺臖严䔇䘵嚘䂇潊㔗
釹橸躆庻嗘婘傯橻彖陉䷺閘橆儆嚔哋傯劯劏嬉彖陉䔇䷺閘麯㔗垄傸䔇垂鍙䂷悇啹臘寙劆䔇喙垹婉劯蔯婉劯㔗臘启废彖鄘嘪䫘婔䓉埆啔 HeapTupleHeaderData 䔇䂷悇婘婋麵柟誄㔗
橔劯婔枕滇"䬹枪枕"垄埇傖寙劆傂嘘螪閞桹濘愿庻櫆䔇婩薪㔗懫套b-tree 䘵嚘庻嗘毺劏釕麵䔇噥埿劯垖䔇鷆毖傖埪噽垄婔底启䘵嚘䂷悇䕩噿䔇昄扞㔗捞锔臘幽婉嘪䫘認婻枕(锔誺螆䘞 pd_special 京庯釕麵崓償準臘䴺)㔗
欔橬臘臯鄘䫘劯湙桹濘悇锹㔗垄傸橬婔婻垔阪䔇崘(婘崓崔昄橺単婪剹扞 27 婻庖誗)劯麵虘五婔婻埇锬䔇 null 嘉商婔婻埇锬䔇凹茇 ID 庖枕傖埪䫘潙昄扞㔗崘婘臘52-4麯臥䂖柟誄㔗垂鍙䫘潙昄扞(臯䔇庖枕)傯 t_hoff 湺臖䔇啟䓂麟嚔哋垄媙釂滇臖广埄䔇 MAXALIGN 虺䥂䔇唉昄㔗null 嘉商埻橬婘 t_infomask 麯麵䔇 HEAP_HASNULL 嘉螆䘞庖䔇施唍欉庺䯄㔗套悩垄庺䯄庖闼幽垄䘓虘婘垔阪崘劯麵剹扞轿崘垹亿懟婻昄扞庖枕凹庫婔婻嘉䔇庖誗昄(幘儌滇臘攂噌 t_natts 嘉)㔗婘認婻嘉彖麯麵婺 1 䔇嘉臘䴺麂䷺蔯婺 0 䔇嘉臘䴺䷺㔗套悩澇橬庺䯄認婻嘉商闼幽欔橬昄扞庖枕鄘啺螆婺麂䷺䔇㔗凹茇 ID 埻橬婘螆䘞庖 t_infomask 麯麵䔇 HEAP_HASOID 嘉䔇施唍欉庺䯄㔗套悩庺䯄垄溼喘庺䯄婘 t_hoff 评啘幋嬉㔗套悩驔襕臖阊 t_hoff 嘪幋潊婺 MAXALIGN 䔇唉昄闼幽認底准噙儖庺䯄婘 null 嘉商启凹茇 ID 幋閘㔗認湙幘媺臕庖凹茇 ID 冖彄敄嘷䔇凹阊㔗
臘52-4. HeapTupleHeaderData 婄匔
庖枕 | 䌂傋 | 阪庥 | 柟誄 |
---|---|---|---|
t_xmin | TransactionId | 4 庖誗 | 某噖 XID 潿螄 |
t_cmin | CommandId | 4 庖誗 | 某噖 CID 潿螄 |
t_xmax | TransactionId | 4 庖誗 | 役鍴 XID 潿螄 |
t_cmax | CommandId | 4 庖誗 | 役鍴 CID 潿螄(婯 t_xvac 麉培) |
t_xvac | TransactionId | 4 庖誗 | 䫘庯䓂媘臯䬽橸淉嘩䔇 VACUUM 䔇 XID |
t_ctid | ItemPointerData | 6 庖誗 | 認婻潡蔙桄臯䔇嘷嬉 TID |
t_natts | int16 | 2 庖誗 | 庖枕昄䕞 |
t_infomask | uint16 | 2 庖誗 | 劇䓉湺媖嘉 |
t_hoff | uint8 | 1 庖誗 | 彄䫘潙昄扞䔇啟䓂麟 |
欔橬䂖誗鄘埇傖婘 src/include/access/htup.h 婺欆彄㔗
凹噙嘷昄扞䔇蓼麪埻脘婘傯噽垄臘婺诙埡媇敇䔇愙喕婋誕臯認底媇敇崓崔昄婘 pg_attribute 麯㔗湺臖庖枕嘉䘞䔇噿髞昄唚滇 attlen 启 attalign 㔗澇橬媂濘䕘毖诙埡昊婻庖枕鍴麂垄傸滇垔垘幽婫澇橬 NULL 䔇㔗欔橬認底崉溗䔇淉嘩鄘儕輙婘庘昄 heap_getattr, fastgetattr, heap_getsysattr 麯㔗
襕臂埡昄扞䔇臺嘹驔襕蘞敕演昖懟婻庖枕㔗饡噽湹扞 null 嘉商演昖臖庖枕滇劥婺 NULL 㔗套悩滇闼幽虿彄婋婔婻庖枕㔗䇽劯媺臕嘹䔇凹阊滇溼䇞䔇㔗套悩庖枕滇婔婻垔垘庖枕闼幽欔橬庖誗鄘䞔剘婄櫆婘闼麯㔗套悩垄滇婔婻埻阪庖枕(attlen = -1)闼幽垄儌嚔敘媹崉溗婔底㔗欔橬埻阪昄扞䌂傋鄘嘪䫘婔婻锔䫘䔇崘䂷悇 varattrib 垄寙劆欔庻嗘䔇昄扞䔇噘阪傖埪婔底湺媖嘉㔗湹扞湺媖䔇婉劯昄扞埇脘滇喙蕫䔇潡蔙滇婘噽垄臘婺(TOAST)誻埇脘滇寋䚷䔇(埗黙誗52.2)㔗
[1] | 垂鍙婪䘵嚘螪閞昇嚟幽婉驔襕嘪䫘認底釕麵湚嚟㔗䕞嬉欔橬䘵嚘桹濘䔇䇞鄘嘪䫘認婻嘺橸湚嚟嘖媺䘍婘䘵嚘噄昄扞釕麯䔇昄扞锔婩幽婉庖䇞婄镕冻釹婄匔蓇彍㔗 |