Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WebエンジニアのためのMySQLデータ構造基礎(再) / mysql data struct...

Mihyaeru
April 25, 2018

WebエンジニアのためのMySQLデータ構造基礎(再) / mysql data structure for web developer 2

Mihyaeru

April 25, 2018
Tweet

More Decks by Mihyaeru

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • ϛώϟΤϧ @mihyaeru21 • ৬ྺ • 2014-04 גࣜձࣾϞόΠϧϑΝΫτϦʔ •

    αϙʔλʔζܦ༝ • Ґஔ৘ใήʔϜ x 3 • 2016-10 freeeגࣜձࣾ • ձܭαʔϏε • ػೳ։ൃͱ͔ύϑΥʔϚϯενϡʔχϯάͱ͔ • ϚΠΫϩαʔϏεతͳ • ओʹαʔόʔαΠυͰΫϥΠΞϯτ΋΍Δ
  2. ͳͥ஌Δඞཁ͕͋Δͷ͔ • Web։ൃͰ͸ORMΛ࢖͏͜ͱ͕ଟ͍ʢͨͿΜʣ • ORM͸͍Ζ͍Ζͱศར • ൓໘... • ͲΜͳΫΤϦʹͳΔͷ͔Θ͔Γʹ͍͘৔߹͋Γ •

    ࣮ଶ͕DBͰɺSQLΛ࣮ߦ͍ͯ͠Δҙ͕ࣝബΕ͕ͪ • ࣮ଶΛҙࣝ͠ͳ͍ͱ... • ਂࠁͳύϑΥʔϚϯε໰୊ͷՄೳੑ • DBಛ༗ͷڍಈͰϋϚΔ
  3. αʔόʔ ετϨʔδΤϯδϯ ετϨʔδΤϯδϯ • σʔλͷӬଓԽΛ࢘Δ • ΠϯσοΫε • τϥϯβΫγϣϯ •

    ετϨʔδΤϯδϯAPI • ετϨʔδΤϯδϯ͸໨తʹԠͯ͡
 બͿ͜ͱ͕Ͱ͖Δ
  4. ༷ʑͳετϨʔδΤϯδϯ • InnoDB • MyISAM • MEMORY • CSV •

    BLACKHOLE • MyRocks • etc... (see https://dev.mysql.com/doc/refman/5.6/ja/storage-engines.html )
  5. ͦͷଞ • MEMORY • ϝϞϦ಺ͷΈɻফ͑ͯ΋໰୊ͳ͍σʔλ͚ͩ • CSV • CSVϑΝΠϧʹอଘ͞ΕΔ •

    BLACKHOLE • Կ΋อଘ͠ͳ͍ʢʁʂʣ • MyRocks • Facebook͕InnoDBͰਏ͘ͳͬͯ࡞ͬͨ΍ͭ • লσΟεΫεϖʔεɺߴॻ͖ࠐΈੑೳ
  6. B໦ 8 13 2 2 3 3 6 6 8

    8 9 9 15 15 10 10 20 20 28 28
  7. B໦ 8 13 2 2 3 3 6 6 8

    8 9 9 15 15 10 10 20 20 28 28 ϊʔυ ※Ϧʔϑϊʔυͷදݱํ๏͸͍͔ͭ͋͘Γ·͢ ※͜ͷਤͰ͸Լଆͷ3͕ͭϦʔϑϊʔυʹͳΓ·͢
  8. B໦ 8 13 2 2 3 3 6 6 8

    8 9 9 15 15 10 10 20 20 28 28 Ωʔ
  9. B໦ 8 13 2 2 3 3 6 6 8

    8 9 9 15 15 10 10 20 20 28 28 ϊʔυΛࢦ͢ϙΠϯλ
  10. B໦ 8 13 2 2 3 3 6 6 8

    8 9 9 15 15 10 10 20 20 28 28 ֨ೲ͞ΕΔ஋
  11. B໦: ݕࡧ 8 13 2 2 3 3 6 6

    8 8 9 9 15 15 10 10 20 20 28 28 ݕࡧ஋x͕9
  12. B໦: ݕࡧ 8 13 2 2 3 3 6 6

    8 8 9 9 15 15 10 10 20 20 28 28 8 ≦ x < 13 ݕࡧ஋x͕9
  13. B໦: ݕࡧ 8 13 2 2 3 3 6 6

    8 8 9 9 15 15 10 10 20 20 28 28 ݕࡧ஋x͕9 8 ≦ x < 13 x = 9
  14. B໦: ݕࡧ 8 13 2 2 3 3 6 6

    8 8 9 9 15 15 10 10 20 20 28 28 ݕࡧ஋x͕9 8 ≦ x < 13 x = 9
  15. B+໦ 8 13 2 2 3 3 6 6 8

    8 9 9 10 10 15 15 20 20 28 28
  16. B+໦ 8 13 2 2 3 3 6 6 8

    8 9 9 10 10 15 15 20 20 28 28 Ϧʔϑϊʔυͷ຤ඌ͕࣍ͷϦʔϑϊʔυΛࢦ͢
  17. B+໦ 8 13 2 2 3 3 6 6 8

    8 9 9 10 10 15 15 20 20 28 28 ιʔτࡁΈͷ஋Λૉૣ͘ಡΈऔΕΔ
  18. ΠϯσοΫε ओΩʔ͕ೖΔ 8 13 2 4 3 8 6 7

    8 1 9 6 10 2 15 5 20 3 28 9
  19. ηΧϯμϦΠϯσοΫε 8 13 2 4 3 8 6 7 8

    1 9 6 10 2 15 5 20 3 28 9 • ओΩʔҎ֎ͷΠϯσοΫε͸ࠓઆ໌ͨ͠ߏ଄ • ηΧϯμϦΠϯσοΫεͱݺͿ
  20. ςʔϒϧͷσʔλߏ଄ 4 7 1 2 ্ా 4/29 10 3 ࡾӜ

    7/5 8 ໊લ ஀ੜ೔ ฒͼॱ ্໺ 1/8 20 4 5 தౡ 1/16 15 6 தࢁ 12/27 2 த઒ 2/2 9 7 8 த໺ 3/13 3 9 தଜ 11/25 6 Ճ౻ 9/23 28
  21. ςʔϒϧͷσʔλߏ଄ 4 7 1 2 ্ా 4/29 10 3 ࡾӜ

    7/5 8 ໊લ ஀ੜ೔ ฒͼॱ ্໺ 1/8 20 4 5 தౡ 1/16 15 6 தࢁ 12/27 2 த઒ 2/2 9 7 8 த໺ 3/13 3 9 தଜ 11/25 6 Ճ౻ 9/23 28 B+໦ͷߏ଄ͦͷ·· Ϧʔϑϊʔυʹ࣮σʔλ͕ೖ͍ͬͯΔ
  22. ςʔϒϧͷσʔλߏ଄ 4 7 1 2 ্ా 4/29 10 3 ࡾӜ

    7/5 8 ໊લ ஀ੜ೔ ฒͼॱ ্໺ 1/8 20 4 5 தౡ 1/16 15 6 தࢁ 12/27 2 த઒ 2/2 9 7 8 த໺ 3/13 3 9 தଜ 11/25 6 Ճ౻ 9/23 28 • ओΩʔͰΫϥελԽ͞Ε͍ͯΔ • ΫϥελԽΠϯσοΫε
  23. ηΧϯμϦΠϯσοΫεΛ࢖ͬͨݕࡧ 8 13 2 4 3 8 6 7 8

    1 9 6 10 2 15 5 20 3 28 9 select * from users where ฒͼॱ = 10;
  24. ηΧϯμϦΠϯσοΫεΛ࢖ͬͨݕࡧ 8 13 2 4 3 8 6 7 8

    1 9 6 10 2 15 5 20 3 28 9 ฒͼॱ = 10
  25. ηΧϯμϦΠϯσοΫεΛ࢖ͬͨݕࡧ 8 13 2 4 3 8 6 7 8

    1 9 6 10 2 15 5 20 3 28 9 ฒͼॱ = 10 ओΩʔ = 2
  26. ηΧϯμϦΠϯσοΫεΛ࢖ͬͨݕࡧ 8 13 2 4 3 8 6 7 8

    1 9 6 10 2 15 5 20 3 28 9 ฒͼॱ = 10 4 7 1 2 ্ా 4/29 10 3 ࡾӜ 7/5 8 ໊લ ஀ੜ೔ ฒͼॱ ্໺ 1/8 20 4 5 தౡ 1/16 15 6 தࢁ 12/27 2 த઒ 2/2 9 7 8 த໺ 3/13 3 9 தଜ 11/25 6 Ճ౻ 9/23 28
  27. ηΧϯμϦΠϯσοΫεΛ࢖ͬͨݕࡧ 8 13 2 4 3 8 6 7 8

    1 9 6 10 2 15 5 20 3 28 9 ฒͼॱ = 10 4 7 1 2 ্ా 4/29 10 3 ࡾӜ 7/5 8 ໊લ ஀ੜ೔ ฒͼॱ ্໺ 1/8 20 4 5 தౡ 1/16 15 6 தࢁ 12/27 2 த઒ 2/2 9 7 8 த໺ 3/13 3 9 தଜ 11/25 6 Ճ౻ 9/23 28
  28. ςʔϒϧ • id • ໊લ • ஀ੜ೔ • ݂ӷܕ •

    ฒͼॱʢ͖ͯͱʔͳ਺ࣈʣ • ి࿩൪߸ʢNULLͷ৔߹͋Γʣ • 100ສߦ • αϯϓϧσʔλΛੜ੒͢Δ΍ͭ • https://github.com/mihyaeru21/mysql-sample-generator
  29. ΠϯσοΫε͕࢖͑ͳ͍ͱͲ͏ͳΔͷ͔ • 100ສߦΛݟ͍ͯͬͯɺWHERE۟ͷ৚ ݅ʹҾ͔͔ͬΒͳ͍ߦΛࣺͯΔ αʔόʔ ετϨʔδΤϯδϯ όοϑΝϓʔϧ ετϨʔδ ໊લΧϥϜ͕ʮՃ౻ʯʁ໊લΧϥϜ͕ʮՃ ౻ʯʁ໊લΧϥϜ͕ʮՃ౻ʯʁ໊લΧϥϜ͕

    ʮՃ౻ʯʁ໊લΧϥϜ͕ʮՃ౻ʯʁ໊લΧϥ Ϝ͕ʮՃ౻ʯʁ໊લΧϥϜ͕ʮՃ౻ʯʁ໊લ ΧϥϜ͕ʮՃ౻ʯʁ໊લΧϥϜ͕ʮՃ౻ʯʁ ໊લΧϥϜ͕ʮՃ౻ʯʁ໊લΧϥϜ͕ʮՃ ౻ʯʁ໊લΧϥϜ͕ʮՃ౻ʯʁ໊લΧϥϜ͕ ʮՃ౻ʯʁ໊લΧϥϜ͕ʮՃ౻ʯʁ໊લΧʜ
  30. ΠϯσοΫε͕࢖͑ͳ͍ͱͲ͏ͳΔ͔ • σϞ • explainΛݟΔ • explain select * from

    users where name = 'Ճ౻'\G • explain select * from slow_users where name = 'Ճ౻'\G
  31. ΠϯσοΫε͸ࠨ͔Βӈ • ΠϯσοΫεͷΩʔ͸ࠨ୺͔Β͔͠࢖͑ͳ͍ • LIKEͰ͸%͕લʹ͋Δͱ࢖͑ͳ͍ • ࠨ୺͕ෆఆ͔ͩΒ • ࠨ୺͔Βݟ͍ͯ͘ͳΒɺ్த·ͰͰ΋OK •

    σϞ • select * from users where name like 'ాத%' limit 1\G • select * from users where name like '%ాத' limit 1\G
  32. ΠϯσοΫε͸ࠨ͔Βӈ ాத ݈ଠ த઒ ᣦࢠ ాத ͘͞Β 68407 ాத Ұً

    11322 ాத Ұ࿠ 75891 ాத ಸʑ 58408 த઒ ঊ 604143 த઒ ༔ਅ 547645
  33. ΠϯσοΫε͸ࠨ͔Βӈ ాத ݈ଠ த઒ ᣦࢠ ాத ͘͞Β 68407 ాத Ұً

    11322 ాத Ұ࿠ 75891 ాத ಸʑ 58408 த઒ ঊ 604143 த઒ ༔ਅ 547645 ాத%
  34. ΠϯσοΫε͸ࠨ͔Βӈ ాத ݈ଠ த઒ ᣦࢠ ాத ͘͞Β 68407 ాத Ұً

    11322 ాத Ұ࿠ 75891 ాத ಸʑ 58408 த઒ ঊ 604143 த઒ ༔ਅ 547645 ాத% ాதͰ࢝·͍ͬͯΔ෦෼͚ͩݟΔ
  35. ΠϯσοΫε͸ࠨ͔Βӈ ాத ݈ଠ த઒ ᣦࢠ ాத ͘͞Β 68407 ాத Ұً

    11322 ాத Ұ࿠ 75891 ాத ಸʑ 58408 த઒ ঊ 604143 த઒ ༔ਅ 547645 ాத%
  36. ΠϯσοΫε͸ࠨ͔Βӈ ాத ݈ଠ த઒ ᣦࢠ ాத ͘͞Β 68407 ాத Ұً

    11322 ాத Ұ࿠ 75891 ాத ಸʑ 58408 த઒ ঊ 604143 த઒ ༔ਅ 547645 ాத%
  37. ΠϯσοΫε͸ࠨ͔Βӈ ాத ݈ଠ த઒ ᣦࢠ ాத ͘͞Β 68407 ాத Ұً

    11322 ాத Ұ࿠ 75891 ాத ಸʑ 58408 த઒ ঊ 604143 த઒ ༔ਅ 547645 %ాத
  38. ΠϯσοΫε͸ࠨ͔Βӈ ాத ݈ଠ த઒ ᣦࢠ ాத ͘͞Β 68407 ాத Ұً

    11322 ాத Ұ࿠ 75891 ాத ಸʑ 58408 த઒ ঊ 604143 த઒ ༔ਅ 547645 %ాத
  39. ΠϯσοΫε͸ࠨ͔Βӈ ాத ݈ଠ த઒ ᣦࢠ ాத ͘͞Β 68407 ాத Ұً

    11322 ాத Ұ࿠ 75891 ాத ಸʑ 58408 த઒ ঊ 604143 த઒ ༔ਅ 547645 %ాத จࣈྻࠨଆ(ઌ಄ଆ)͔Βιʔτ͞ΕͯΔ͔Β
 ιʔτ͞Ε͍ͯΔ͜ͱΛੜ͔ͤͳ͍
  40. ෳ߹ΠϯσοΫε • ෳ਺ͷΧϥϜΛ·ͱΊͯΠϯσοΫεΛுΔ • ΠϯσοΫεͷҰ෦͚ͩΛ࢖͏͜ͱ΋Ͱ͖Δ • ͜͜Ͱ΋ࠨ͔Βӈ͕ग़ͯ͘Δ • σϞ •

    select count(*) from users where blood_type = 'A' and name like 'ాத%'\G • select count(*) from users where blood_type = 'A'\G
  41. ෳ߹ΠϯσοΫε A, ాத ݈ଠ B, த઒ ᣦࢠ A, ాத ͘͞Β

    68407 A, ాத Ұً 11322 A, த઒ Ұ࿠ 75891 A, த઒ ಸʑ 58408 B, த઒ ঊ 604143 B, த઒ ༔ਅ 547645
  42. ෳ߹ΠϯσοΫε: ෳ߹৚݅ʹΑΔݕࡧ A, ాத ݈ଠ B, த઒ ᣦࢠ A, ాத

    ͘͞Β 68407 A, ాத Ұً 11322 A, த઒ Ұ࿠ 75891 A, த઒ ಸʑ 58408 B, த઒ ঊ 604143 B, த઒ ༔ਅ 547645 A, ాத%
  43. ෳ߹ΠϯσοΫε: ෳ߹৚݅ʹΑΔݕࡧ A, ాத ݈ଠ B, த઒ ᣦࢠ A, ాத

    ͘͞Β 68407 A, ాத Ұً 11322 A, த઒ Ұ࿠ 75891 A, த઒ ಸʑ 58408 B, த઒ ঊ 604143 B, த઒ ༔ਅ 547645 A, ాத%
  44. ෳ߹ΠϯσοΫε: ෳ߹৚݅ʹΑΔݕࡧ A, ాத ݈ଠ B, த઒ ᣦࢠ A, ాத

    ͘͞Β 68407 A, ాத Ұً 11322 A, த઒ Ұ࿠ 75891 A, த઒ ಸʑ 58408 B, த઒ ঊ 604143 B, த઒ ༔ਅ 547645 A, ాத%
  45. ෳ߹ΠϯσοΫε: ෳ߹৚݅ʹΑΔݕࡧ A, ాத ݈ଠ B, த઒ ᣦࢠ A, ాத

    ͘͞Β 68407 A, ాத Ұً 11322 A, த઒ Ұ࿠ 75891 A, த઒ ಸʑ 58408 B, த઒ ঊ 604143 B, த઒ ༔ਅ 547645 A, ాத%
  46. ෳ߹ΠϯσοΫε: Ұ෦ͷ৚݅ʹΑΔݕࡧ(OK) A, ాத ݈ଠ B, த઒ ᣦࢠ A, ాத

    ͘͞Β 68407 A, ాத Ұً 11322 A, த઒ Ұ࿠ 75891 A, த઒ ಸʑ 58408 B, த઒ ঊ 604143 B, த઒ ༔ਅ 547645 A
  47. ෳ߹ΠϯσοΫε: Ұ෦ͷ৚݅ʹΑΔݕࡧ(OK) A, ాத ݈ଠ B, த઒ ᣦࢠ A, ాத

    ͘͞Β 68407 A, ాத Ұً 11322 A, த઒ Ұ࿠ 75891 A, த઒ ಸʑ 58408 B, த઒ ঊ 604143 B, த઒ ༔ਅ 547645 A
  48. ෳ߹ΠϯσοΫε: Ұ෦ͷ৚݅ʹΑΔݕࡧ(OK) A, ాத ݈ଠ B, த઒ ᣦࢠ A, ాத

    ͘͞Β 68407 A, ాத Ұً 11322 A, த઒ Ұ࿠ 75891 A, த઒ ಸʑ 58408 B, த઒ ঊ 604143 B, த઒ ༔ਅ 547645 A
  49. ෳ߹ΠϯσοΫε: Ұ෦ͷ৚݅ʹΑΔݕࡧ(OK) A, ాத ݈ଠ B, த઒ ᣦࢠ A, ాத

    ͘͞Β 68407 A, ాத Ұً 11322 A, த઒ Ұ࿠ 75891 A, த઒ ಸʑ 58408 B, த઒ ঊ 604143 B, த઒ ༔ਅ 547645 A
  50. ෳ߹ΠϯσοΫε: Ұ෦ͷ৚݅ʹΑΔݕࡧ(NG) A, ాத ݈ଠ B, த઒ ᣦࢠ A, ాத

    ͘͞Β 68407 A, ాத Ұً 11322 A, த઒ Ұ࿠ 75891 A, த઒ ಸʑ 58408 B, த઒ ঊ 604143 B, த઒ ༔ਅ 547645 த઒
  51. ෳ߹ΠϯσοΫε: Ұ෦ͷ৚݅ʹΑΔݕࡧ(NG) A, ాத ݈ଠ B, த઒ ᣦࢠ A, ాத

    ͘͞Β 68407 A, ాத Ұً 11322 A, த઒ Ұ࿠ 75891 A, த઒ ಸʑ 58408 B, த઒ ঊ 604143 B, த઒ ༔ਅ 547645 த઒ ݂ӷܕ͕༏ઌ͞Εͯιʔτ͞Ε͍ͯΔ͔Β ໊લ͚ͩͩͱιʔτ͞Ε͍ͯΔ͜ͱΛੜ͔ͤͳ͍
  52. NOTͷѻ͍ • Ұக͍ͤͯ͘͞ͷ͕جຊʹͳΔͨΊΠϯσοΫε͕ޮ ͔ͳ͍ • NOT͸Ͱ͖Δ͚ͩॻ͔ͳ͍Α͏ʹ • σϞ • select

    count(*) from users where name = 'Ճ౻'\G • select count(*) from users where name != 'Ճ౻'\G • select count(*) from users where name like 'Ճ౻%'\G • select count(*) from users where name not like 'Ճ౻%'\G
  53. NULLͷѻ͍ • ࣮͸ΠϯσοΫε͕ޮ͘ • IS NULL • IS NOT NULL

    • ͜ͷڍಈ͸MySQL͚ͩͬΆ͍ • σϞ • select count(*) from users where phone_num is null\G • select count(*) from slow_users where phone_num is null\G • select count(*) from users where phone_num is not null\G • select count(*) from slow_users where phone_num is not null\G
  54. ιʔτ • ݕࡧ͚ͩͰͳ͘ιʔτʹ΋ΠϯσοΫε͕࢖͑Δ • Կ౓΋ग़͖ͯͨΑ͏ʹB+໦ͷϦʔϑ͸ιʔτ͞ΕͯΔ • ෳ߹ΠϯσοΫε͸1൪໨ͰߜΓࠐΜͰ2൪໨Ͱιʔτ Ͱ͖Δ • σϞ

    • select * from users order by order_num limit 1\G • select * from slow_users order by order_num limit 1\G • select * from users where blood_type = 'B' order by birthday limit 1\G • select * from slow_users where blood_type = 'B' order by birthday limit 1\G
  55. ιʔτ A, ాத ݈ଠ B, த઒ ᣦࢠ A, ాத ͘͞Β

    68407 A, ాத Ұً 11322 A, த઒ Ұ࿠ 75891 A, த઒ ಸʑ 58408 B, த઒ ঊ 604143 B, த઒ ༔ਅ 547645 A
  56. ιʔτ A, ాத ݈ଠ B, த઒ ᣦࢠ A, ాத ͘͞Β

    68407 A, ాத Ұً 11322 A, த઒ Ұ࿠ 75891 A, த઒ ಸʑ 58408 B, த઒ ঊ 604143 B, த઒ ༔ਅ 547645 A ઌ಄͕AͰ֬ఆ͍ͯ͠Δͱ͍͏͜ͱ͸
 ΩʔશମͰݟͨΒ໊લͰ΋ιʔτ͞Ε͍ͯΔ
  57. ΧόϦϯάΠϯσοΫε • ηΧϯμϦΠϯσοΫεʹ͸ΩʔͷΧϥϜͱओΩʔؚ͕·ΕΔ • ΫΤϦதͷSELECTɺWHEREɺORDERͳͲ͕ͦΕΒͷΧϥϜ ͷΈͰߏ੒͞Ε͍ͯΕ͹σʔλຊମͷB+໦ΛݟΔඞཁͳ͍ͷ Ͱ͸ʁ • σʔλຊମΛݕࡧ͢Δख͕ؒল͔Εͯߴ଎ʹͳΔ •

    ࢥߟఀࢭͨ͠ঢ়ଶͰORMΛ࢖͏ͱৗʹ SELECT * ʹͳΓɺ͜ͷ Ըܙ͕ड͚ΒΕͳ͘ͳΔ • σϞ • select count(*) from users where name = 'Ճ౻ ܙ'\G • select order_num, name from users order by order_num desc limit 1\G
  58. ΧόϦϯάΠϯσοΫε Ճ౻ ݈ଠ த઒ ᣦࢠ Ճ౻ ܙ 13521 Ճ౻ ܙ

    14491 Ճ౻ ݈հ 75891 த઒ ಸʑ 58408 த઒ ঊ 604143 த઒ ༔ਅ 547645 Ճ౻ ܙ
  59. ΧόϦϯάΠϯσοΫε Ճ౻ ݈ଠ த઒ ᣦࢠ Ճ౻ ܙ 13521 Ճ౻ ܙ

    14491 Ճ౻ ݈հ 75891 த઒ ಸʑ 58408 த઒ ঊ 604143 த઒ ༔ਅ 547645 COUNT(*) ʹඞཁͳ৘ใ͸े෼ʹ଍Γ͍ͯΔ name ͔ id ͰΧ΢ϯτ͞ΕΔ Ճ౻ ܙ
  60. REPEATABLE READ஫ҙ • ৽ଔ1೥໨ͷ࣌ʹɺ͜ΕΛཧղ͍ͯ͠ͳͯ͘DBͷόά ͩͱࢥͬͯ͠·ͬͨ... • σϞ • A: begin;

    • B: begin; • A: select * from users where id = 123456; • B: select * from users where id = 123456 for update; -- ͜ͷ࣌఺ͰഉଞϩοΫ • B: update users set order_num = order_num + 1 where id = 123456; • B: select * from users where id = 123456; • A: select * from users where id = 123456; -- ·ͩίϛοτͯ͠ͳ͍͔ΒมΘͬͯͳ͍ • B: commit; • A: select * from users where id = 123456; -- ίϛοτޙ͚ͩͲมΘͬͯͳ͍ • A: select * from users where id = 123456 for update; -- B͕ίϛοτͨ͠஋ͰऔΕΔ