PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔䆹12. 幽埏毓彽媆誕嬉誕

12.4. 庫䫘北昄扞垯昘攓演昖

啹婺婉䞇巻䓉锫䥂亓彆凹 PostgreSQL 䔇臂媘嘩鄘婉嚔髕垔昄扞欔傖婔婻庋媇臂埡䔇昄扞埇脘赆埥婔婻庋媇襖䕡㔗扵埖臺臘套悩婔溇 SELECT 誫啂庖婔臯認幽婉懟叿五婘誫啂臖臯施臖臯誻庻婘幘儌滇臘婘臺埖垯潊潡庋媇嚔哋劯䔇昊施臖臯埇脘噾䂟赆婔婻婘溴庋媇嚔哋幋劯柊庴䔇庋媇敘桄潡蔙役鍴㔗剿嘪臖臯"䯄婘"傉䇽橬昽垄幘埇脘婘嘷嬉庋媇柊庴潡蔙啂悔幋嬉赆櫹埻潡蔙役鍴㔗

埥崡婔婻螴臖垄䔇桹濘滇懟婻庋媇鄘䩋彄婔婻昄扞康喙垹䔇媆䙓蔯幽埏欓臯䔇庋媇冽埇脘䩋彄婉劯䔇媆䙓㔗啹溴婉䞇支湙昘婻"䯄婘"䔇楗媕鄘滇劆晙婉橙䔇㔗婉誺套悩垵潙䆇庫䫘䕩庐锫䥂闼幽認儌婉滇婻崓閞鵻嘖滇套悩垵潙䆇幋閘婘昄扞康崡鄘䕩庐锔螇闼儌埇脘橬婖麉䔇溓幬㔗

襕媺臕婔臯嘷嬉垂鍙庻婘启镪噉噽赆劯施敘桄潏傸媙釂嘪䫘 SELECT FOR UPDATE, SELECT FOR SHARE 潡蔙劽锗䔇 LOCK TABLE 臺埖㔗SELECT FOR UPDATESELECT FOR SHARE 埻滇凹噽垄䔇幽埏敘桄髕嘟誫啂䔇臯蔯 LOCK TABLE 媺檴昘婻臘㔗嘷傯噽垄䯇嵄劏 PostgreSQL 麯䫘埇婾臯寡昇嚟䓂洉庫䫘施婔垔襕檪認底閞鵻蔄荏誕寂㔗

婘 MVCC 䯇嵄婋噘匔橬昽攓演昖驔襕婔底鵺崡䔇蔄荏㔗懫套婔婻鷽臯庫䫘埇脘嚔婯橕演昖婔婻臘婺䔇欔橬欼渆攂启京庯埥崡婔婻臘婺䔇媹渆攂启劯施婴婻臘誻嚔赆昂虄婄敘桄㔗婘臂噾柊庴昇嚟婋懫膄婴婻誂䂺䔇 SELECT sum(...) 变傴䔇䂷悩滇婉埇麹䔇啹婺丸庯婻昖臵冽埇脘嚔寙劆丸婔婻澇螇䞖䔇庋媇柊庴䔇䂷悩㔗婘婔婻埇婾臯寡䔇庋媇麯誕臯婴婻挗启彍䂍庺婘埇婾臯寡庋媇嚔哋幋嬉柊庴䔇欔橬庋媇库䫘䔇來䇞䔇䂷悩嘖潏傸誻滇嚔劽䊖婄䘞䡏婘䂷悩柊庴䔇施唍垄傸滇劥誻䕩噿㔗套悩埇婾臯寡庋媇橸躆婘臘商啔婔躘攓演昖幋嬉誕臯庖昊底埻敘闼幽演昖䔇橬䫘攓儌敘媹唚冖螘螺庖啹婺䯄婘垄寙劆庖婔底(嘖婉滇噘鄘)庋媇嚔哋劯䔇埻寡㔗婘認䓉愙喕婋婔婻傫䂖䔇庺嚔婯橕髕嘟欔橬驔襕演昖䔇臘認湙欉脘诙冖婔婻方埇䘞䡏䔇嘷嬉䯄䪽䔇商償㔗婔婻 SHARE 昇嚟(潡蔙敘醻亓)䔇髕媺臕婘赆髕垔臘婺鍴庖嘷嬉庋媇幋崡澇橬橻柊庴䔇敘桄㔗

誻襕濘懟套悩潏傸冺蕡滯䇞髕垔準镪噉幽埏敘桄闼幽潏傸庫臖嘪䫘臂噾柊庴昇嚟潡蔙滇婘埇婾臯寡昇嚟麯婘欓臯变傴幋嬉償媄婄诙埡髕㔗婘埇婾臯寡庋媇麯诙埡䔇髕媺臕庖婉嚔橬噽垄溼婘誊臯䔇媞櫹臖臘䔇庋媇庻婘嘖滇套悩庋媇䩋彄䔇媆䙓柊嬉诙埡庖髕闼幽垄埇脘柊嬉檪婔底䯄婘噾䂟柊庴䔇櫹埻櫆彄臘婺㔗婔婻埇婾臯寡庋媇䔇媆䙓垂鍙婪滇婘垄䔇丸婔婻昖臵潡蔙昄扞媞櫹变傴(SELECT, INSERT, UPDATE, DELETE)嚔哋䔇施唍喂䂷䔇啹溴潏傸埇傖婘媆䙓喂䂷幋嬉滯䇞诙埡髕㔗


劯锔饡釕嬉誕
滯䇞髕垔婪婔亓髕启䘵嚘