ãšã³ããªãŒ
SQLæšæºã§ã¯ããã©ã³ã¶ã¯ã·ã§ã³åé¢ã®4ã€ã®ã¬ãã«-ã³ããããããŠããªãèªã¿åããã³ããããããèªã¿åããå埩å¯èœãªèªã¿åããããã³ã·ãªã¢ã«åå¯èœã«ã€ããŠèª¬æããŠããŸãã ãã®èšäºã§ã¯ãåé¢ã¬ãã«ãRead committedããã³Serializableã§ãã4ã€ã®äžŠè¡ãã©ã³ã¶ã¯ã·ã§ã³ã®ã©ã€ããµã€ã¯ã«ã«ã€ããŠèª¬æããŸãã
èªã¿åãã³ãããåé¢ã¬ãã«ã§ã¯ãããŒã¿ã®èªã¿åãã«é¢ãã次ã®ç¹å¥ãªæ¡ä»¶ã蚱容ãããŸãã
ç¹°ãè¿ãäžå¯ã®èªã¿åã -ãã©ã³ã¶ã¯ã·ã§ã³ã¯ä»¥åãšåãããŒã¿ãåèªã¿åãããå¥ã®ãã©ã³ã¶ã¯ã·ã§ã³ïŒæåã®èªã¿åãåŸã«çµäºããïŒã«ãã£ãŠå€æŽãããããšãæ€åºããŸãã
å¹»åèªã¿åã -ãã©ã³ã¶ã¯ã·ã§ã³ã¯ãç¹å®ã®æ¡ä»¶ã®è¡ã»ãããè¿ãã¯ãšãªãç¹°ãè¿ãå®è¡ãããã®æéå ã«å®äºãããã©ã³ã¶ã¯ã·ã§ã³ã«ãã£ãŠæ¡ä»¶ãæºãããŠããè¡ã»ãããå€æŽãããããšãæ€åºããŸãã
Serializableã«é¢ããŠã¯ããã®åé¢ã¬ãã«ã¯æãå³æ Œã§ãããããŒã¿èªã¿åãçŸè±¡ã¯ãããŸããã
ACIDãŸãã¯4ã€ã®ãã©ã³ã¶ã¯ã·ã§ã³ããããã£
ãã©ã³ã¶ã¯ã·ã§ã³ã®åé¢ã¬ãã«ãæ°èªã§æ€èšããåã«ããã©ã³ã¶ã¯ã·ã§ã³ã·ã¹ãã ã®åºæ¬çãªèŠä»¶ãæãåºããŠã¿ãŸãããã
ã¢ãããã¯æ§ ïŒã¢ãããã¯æ§ïŒ-ãã©ã³ã¶ã¯ã·ã§ã³ãå šäœãšããŠå®äºããå¿ èŠããããããŸã£ããå®äºããªãå¿ èŠããããšããäºå®ã§è¡šçŸãããŸãã
äžè²«æ§ -ãã©ã³ã¶ã¯ã·ã§ã³ãå®äºãããšãããŒã¿ãäžè²«ããç¶æ ããå¥ã®ç¶æ ã«ç§»è¡ããããšãä¿èšŒããŸããã€ãŸãããã©ã³ã¶ã¯ã·ã§ã³ã¯ããŒã¿ã®çžäºäžè²«æ§ãç Žå£ã§ããŸããã
åé¢ -ãŠãŒã¶ãŒããã»ã¹ã®åé¢ãšã¯ãããŒã¿ããŒã¹ãžã®ã¢ã¯ã»ã¹ã競åãããã©ã³ã¶ã¯ã·ã§ã³ããäºãã«åé¢ããŠé 次ç©ççã«åŠçãããããšãæå³ããŸããããŠãŒã¶ãŒã«ãšã£ãŠã¯ã䞊åã«å®è¡ãããŠããããã«èŠããŸãã
èä¹ æ§ -ãšã©ãŒãã¬ã©ã³ã¹-ãã©ã³ã¶ã¯ã·ã§ã³ãæ£åžžã«å®äºããå ŽåãããŒã¿ã®å€æŽã¯ã©ã®ãããªç¶æ³ã§ã倱ãããããšã¯ãããŸããã
ã³ããããããåé¢ã¬ãã«ã®èªã¿åã
ããã©ã«ãã§ã¯ãPostgreSQLã«ã¯Read Committedåé¢ã¬ãã«ããããŸãã ãã®ã¬ãã«ã®åé¢ã«ãããæ£åžžã«å®äºãããã©ã³ã¶ã¯ã·ã§ã³ã«ãã£ãŠè¡ãããå€æŽããæ®ãã®äžŠåãªãŒãã³ãã©ã³ã¶ã¯ã·ã§ã³ã§åžžã«ç¢ºèªã§ããŸãã ãã®ã¬ãã«ã§å®è¡ãããŠãããã©ã³ã¶ã¯ã·ã§ã³ã§ã¯ãSELECTã¯ãšãªïŒFOR UPDATE / SHAREå¥ãªãïŒã¯ãã¯ãšãªã®éå§åã«ã³ããããããããŒã¿ã®ã¿ãåç §ããŸãã ã³ããããããŠããªãããŒã¿ãã䞊åãã©ã³ã¶ã¯ã·ã§ã³ã«ããèŠæ±ã®å®è¡äžã«è¡ãããå€æŽã¯è¡šç€ºãããŸããã åºæ¬çã«ãSELECTã¯ãšãªã¯ãã¯ãšãªã®éå§æã«ããŒã¿ããŒã¹ã®ã¹ãããã·ã§ãããåç §ããŸãã ãã ããSELECTã¯ããŸã ã³ããããããŠããªãå Žåã§ããåããã©ã³ã¶ã¯ã·ã§ã³ã§ä»¥åã«è¡ãããå€æŽã®çµæã確èªããŸãã ãŸããæåã®SELECTã®åŸã«ä»ã®ãã©ã³ã¶ã¯ã·ã§ã³ãå€æŽãã³ããããããšã2ã€ã®é£ç¶ããSELECTã¹ããŒãã¡ã³ããåããã©ã³ã¶ã¯ã·ã§ã³å ã§ãç°ãªãããŒã¿ãèŠãããšãã§ããããšã«æ³šæããŠãã ããã
Read Committedåé¢ã¬ãã«ã®æ¬è³ªãå³1ã«ç€ºããŸãã
泚ïŒããŒãã«ã«ã¯ãããŒã¿ã®æåã®ããŒãžã§ã³ïŒv1ïŒã®ã¬ã³ãŒããæ¢ã«å«ãŸããŠããŸãã SELECT v1ã³ãã³ããåãå ¥ããŠãã ããã -ããŒãžã§ã³v1ã®ããŒã¿ãè¿ããv1ãv2ã«æŽæ°ããã³ãã³ããšããŠã -æåã®ããŒãžã§ã³ãã2çªç®ã®ããŒãžã§ã³ã«ããŒã¿ãæŽæ°ããã³ãã³ããšããŠã
ã泚æ ãã®å³ã¯ãINSERTã¯ãšãªã®å¹æã瀺ããŠããŸããã ãã®åé¢ã¬ãã«å ã§ã¯ãããšãã°ã¹ããã3ã§æåã®ãã©ã³ã¶ã¯ã·ã§ã³ã«è¿œå ãããè¡ã¯ãæåã®ãã©ã³ã¶ã¯ã·ã§ã³ã®å®äºåŸã«ä»ã®ãã©ã³ã¶ã¯ã·ã§ã³ããèŠããããã«ãªããŸãã
Read Committedã¢ãŒãã§æäŸãããéšåçãªãã©ã³ã¶ã¯ã·ã§ã³åé¢ã¯ãå€ãã®ã¢ããªã±ãŒã·ã§ã³ã§åãå ¥ããããŸãã ãã®ã¢ãŒãã¯ãã°ããç°¡åã«äœ¿çšã§ããŸããããã¹ãŠã®å Žåã«é©ããŠããããã§ã¯ãããŸããã è€éãªã¯ãšãªãšå€æŽãå®è¡ããã¢ããªã±ãŒã·ã§ã³ã§ã¯ãSerializableãªã©ãããŒã¿ã®ããäžè²«ãã衚瀺ãå¿ èŠã«ãªãå ŽåããããŸãã
ã·ãªã¢ã©ã€ãºå¯èœãªåé¢ã¬ãã«
ã·ãªã¢ã©ã€ãºå¯èœãªåé¢ã¯ãSELECTã¯ãšãªã䜿çšããŠåŠšããããªããã©ã³ã¶ã¯ã·ã§ã³ããŒã¿ããŒã¹ã¢ã¯ã»ã¹ãæäŸããŸãã ãã ããUPDATEããã³DELETEã¯ãšãªã䜿çšãããã©ã³ã¶ã¯ã·ã§ã³ã®å ŽåãSerializableã®åé¢ã¬ãã«ã§ã¯ãç°ãªããã©ã³ã¶ã¯ã·ã§ã³å ã§åãè¡ãå€æŽã§ããŸããã ãã®ã¬ãã«ã®åé¢ã§ã¯ããã¹ãŠã®ãã©ã³ã¶ã¯ã·ã§ã³ã¯ããã¹ãŠé çªã«ïŒæ¬¡ã ã«ïŒéå§ããããã®ããã«åŠçãããŸãã 2ã€ã®åæãã©ã³ã¶ã¯ã·ã§ã³ãåãè¡ãæŽæ°ããããšãããšãããã¯äžå¯èœã«ãªããŸãã ãã®å ŽåãPostgreSQLã¯ãã©ã³ã¶ã¯ã·ã§ã³ã匷å¶çã«å®è¡ãã2çªç®ä»¥éã®ãã¹ãŠã®ãã©ã³ã¶ã¯ã·ã§ã³ããã£ã³ã»ã«ããããã«è¡ãå€æŽããããšããŸããïŒããŒã«ããã¯-ROLLBACKïŒã
Serializableåé¢ã¬ãã«ã®æ¬è³ªãå³2ã«ç€ºããŸãã
ã泚æ ãã®å³ã¯ãINSERTã¯ãšãªã®å¹æã瀺ããŠããŸããã ãã®åé¢ã¬ãã«å ã§ã¯ãããšãã°ã¹ããã3ã§æåã®ãã©ã³ã¶ã¯ã·ã§ã³ã«è¿œå ãããè¡ã¯ãæåã®ãã©ã³ã¶ã¯ã·ã§ã³ã®å®äºåŸã2çªç®ã3çªç®ãããã³4çªç®ã®ãã©ã³ã¶ã¯ã·ã§ã³ã«äœ¿çšã§ããŸããã ãŸããROLLBACKã®çµæã¯å³ã«ç€ºãããŠããŸããïŒã¹ããã8ããã³11ïŒã 2çªç®ãš3çªç®ã®ãã©ã³ã¶ã¯ã·ã§ã³ãããã¯ãããŠããªãããŒã¿ã«å€æŽãå ããå Žåããã©ã³ã¶ã¯ã·ã§ã³ã倱æããããããããã®ãã¹ãŠã®å€æŽã¯ã³ããããããŸããïŒããããã£ã®æ¬è³ªã¯Atomicityã§ãïŒã
Serializableã®åé¢ã¬ãã«ã¯ããã©ã³ã¶ã¯ã·ã§ã³ã®åœ±é¿ãåãããã¹ãŠã®ããŒã¿ãä»ã®ãã©ã³ã¶ã¯ã·ã§ã³ã«ãã£ãŠå€æŽãããªãããã«ããŸãã ãã®ã¬ãã«ã§ã¯ãããã¡ã³ãã ãã®åºçŸã¯é€å€ããããããè€éãªç«¶äºçæäœãå¯èœã«ãªããŸãã å®éã«ã¯ãäŒèšã·ã¹ãã ã§ã¯ãã®ã¬ãã«ã®åé¢ãå¿ èŠã§ãã
SELECTã¯ãšãªã®ã¿ãå«ããã©ã³ã¶ã¯ã·ã§ã³ã®å ŽåãçŸåšã®ãã©ã³ã¶ã¯ã·ã§ã³ã®æäœäžã«äžŠåã«å®äºãããã©ã³ã¶ã¯ã·ã§ã³ã«ãã£ãŠè¡ãããå€æŽãèŠãããªãå ŽåãSerializableã®åé¢ã¬ãã«ã䜿çšããããšã§æ£åœåãããŸãã
ã·ãªã¢ã«åã®ç°åžžïŒææ°ã®æŽæ°ïŒ
ããŒã¿ãèªã¿åãå¥ã®çŸè±¡ã¯ããã©ã³ã¶ã¯ã·ã§ã³ã®ã°ã«ãŒããæ£åžžã«ä¿®æ£ããçµæãããããã®ãã©ã³ã¶ã¯ã·ã§ã³ãé çªã«å®è¡ããããã®ããããçš®é¡ã®ãªãã·ã§ã³ãšççŸãããšããäºå®ã«ãã£ãŠèª¬æãããŸãã
ã·ãªã¢ã«åã®ç°åžžãšå€±ãããæŽæ°ãé¢é£ããçŸè±¡ã§ãããšããäºå®ã«ééãããŠããå Žåã¯ãã³ã¡ã³ãã«ç§ãåããŠãã ããã
PostgreSQL PRO Webãµã€ãã®ããã¥ã¡ã³ãã«ã¯ãRead Committedã§ãã·ãªã¢ã«åã®ç°åžžããèš±å¯ãããŠãããšæžãããŠããŸãã åœå ã®ãŠã£ãããã£ã¢ã¯ãããŒãã«ãç¹ã«PostgreSQLãåç §ããŠãããšäž»åŒµããã®ã§ã¯ãªããRead Commited ã¯ã·ãªã¢ã©ã€ãŒãŒã·ã§ã³ã®ç°åžžãé²ããšæžããŠããŸãã è±èªçãŠã£ãããã£ã¢ã§ã¯ããã®ããŒã¿èªã¿åãã®çŸè±¡ã«ã€ããŠã¯èšåããŠããŸããã ãããããã€ãã®ãŠã£ãããã£ã¢ã¯ãè¡šã®ããŒãžã§ã³ã§ã倱ãããæŽæ°ãçŸè±¡ãåŒçšããŠãããã«ãŒãœã«ã«ããè¿œå ã®ä¿è·ïŒã«ãŒãœã«å®å®æ§ïŒã«ãããRead CommittedãæŽæ°ã®æ倱ãåããªãå¯èœæ§ãããããšã瀺ããŠããŸãã ãŠã¯ã©ã€ãã®ãŠã£ãããã£ã¢ã¯ãã·ã¢èªçã®èšäºããµããŒãããã¹ãã€ã³èªã®ãŠã£ãããã£ã¢ã¯è±èªçã®èšäºããµããŒãããŠããŸãã è±èªçã®PostgreSQLããã¥ã¡ã³ãã¯ãPostgreSQL PROããã¥ã¡ã³ããšéãã¯ãããŸãã ã
ã«ãŒãœã«ã®å®å®æ§ã¯ãrcã«ãŒãœã«ã«æ°ããèªã¿åãæäœïŒãã§ããïŒãè¿œå ãïŒèªã¿åãã«ãŒãœã«ãã€ãŸãã«ãŒãœã«ããã®èªã¿åãïŒãçŸåšã®ã«ãŒãœã«èŠçŽ ã«ããã¯ãèšå®ããããšãèŠæ±ããããšã«ãããSQLã«ãŒãœã«ã®READ COMMITEDã¬ãã«ã®ããã¯åäœãæ¡åŒµããŸãã ããã¯ã¯ãã«ãŒãœã«ã移åããïŒçŸåšã®èŠçŽ ãå€æŽããããŸã§ïŒããããããã¯ã³ãããæäœã«ãã£ãŠéãããããŸã§ä¿æãããŸãã åœç¶ãã«ãŒãœã«ã«ãããã©ã³ã¶ã¯ã·ã§ã³ã®èªã¿åãã¯çŸåšã®è¡ãå€æŽã§ããŸãïŒwc-ã«ãŒãœã«ã«ããæžã蟌ã¿ïŒããã®å Žåãã«ãŒãœã«ã移åããŠãã次ã®è¡ããã§ããããåŸã§ãããã©ã³ã¶ã¯ã·ã§ã³ãã³ãããããããŸã§ãã®è¡ã®æžã蟌ã¿ããã¯ã¯ä¿æãããŸãã
åèšïŒ149ã
ãããã«
ãã©ã³ã¶ã¯ã·ã§ã³åé¢ã¬ãã«ãç解ããããšã¯ããã«ããŠãŒã¶ãŒDBMSã§ããŒã¿ãåŠçããéã®éèŠãªåŽé¢ã§ãã åé¢ã¬ãã«ã«ã¯ãæ確ã«å®çŸ©ãããç¹æ§ãšåäœããããŸãã åé¢ã¬ãã«ãé«ããšã䞊ååŠçæ©èœãäœäžããããã»ã¹ã®ãããããã¯ã®ãªã¹ã¯ãé«ãŸããŸãã ãããã£ãŠãè«çããŒã¿ã®æŽåæ§ãé床ãããã³äžŠåãã«ããŠãŒã¶ãŒåŠçã®å¯èœæ§ã確ä¿ããããã®èŠä»¶ã«å¿ããŠãã¢ããªã±ãŒã·ã§ã³ã®ã¿ã¹ã¯ã«å¿ããã¬ãã«ã®æ£ãã䜿çšãåžžã«éçºè ã®éžæã«ãªããŸãã
æåŠ
» MVCCãã¹ã¯ãªã
ã 13.2ã ãã©ã³ã¶ã¯ã·ã§ã³åé¢
» åé¢ã¬ãã«ã®æ¹å€
» SQLã®ãã©ã³ã¶ã¯ã·ã§ã³åé¢ã®ã¬ãã«ã ããŒãã·ãŒã
» ãã©ã³ã¶ã¯ã·ã§ã³åé¢ã¬ãã«
» ...倱ãããæŽæ°çŸè±¡