PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔䆹52. 昄扞康䬷䊖庻嗘媆誕嬉誕

52.3. 昄扞康彖釕桺傽

橸䆹柊冕婔婻臘启䘵嚘欔嘪䫘䔇釕麵湚嚟䔇楗誄㔗[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_lsnXLogRecPtr8 庖誗LSN: 橔劯媞櫹認婻釕麵䔇 xlog 螄嘘橔劯婔婻庖誗劯麵丸婔婻庖誗
pd_tliTimeLineID4 庖誗橔劯媞櫹䔇 TLI
pd_lowerLocationIndex2 庖誗彄躻䫌䷺閘嚔崘䔇啟䓂麟
pd_upperLocationIndex2 庖誗彄躻䫌䷺閘䂷儆䔇啟䓂麟
pd_specialLocationIndex2 庖誗彄䬹枪䷺閘嚔崘䔇啟䓂麟
pd_pagesize_versionuint162 庖誗釕麵崓償启婄匔䬽橸埙媇敇

欔橬䂖誗鄘埇傖婘 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_xminTransactionId4 庖誗某噖 XID 潿螄
t_cminCommandId4 庖誗某噖 CID 潿螄
t_xmaxTransactionId4 庖誗役鍴 XID 潿螄
t_cmaxCommandId4 庖誗役鍴 CID 潿螄(婯 t_xvac 麉培)
t_xvacTransactionId4 庖誗䫘庯䓂媘臯䬽橸淉嘩䔇 VACUUM 䔇 XID
t_ctidItemPointerData6 庖誗認婻潡蔙桄臯䔇嘷嬉 TID
t_nattsint162 庖誗庖枕昄䕞
t_infomaskuint162 庖誗劇䓉湺媖嘉
t_hoffuint81 庖誗彄䫘潙昄扞䔇啟䓂麟

欔橬䂖誗鄘埇傖婘 src/include/access/htup.h 婺欆彄㔗

凹噙嘷昄扞䔇蓼麪埻脘婘傯噽垄臘婺诙埡媇敇䔇愙喕婋誕臯認底媇敇崓崔昄婘 pg_attribute 麯㔗湺臖庖枕嘉䘞䔇噿髞昄唚滇 attlenattalign 㔗澇橬媂濘䕘毖诙埡昊婻庖枕鍴麂垄傸滇垔垘幽婫澇橬 NULL 䔇㔗欔橬認底崉溗䔇淉嘩鄘儕輙婘庘昄 heap_getattr, fastgetattr, heap_getsysattr 麯㔗

襕臂埡昄扞䔇臺嘹驔襕蘞敕演昖懟婻庖枕㔗饡噽湹扞 null 嘉商演昖臖庖枕滇劥婺 NULL 㔗套悩滇闼幽虿彄婋婔婻庖枕㔗䇽劯媺臕嘹䔇凹阊滇溼䇞䔇㔗套悩庖枕滇婔婻垔垘庖枕闼幽欔橬庖誗鄘䞔剘婄櫆婘闼麯㔗套悩垄滇婔婻埻阪庖枕(attlen = -1)闼幽垄儌嚔敘媹崉溗婔底㔗欔橬埻阪昄扞䌂傋鄘嘪䫘婔婻锔䫘䔇崘䂷悇 varattrib 垄寙劆欔庻嗘䔇昄扞䔇噘阪傖埪婔底湺媖嘉㔗湹扞湺媖䔇婉劯昄扞埇脘滇喙蕫䔇潡蔙滇婘噽垄臘婺(TOAST)誻埇脘滇寋䚷䔇(埗黙誗52.2)㔗

濘懟

[1]

垂鍙婪䘵嚘螪閞昇嚟幽婉驔襕嘪䫘認底釕麵湚嚟㔗䕞嬉欔橬䘵嚘桹濘䔇䇞鄘嘪䫘認婻嘺橸湚嚟嘖媺䘍婘䘵嚘噄昄扞釕麯䔇昄扞锔婩幽婉庖䇞婄镕冻釹婄匔蓇彍㔗


劯锔饡釕嬉誕
TOAST婪婔亓BKI 劯䆇毖埼