Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
データベース再入門
Search
Naoki Sega
July 19, 2014
Programming
6
11k
データベース再入門
第2回ゲームサーバ勉強会(
http://peatix.com/event/42642
)で発表した資料
Naoki Sega
July 19, 2014
Tweet
Share
More Decks by Naoki Sega
See All by Naoki Sega
GC24 Recap: "Building a High-Performance Concurrent Map in Go" and "The Go Contributor Summit"
nsega
0
10
The introduction of my way to learn Go together with Go community
nsega
0
48
The introduction of my way to learn Go for beginners
nsega
1
460
Introduction to singleflight
nsega
0
4.2k
Google Cloud Next '19 Recap
nsega
1
570
Introduction my way to learn Go for beginners
nsega
0
80
Other Decks in Programming
See All in Programming
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
960
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
950
Outline View in SwiftUI
1024jp
1
330
RubyLSPのマルチバイト文字対応
notfounds
0
120
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
140
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Become a Pro
speakerdeck
PRO
25
5k
It's Worth the Effort
3n
183
27k
Building Your Own Lightsaber
phodgson
103
6.1k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
A Modern Web Designer's Workflow
chriscoyier
693
190k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Why Our Code Smells
bkeepers
PRO
334
57k
Transcript
σʔλϕʔεͷ࠶ೖ 2014/7/19 (Sat) ୈ2ճήʔϜαʔόษڧձ
About Me • լ थ twitter:@nsega • ॴଐɿGCREST,Inc
ΞϓϦέʔγϣϯΤϯδχΞ (αʔόαΠυAP/DBಘҙɺωΠςΟϒ࠷ۙΔ) લ৬ɺSIer ͰΞϓϦΤϯδχΞ. • ίϛϡχςΟ • JavaEEษڧձ
About Me • ۀͰɾɾ ेDB(RDBMS/NoSQL) - PostgreSQL, MySQL αʔόར༻ͨ͠αʔϏεͷ։ൃ/ӡ༻ •
ۀ֎Ͱɾɾ • ࣾ/ࣾ֎ษڧձͰNoSQLؔ࿈ͷൃදΛগʑ • ΦʔϜࣾग़൛̓ͭͷσʔλϕʔἐͭͷੈք: MongoDBͷνϟϓλʔ/ϨϏϡʔ
͡Ίʹ • σʔλϕʔεΛͬͨΞϓϦ։ൃͰɺαʔόαΠ υͱͯ͠ܞΘͬͨࢲݸਓͷܦݧͰհͤͯ͞Β ͍·͢ɻ • αʔόαΠυ/DB ͷ͜ͱΛ͋·ΓΒͳ͍ॳ৺ ऀɾதڃऀํ͚ͷ ༰ʹͳ͍ͬͯ·͢ɻ
• ؒҧ͍ɺෆ໌ͳͲ͕͋Εɺ ͝ԕྀͳ͘ποίΜͰ͍ͩ͘͞ɺܴ͠·͢
Agenda
Agenda • σʔλϕʔε ʹ͍ͭͯ • RDBMSͱNoSQL ʹ͍ͭͯ • DB/ςʔϒϧઃܭ ʹ͍ͭͯ
• ࣮ࡍʹݱͰΑ͘ΔTipsհ • ·ͱΊ
σʔλϕʔεʹ͍ͭͯ
ͦͦσʔλϕʔεͱ ͳΜͰ͠ΐ͏͔ʁ
σʔλϕʔεͱʁ • ࠔͬͨͱ͖ͷ wikipedia
http://ja.wikipedia.org/wiki/σʔλϕʔε
σʔλϕʔεʹ σʔλΛอଘͬͯʁ • σʔλϕʔεʹอଘ͢Δʹɺσʔλ͕Ͳ͏͍͏ ܗ͔͕ఆٛ͞ΕΔඞཁ͕͋Δɻ • σʔλϕʔεʹ֨ೲ͢ΔσʔλΛͲͷΑ͏ʹஔ ͢Δ͔Λཧతɾཧతͳଆ໘͔Βنఆ͢Δ ͷ(σʔλϞσϧ)͕ඞཁɻ
σʔλϞσϧͬͯʁ ! • σʔλϞσϧʹɺओʹ࣍ͷछྨ͕ڍ͛ΒΕΔɻ • ֊ܕσʔλϞσϧ • ωοτϫʔΫܕσʔλϞσϧ • ϦϨʔγϣφϧσʔλϞσϧ
(ؔϞσϧ) ↑Α͘ࢲୡ͕͔ͭ͏Ϟσϧ͕͜Ε http://ja.wikipedia.org/wiki/σʔλϕʔε
ϦϨʔγϣφϧσʔλϕʔεʁ • ϦϨʔγϣφϧσʔλϕʔε(RDB)ͱ ϦϨʔγϣφϧσʔλϞσϧʹͱ͍ͮͯ ઃܭɾ։ൃ͞ΕΔσʔλϕʔεɻ • ීஈɺࢲୡ͕σʔλϕʔεͱಡΜͰ͍Δͷ => ϦϨʔγϣφϧσʔλϕʔε(RDB)Λࢦ͢͜ ͱ͕ଟ͍ɻ
RDBMSͷ σʔλΛѻ͏ʹʁ • SQLͷग़൪Ͱ͢ɻ
http://ja.wikipedia.org/wiki/SQL “SQLɺϦϨʔγϣφϧσʔλϕʔεཧγεςϜ (RDBMS) ʹ͓͍ ͯɺσʔλͷૢ࡞ఆٛΛߦ͏ͨΊͷσʔλϕʔεݴޠʢ͍߹Θͤ ݴޠʣͰ͋Δɻ”
RDBMSͷ σʔλΛѻ͏ʹʁ • SQLʹɺେ͖̏ͭ͘ͷׂͷݴޠ͕͋Δɻ • σʔλఆٛݴޠ(DDL) CREATE, DROP, ALTER •
σʔλૢ࡞ݴޠ(DML) INSERT INTO, UPDATE ʙ SET ʙ DELTE FROM, SELECT ʙ FROM ʙ WHERE ʙ • σʔλ੍ޚݴޠ(DCL) GRANT, REVOKE, BEGIN, COMMIT, ROLLBACK, ..etc
RDBMS SQL ΞϓϦέʔγϣϯ • σʔλఆٛ(DDL) • σʔλૢ࡞(DML • σʔλ੍ޚ(DCL) σʔλϕʔε
SQLͰͷର ςʔϒϧ
σʔλϕʔε ͏ඞཁ͋Δͷʁ
Yes ※࣍ͷ݅Λຬͨ͢ͷ
ෳਓͰɺ յΕͨΒେมͳ͜ͱʹ ͳΔσʔλΛؚΉɺ େྔͷσʔλΛѻ͏
σʔλϕʔεͷ͍Ͳ͜Ζ • େྔσʔλͷͷ͔ΒରͷσʔλΛߴʹ୳͍ͨ͠ • େྔσʔλΛϝϞϦͰѻ͍͍ͨ • ো͕ى͖ͨͱ͖ʹɺਝʹϦΧόϦ͍ͨ͠ • σʔλͷߋ৽ΛฒྻੑΛอͪͳ͕Β੍ޚ͍ͨ͠ •
σʔλͷ߹ੑΛอূ͍ͨ͠ http://www.amazon.co.jp/dp/4774150207 (1ষࢀর)
σʔλϕʔεͷ ͓͓͖͍͑ͯͨ͞ಛ1 • ΠϯσοΫε • αʔνʢ୳ࡧ)Λߴʹ͢ΔͨΊͷσʔλߏ • දతͳΠϯσοΫεྫ • B+ΠϯσοΫε
• ϋογϡΠϯσοΫε http://ja.wikipedia.org/wiki/ࡧҾ_(σʔλϕʔε)
B+ΠϯσοΫε ϋογϡΠϯσοΫε 1͔Β7ͷΩʔͱσʔλ d1-d7 ͕ϦϯΫ͞Ε͍ͯΔɻ Ͱࣔ͞Εͨ࿈݁ϦετʹΑͬͯ ॱং௨Γͷૉૣ͍͕ࠪՄೳ http://ja.wikipedia.org/wiki/B+ ݕࡧ͢ΔΩʔͷΛϋογϡ ؔʹ༩͑ͯϨίʔυ͕֨ೲ
͞ΕͨϖʔδΛಛఆ͢Δ http://itpro.nikkeibp.co.jp/article/COLUMN/20060113/227241/
σʔλϕʔεͷ ͓͓͖͍͑ͯͨ͞ಛ2 ! • τϥϯβΫγϣϯॲཧ • σʔλʹର͢ΔҰͭͷཧతૢ࡞ͷࣄΛ τϥϯβΫγϣϯͱݺͿ • σʔλͷ߹ੑΛอͭͨΊʹඞཁͳཁૉ
http://ja.wikipedia.org/wiki/τϥϯβΫγϣϯॲཧ
σʔλϕʔεͷ ͓͓͖͍͑ͯͨ͞ಛ2 • τϥϯβΫγϣϯʹΑ࣮ͬͯݱ͞ΕΔ͜ͱ • σʔλͷߋ৽ͷฒྻੑΛอͭɻ -> ෳਓͰͷߋ৽ͷέʔεʹɻ • σʔλͷ߹ੑΛอূ͢Δɻ
-> োൃੜ࣌ʹσʔλ߹ΛอͬͨϦΧόϦΛՄೳ ʹɻ • ACIDಛੑΛ࣮ݱ͢Δɻ http://ja.wikipedia.org/wiki/ACID (ίϯϐϡʔλՊֶ)
τϥϯβΫγϣϯͷྫ http://www.geocities.jp/sugachan1973/doc/funto60.html (ྫ) ී௨༬͔ۚΒఆظ༬ۚ10ສԁΛҠ͢ॲཧ ਖ਼ৗऴྃ࣌(COMMIT) ҟৗऴྃ࣌(ROLLBACK)
σʔλϕʔεͷ ͓͓͖͍͑ͯͨ͞ಛ3 • ϨϓϦέʔγϣϯ http://ja.wikipedia.org/wiki/ϨϓϦέʔγϣϯ “ଟ͘ͷσʔλϕʔεཧγεςϜ͕࠾༻͍ͯ͠Δ֓೦Ͱɺσʔλϕʔ εͷΦϦδφϧͱίϐʔͷϚελʔεϨʔϒؔΛҙຯ͢ΔɻϚελʔ ଆߋ৽Λه͠ɺͦΕ͕εϨʔϒ܈ʹ௨͞ΕΔɻεϨʔϒଆߋ ৽Λਖ਼͘͠ड͚औͬͨͱ͍͏ϝοηʔδΛૹΓɺ࣍ͷߋ৽Λड͚͚ ΒΕΔঢ়ଶͰ͋Δ͜ͱΛ௨͢Δɻ”
RDBMS Master Slave1 Slave2 Slave3 ϨϓϦέʔγϣϯ(ྫ) ྫ) Master:1ɺSlave:3 ߋ৽ใΛ
ߋ৽ใ Λ ߋ৽ใΛ ߋ৽ใΛอ࣋
RDBMSͱNoSQL ʹ͍ͭͯ
RDBMS http://ja.wikipedia.org/wiki/ؔσʔλϕʔεཧγεςϜ “ΤυΨʔɾFɾίου͕ఏএͨؔ͠ϞσϧʢϦϨʔγϣφϧϞσϧʣʹج͍ͮ ͨɺίϯϐϡʔλͷσʔλϕʔεཧγεςϜ (DBMS) Ͱ͋ΔɻRDBMS ʹΑͬ ͯߏங͢ΔσʔλϕʔεΛɺؔσʔλϕʔεͱ͍͏ɻؔϞσϧʹ͓͚Δʮؔ (ϦϨʔγϣϯ)ʯɺҰൠʹʮද
(ςʔϒϧ)ʯ ͱݺΕΔ͜ͱ͕ଟ͍ɻ 2007ݱࡏɺ͘ΒΕ͍ͯͯ·ͨ͘ΘΕ͍ͯΔσʔλϕʔεͷ΄ͱΜͲ ɺؔϞσϧʹج͍͍ͮͯΔɻ”
RDBMSϓϩμΫτ • MySQL • PostgreSQL • Oracle • SQL Server
• MariaDB …etc
RDBMS/ಘҙͳ͜ͱ • σʔλͷҰ؏ੑΛอͪͳ͕Βͷߋ৽͕ߦ͑Δ (τϥϯβΫγϣϯ) • ݕࡧ(SELECT)ʹJOINΛར༻ͨ͠ෳࡶͳ݅Λࢦ ఆͯ͠औಘͰ͖Δ • ಋೖ࣮ϊϋ͕๛ (ރΕ͍ͯΔٕज़ͷͨΊ)
RDBMS/ۤखͳ͜ͱ • େྔσʔλͷॻ͖ࠐΈΛߦ͏(DISK I/O ෦) • ߋ৽ͷൃੜ͢ΔςʔϒϧͷΠϯσοΫε࡞ςʔϒϧߏ ͷมߋ (͔͔࣌ؒΔɺ͔ͭɺςʔϒϧࣗମϩοΫͯ͠͠·͏ͨΊߋ৽ ͕ߦ͑ͳ͍ʣ
• ΧϥϜΛݻఆͣ͠Β͍༻్Ͱͷར༻ • ݁ՌΛଈ࣌Ͱૣ݁͘ՌΛฦ͢ (τϥϯβΫγϣϯ͕͋Δ)
NoSQL http://ja.wikipedia.org/wiki/NoSQL “NoSQLʢҰൠʹ”Not only SQL”ͱղऍ͞ΕΔʣͱɺϦϨʔγϣφϧσʔλϕʔ εཧγεςϜ (RDBMS) Ҏ֎ͷσʔλϕʔεཧγεςϜΛࢦ͓͓͢·͔ͳ ྨޠͰ͋ΔɻϦϨʔγϣφϧσʔλϕʔεΛΈ͘ʹ༻͖͍ͯͨ͠ྺ࢙Λ ଧഁ͠ɺͦΕҎ֎ͷσʔλϕʔεͷར༻ɾൃలΛଅਐͤ͞Α͏ͱ͢Δӡಈͷඪޠ
ͱͯ͠ͷҙຯ߹͍Λ࣋ͭɻ ؔϞσϧͰͳ͍σʔλετΞͷಛͱͯ͠ɺݻఆ͞ΕͨεΩʔϚʹറΒΕͳ ͍͜ͱɺؔϞσϧͷ݁߹ૢ࡞Λར༻͠ͳ͍͜ͱʢ߹ʹΑͬͯ୯ʹͦͷΑ͏ ͳػೳ͕ܽམ͍ͯ͠Δ͚ͩʣɺਫฏεέʔϥϏϦςΟ͕֬อ͍͢͠ࣄ͕ଟ͍͜ ͱɺτϥϯβΫγϣϯΛར༻Ͱ͖ͳ͍ͷ͕ଟ͍͜ͱͳͲ͕ڍ͛ΒΕΔɻ”
NoSQLϓϩμΫτ • memcahed (ΩʔόϦϡʔܕ) • Redis (ΩʔόϦϡʔܕ) • Riak (ΩʔόϦϡʔܕ)
• MongoDB (υΩϡϝϯτϕʔεܕ) • HBase (ΧϥϜϑΝϛϦʔܕ ) • Cassandra (ΧϥϜϑΝϛϦʔܕ) …etc
NoSQL • NoSQLͱ͍ͬͯɺଟ͘ͷ͕͋Δɻ ͞Βʹɺѻ͏σʔλϞσϧɺෳछྨ͋Δɻ (RDBMSɺѻ͏ϞσϧؔϞσϧ͚ͩͰͨ͠ΑͶʁ) • ΩʔόϦϡʔܕ • υΩϡϝϯτϕʔεܕ •
ΧϥϜϑΝϛϦʔܕ …etc http://ja.wikipedia.org/wiki/NoSQL
NoSQL/ಘҙͳ͜ͱ • σʔλΛࢄ͍ͤ͢͞ େྔσʔλͷॻ͖ࠐΈΛॲཧ͍ͤ͢͞ (ࢄͤ͞ΕΔͷͰDISK IOࢄͰ͖Δ) • εέʔϧΞτ͍ͤ͢͞
NoSQL/ۤखͳ͜ͱ ! • σʔλࢄͤͨ͞߹ɺCAPఆཧ͕ݴ͑Δ • CAPఆཧͷఆٛ ϊʔυؒͷσʔλෳʹ͓͍ͯɺಉ࣌ʹ࣍ͷ3ͭͷอূ Λఏڙ͢Δ͜ͱͰ͖ͳ͍ɻ • Ұ؏ੑ(Consistenecy)
ɺՄ༻ੑ(Availability)ɺ அੑ(Partition-tolerance) ͷ̏ͭͷ͏ͪɺಉ࣌ʹຬͨͤΔͷ̎ͭ http://ja.wikipedia.org/wiki/CAPఆཧ
RDBMSͱNoSQL • (RDBMSಘҙͳ͜ͱ) vs (NoSQLಘҙͳ͜ͱ) -> ղܾࡦͷ෯ΛڱΊΔ (͋·Γҙຯ͕ͳ͍) • (RDBMSಘҙͳ͜ͱ)
+ (NoSQLಘҙͳ͜ͱ) -> ཁ݅Λຬͨ͢ղܾࡦΛ૿͢ɻ ಘҙͳྖҬಉ࢜ΛΈ߹ΘͤΔɻ
RDBMSͱNoSQL • Ϣʔεέʔε (NoSQL͕Χόʔ͢Δ෦) • ϩάΠϯͷηογϣϯใΛΩϟογϡ • λΠϜϥΠϯܗࣜͷwebΞϓϦ(TwitterϥΠΫ) • PvP,
GvG ͳͲϦΞϧλΠϜͰͷϚονϯάॲཧ • ϥϯΩϯάॲཧΛϦΞϧλΠϜදࣔ (ϦΞϧλΠϜʹλΠϜϥΠϯΛදࣔͤ͞Δ߹ͳͲ) • ϖʔδຖʹΞΫηεΛදࣔ͢Δ
ςʔϒϧઃܭ ʹ͍ͭͯ
ςʔϒϧઃܭ • σʔλϞσϦϯάͷྲྀΕ • σʔλͷྨ • ςʔϒϧઃܭTips
σʔλϞσϦϯά ͷྲྀΕ • ྫ: ΞΠςϜ/ΧςΰϦ ͷΈ ERਤ(Entity-relationship Diagram)ͰϞσϦϯά http://ja.wikipedia.org/wiki/࣮ମؔ࿈Ϟσϧ ΞΠςϜ
ΧςΰϦ ᶃ֓೦Ϟσϧ => ᶄཧϞσϧ => ᶅཧϞσϧ
σʔλϞσϦϯά ͷྲྀΕ • ྲྀΕΛ͓͞Β͍ 1. ֓೦ϞσϧΛ࡞Δɻ ཁ͔݅Βɺඞཁͳσʔλ߲Λચ͍ग़͢ 2. ཧϞσϧΛ࡞Δɻ σʔλ߲ͷҙຯ/ؔ࿈ΛؑΈͯɺσʔλΛਖ਼نԽ͍ͯ͘͠
ERਤΛ͍ͭͬͯ͘͘ 3. ཧϞσϧΛ࡞Δɻ ERਤΛ͍ͭͬͯ͘͘(࣮ࡍʹRDMBSʹςʔϒϧఆٛͰ͖ΔΑ͏ʹ) ※IPA/σʔλϕʔεεϖγϟϦετࢼݧͷ ςʔϒϧઃܭ͕͔ͳΓ܇࿅ʹͳΔɻ
ϞσϦϯά͢Δͱ͖ͷ σʔλͷྨ • Ϛελܥσʔλ ̍ొ͞ΕͨΒසൟʹมߋ͞Εͳ͍σʔλ ྫ) ΞΠςϜใɺϞϯελʔใɺεΩϧใ ςʔϒϧ໋໊ྫɿM_XXXX γϦʔζ •
τϥϯβΫγϣϯܥσʔλ සൟʹมߋɾՃ͞ΕΔσʔλ ྫ) ΞΠςϜऔಘঢ়گɺΫΤετਐߦঢ়گɺεΩϧशಘใ ςʔϒϧ໋໊ྫɿT_XXXX γϦʔζ
ςʔϒϧઃܭTips • ERਤ༻ͷπʔϧΛར༻͢Δ͜ͱΛΦεεϝ (ݱͰɺERMasterΛͬͯΔ) • ERਤ͔ΒDDLࣗಈੜՄೳʹ http://ermaster.sourceforge.net/index_ja.html (DDL) CREATE
TABLE จ
ςʔϒϧઃܭTips • ERਤϕʔεͰςʔϒϧઃܭϨϏϡʔඞਢ • ςʔϒϧ໊ɺΧϥϜ໊ɺ໋໊ͷنଇ͕͓͔͘͠ͳ͍͔ɻҰͰΘ͔Γ͍͔͢ɻ • ΧϥϜͷܕͷਫ਼ߟྀ͞Ε͍ͯΔ͔ɻ(INT/BIGINT/SERIALʣ • τϥϯβΫγϣϯܥͷσʔλɺσʔλྔɺσʔλ݅ఆ͞Ε͍ͯΔ͔ɻ ଟ͍ͷɺׂ͢Δɻ
• ςʔϒϧͷCRUD(σʔλͷ࡞(Create),ಡΈग़͠(Read),ߋ৽(Update),আ(Delete))ɺ ༷ʹͱ͍ͮͯઆ໌Ͱ͖Δ͔ɻ • ֤ςʔϒϧͷओΩʔ͕ద͔ɻ (࣮ࡍͲΜͳσʔλ͕ೖͬͯDMLΛ࣮ߦ͍ͯ͠Δ͔ΠϝʔδͰ͖͍ͯΔ͔) • ͋Δఔ൚༻తͳߏʹͳ͍ͬͯΔ͔ɻ (ଞͷςʔϒϧͰࣅͨΑ͏ͳςʔϒϧ͕ͳ͍͔)
࣮ࡍʹݱͷઃܭ/։ൃ ͰΑ͘ΔTips
Tips1 ERਤͷϨϏϡʔɺιʔεͷϨϏϡʔɺSQL(ΫΤϦ)ͷϨϏϡʔ • ϨϏϡʔ࣌ͷpoint • explainΛ࣮ߦͯ͠SQLͷ࣮ߦܭըΛ֬ೝ(࣮ߦίετ͕ҟৗʹߴ͍ɺͳͲҙ) • ιʔεͰSQLΛඞཁճҎ্ʹൃߦͯ͠ͳ͍͔ɻ(ORMͱ͔Α͋͘Δ) ϝϦοτɿ ෛՙରࡦͷࣄલ༧ʹͳΔɻखΓࢭɻ
σϝϦοτɿ DBઃܭ/ΫΤϦνϡʔχϯάʹ͍ͭͯϦʔυͰ͖ΔΤϯδχΞͷΞαΠϯ͕ඞਢ
Tips2 ϨϓϦέʔγϣϯ(ྫ:Master:1/Slave:2)Λར༻ׂ͠Λ͚DBෛՙΛࢄ • ࢀরܥ(SELECT)ɺSlave • ߋ৽ܥ(INSERT,UPDATE,DELETE)ɺMaster ϝϦοτɿ DBෛՙ(Disk IOɺMemoryɺCPU༻)ΛࢄͰ͖Δ σϝϦοτɿ
ϨϓϦέʔγϣϯԆ(Master->Slave)Λߟྀͨ͠ઃܭ/࣮ʹ͢Δඞཁ͕͋Δ ࣌ʹSELECTΛMasterʹڧ੍తʹ͚Δඞཁ͕͋Δɻ
Master Slave1 Slave2 ྫ) Master:1ɺSlave:2 ͷϨϓϦέʔγϣϯ ᶄߋ৽ใΛ ᶄߋ৽ใΛ
ΞϓϦέʔγϣϯ ᶃߋ৽ॲཧ ࣮ߦ UPDATE,INSERT,DELETE ᶅࢀরॲཧ ࣮ߦ SELECT ࣮ߦλΠϛϯά ͕ ᶄ => ᶅͰͳ͘ɺ ࣮ߦλΠϛϯά ͕ ᶅ => ᶄ ͱͳΔ߹͕͋Γɺ ࢀরͨ͠ઌ(Slave1,2)ʹߋ৽ͨ͠ใ͕ө͞Εͳ͍
Tips3 σʔλྔΛࢄͤ͞Δ(ςʔϒϧͷਫฏׂɺਨׂ͢Δ ) • ਫฏׂ => ςʔϒϧͷϨίʔυ୯ҐͰɺผͷςʔϒϧͰѻ͏ɻ - ྫ)
user_id () Λ 100Ͱআࢉͯ͠ɺςʔϒϧࣗମΛ100ׂ͢Δ • ਨׂ => ςʔϒϧͷҰ෦ͷྻ͚ͩΛਨʹɺߋ৽ॲཧ͕͓͓͍߲ͱͲ͏͢Δͷ͔ʁ ྫ) Ϣʔβใͷߋ৽ස͕͍߲(χοΫωʔϜɺใ)ͱɺߋ৽ස͕ ߴ͍(ϨϕϧɺମྗͳͲ)Λɺผςʔϒϧʹׂɻ ϝϦοτɿDBੑೳɺཧ͢͠͞ɺՄ༻ੑΞοϓ͢Δ σϝϦοτɿςʔϒϧΛ؆୯ʹJOINͰ͖ͳ͘ͳΔɺઃܭͰߟྀ͖͢ࣄ͕૿͑Δ
Tips4 ୲ΛΫϥΠΞϯτ/αʔόͰ໌֬ʹΘ͚ͣɺ 1ػೳ୯ҐͰΘ͚(ΫϥΠΞϯτ/αʔό)྆ํΔɻ ϝϦοτɿ ։ൃεϐʔυτʔλϧͰݟΔͱૣ͍ɻ αʔό/ΫϥΠΞϯτ ؒɺ௨ͨ͠ઃܭ͕୲ऀͰ݁͢Δ σϝϦοτɿ ։ൃن͕େ͖͘ͳΔͱνʔϜϦιʔεʹґଘɻ
·ͱΊ
·ͱΊ • վΊͯσʔλϕʔεΛ͏؍Λ;Γ͔͑ͬͯΈͨɻ • RDBMS + NoSQL Ͱͷҧ͍Λҙࣝͯ͠Έͨɻ • ΫϥΠΞϯτଆɺAPIΛհͯ͠αʔόʹӬଓԽ͞Ε͍ͯΔσʔ
λߏΛͲ͏ૢ࡞͍ͯ͠Δͷ͔Πϝʔδͯ͠ΈΔɻ • αʔόαΠυଆɺAPIΛհͯ͠ɺDB͔Β͜ͷσʔλߏΫϥ ΠΞϯτͰͲ͏ૢ࡞͞Ε͍ͯΔͷ͔ΛΠϝʔδͯ͠ΈΔɻ • ཪଆͰߦΘΕ͍ͯΔ͜ͱ͕ΠϝʔδͰ͖ΔͱɺΫϥ/αόΛݟ௨ ͤͨઃܭ/։ൃ͕ߦ͑Δɻ
ࢀߟॻ੶ɾURL
ࢀߟॻ੶ • σʔλϕʔεΤϯδχΞཆಡຊ http://www.amazon.co.jp/dp/4774158062 • WebΤϯδχΞͷͨΊͷσʔλϕʔεٕज़[࣮ફ]ೖ http://www.amazon.co.jp/dp/4774150207 • σʔλϕʔεపఈ߈ུ (WEB+DB
PRESS plus) [େܕຊ] http://www.amazon.co.jp/dp/4774163651 • NoSQLσʔλϕʔεϑΝʔετΨΠυ [େܕຊ] http://www.amazon.co.jp/dp/4798029599 • SQL ॻ͖ํυϦϧ http://www.amazon.co.jp/dp/4774130850 • SQL Ξϯνύλʔϯ http://www.oreilly.co.jp/books/9784873115894/
ࢀߟURL • σʔλϕʔε֓ཁ wikipedia : σʔλϕʔε http://ja.wikipedia.org/wiki/σʔλϕʔε http://en.wikipedia.org/wiki/Database • ΠϯσοΫε
B-TreeΠϯσοΫεͷλϓϧऔಘݺͼग़͠ http://www.postgresqlinternals.org/index.php/Τά θΩϡʔλ ΠϯσοΫεͷجૅࣝ http://www.hi-ho.ne.jp/tsumiki/doc_1.html ୈ7ճɹੑೳվળͷ伴ɼΠϯσοΫεͷಛੑΛΔ ʙB-treeͱϋογϡ http://gihyo.jp/dev/serial/01/sql_academy2/000701 ߹ͤ࠷దԽΠϯαΠυ http://www.slideshare.net/ItagakiTakahiro/ss- 4656848 • DBύϑΥʔϚϯενϡʔχϯάͷجૅɿΠϯσο Ϋεೖ http://www.slideshare.net/simosako/rdb • DBΞʔΩςΫνϟ PostgreSQLΞʔΩςΫνϟೖʢPostgreSQL Conference 2012ʣ http://www.slideshare.net/uptimejp/postgre- sqlpgcon12j • NoSQL+RDBMS NOSQL Databases http://nosql-database.org/ ϙϦάϩοτύʔγεςϯε http://martinfowler.com/bliki/ PolyglotPersistence.html Nosqlͷجૅࣝʢ20137݄ߨٛࢿྉʣ http://www.slideshare.net/geminimobile/nosql20137
͝ਗ਼ௌ͋Γ͕ͱ͏ ͍͟͝·ͨ͠ʂʂ
Q & A