Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
iOSDC Japan 2026 - Swiftで作って学ぼう!データベース自作入門
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
kaseken (Kent Kaseda)
September 11, 2026
Programming
790
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
iOSDC Japan 2026 - Swiftで作って学ぼう!データベース自作入門
kaseken (Kent Kaseda)
September 11, 2026
Transcript
68 slides
Swift で作って学ぼう!データベース自作入門 iOSDC Japan 2026 @kentkaseda kaseken kaseken 1
スライド1)・原稿2)は公開済み 1) https://speakerdeck.com/kaseken/iosdc2026 2) https://github.com/kaseken/db.swift/blob/main/docs/iosdc2026.md 2
データベースを “使った” ことがある人 3
データベースを “作った” ことがある人 4
本日の目標 この場にいる全員に データベースの自作をトライさせること 5
なぜデータベースの自作をオススメするのか? 6
なぜデータベースの自作をオススメするのか? ① 技術領域によらない 7
なぜデータベースの自作をオススメするのか? ② 時代によらない 8
以下のプロンプトを実行! > https://cstack.github.io/db_tutorial の内容をSwiftで実装してください ただし、クエリの形式はSQLに準拠してください Thanks to @cstack for
this great tutorial! 9
AIを使うのはずるくない?🤔 10
これなら全員できますよね?🤗 11
私の場合... チャプターごとにAIで実装 生成されたコードをレビュー 次のチャプターへ 腑に落ちるまで AIに質問 & リファクタリング Ref) https://github.com/kaseken/db.swift
12
13
14
15
16
17
こちらのやり方を紹介しました データベースを自作する! データベースの仕組みを理解する! 18
データベースを自作する! データベースの仕組みを理解する! これから説明 19
アーキテクチャ SQL SQLパーサー 命令 B+Tree データの取得・更新 ページャー データの取得・永続化 ファイル 20
アーキテクチャ SQL SQLパーサー 命令 B+Tree データの取得・更新 ページャー データの取得・永続化 👉 ファイル
21
ファイル ページ 0 ページ 1 ページ 2 ページ 3 4096バイト
22
ファイル ページ 0 ページ 1 ページ 2 ページ 3 レコード
0 レコード 1 レコード 2 レコード 3 23
ファイル ページ 0 ページ 1 ページ 2 ページ 3 レコード
0 レコード 1 レコード 2 レコード 3 カラム1 (id) カラム2 (name) カラム3 (email) 24
SwiftDataでもファイルに保存される 25
👇 データベースのファイル 26
行指向DB (e.g. MySQL) カラム ① カラム ② カラム ① カラム
② 列指向DB (e.g. BigQuery) カラム ① カラム ① カラム ① カラム ① ︙ カラム ① カラム ② カラム ① カラム ② ︙ カラム ② カラム ② カラム ② カラム ② ︙ 27
アーキテクチャ SQL SQLパーサー 命令 B+Tree データの取得・更新 👉 ページャー データの取得・永続化 ✅
ファイル 28
B+Tree ページ ページャー メモリ ディスク ページ ファイル 29
B+Tree ページ ページャー メモリ ページ ディスク ファイル 30
キャッシュ ページ 0 ページ 1 nil nil 31
B+Tree ページ2ください ページャー キャッシュ ページ 0 ページ 1 nil nil
ページ2ください ファイル ページ 0 ページ 1 ページ 2 ページ 3 32
B+Tree ページ 2 ページャー キャッシュ ページ 0 ページ 1 ページ
2 nil ページ 2 ファイル ページ 0 ページ 1 ページ 2 ページ 3 33
B+Tree ページ 2 ページャー キャッシュ ページ 0 ページ 1 ページ
2 nil ページ 0 ページ 1 ページ 2 ページ 3 ファイル 34
B+Tree ページャー キャッシュ ページ 0 ページ 1 ページ 2 nil
flush ファイル ページ 0 ページ 1 ページ 2 ページ 3 35
アーキテクチャ SQL SQLパーサー 命令 👉 B+Tree データの取得・更新 ✅ ページャー データの取得・永続化
✅ ファイル 36
B+Treeは、内部ノード・リーフノードの 2種類のノードを持つ 内部ノード 内部ノード リーフノード リーフノード 内部ノード リーフノード リーフノード リーフノード
37
各ノードは、一ページ分のデータを持つ リーフノード 内部ノード ? ? 38
B+Tree ページ ページャー メモリ ディスク ページ ファイル 39
B+Treeのノード ページ ページ ページャー メモリ ディスク ページ ファイル 40
各ノードは、一ページ分のデータを持つ リーフノード 内部ノード ? ? 41
リーフノードは、レコード一覧を保持 ページ キー レコード キー レコード キー レコード 42
キーによってソートされている ページ 2 レコード 5 レコード 8 レコード 43
内部ノードは、子ノードへのポインタとキーの最大値を保持 ページ #1 子ノード #1 #1の最大キー #2 子ノード #2 #2の最大キー
#3 子ノード #3 44
子ノードに含まれるキーの最大値が、親の内部ノードに保持される #1 10 #1の最大キー レコード 13 #2 レコード 17 #3
17 レコード 45
子ノードに含まれるキーの最大値が、親の内部ノードに保持される #1 #1の最大キー #2 35 #3 #3に含まれる キーの最大値 #1 8
#2 17 #3 46
キーの最大値はソートされている #1 子ノード #1 8 #2 子ノード #2 17 #3
子ノード #3 47
19 21 22 #1 17 #2 35 #3 #1 22
#2 29 #3 24 26 29 30 31 35 48
子ノードに含まれるキーの最大値が、親の内部ノードに保持される 19 21 22 #1 17 #2 35 #3 #1
22 #2 29 #3 24 26 29 30 31 35 49
#1 8 #2 17 #3 子ノード #1 子ノード #2 子ノード
#3 8以下 9以上・17以下 18以上 50
キーが12のレコードを検索する場合 ... #1 子ノード #1 8 #2 子ノード #2 17
#3 子ノード #3 9以上・17以下 51
内部ノードは、 1ページ内で大量の子ノードを管理 ページ #1 12 #2 31 #3 47 #4
67 #5 78 #6 91 #7 103 #8 123 #9 140 #10 159 #11 171 #12 192 #13 213 #14 244 #15 265 #16 287 #17 302 #18 330 52
アーキテクチャ 👉 SQL SQLパーサー 命令 ✅ B+Tree データの取得・更新 ✅ ページャー
データの取得・永続化 ✅ ファイル 53
SELECT * FROM users WHERE id = 24 SQLパーサー id
= 24のレコードを検索 B+Tree 54
id = 24のレコードを検索 B+Tree #1 17 #2 35 #3 ルートノードのページを取得
ページャー (未キャッシュの場合) ページを取得 ファイル 55
id = 24のレコードを検索 B+Tree #1 17 #2 35 #3 #2に含まれる
(18以上・35以下) 56
id = 24のレコードを検索 B+Tree #1 17 #2 35 #3 #1
22 #2 29 #3 ノードのページを取得 ページャー (未キャッシュの場合) ページを取得 ファイル 57
id = 24のレコードを検索 B+Tree #1 17 #2 35 #3 #1
22 #2 29 #3 #2に含まれる (23以上・29以下) 58
id = 24のレコードを検索 B+Tree 24 #1 17 #2 35 #3
#1 22 #2 29 #3 レコード 26 レコード 29 レコード ノードのページを取得 ページャー 59
id = 24のレコードを検索 B+Tree 検索結果 24 #1 17 #2 35
#3 #1 22 #2 29 #3 レコード 26 レコード 29 レコード 60
INSERT INTO users (id,username,email) VALUES (27,'foo','
[email protected]
') SQLパーサー id = 27のレコードを追加
B+Tree 61
id = 27のレコードを追加 B+Tree 24 #1 17 #2 35 #3
#1 22 #2 29 #3 レコード 26 レコード 29 レコード ここに追加すべき 62
id = 27のレコードを追加 B+Tree 24 レコード #1 17 #2 35
#3 #1 22 #2 29 #3 26 レコード 27 レコード 29 レコード 追加された 63
アーキテクチャ ✅ SQL SQLパーサー 命令 ✅ B+Tree データの取得・更新 ✅ ページャー
データの取得・永続化 ✅ ファイル 64
データベースを自作する! データベースの仕組みを理解する! 65
データベースを自作する! データベースの仕組みを理解する! もっと学びたい方にはCMUの講義1)がおすすめ 1) カーネギーメロン大学の有名講義『 Intro to Database Systems』を全てのプログラマに見てほしい 66
皆さんへの宿題です! データベースを自作する! データベースの仕組みを理解する! 67
ぜひDBの自作に挑戦してみてください! > https://cstack.github.io/db_tutorial の内容をSwiftで実装してください ただし、クエリの形式はSQLに準拠してください Thanks to @cstack for this
great tutorial! 68
More Decks by kaseken (Kent Kaseda)
See All by kaseken (Kent Kaseda)
Kotlin Fest 2025 - 内部実装から理解する Coroutines ― Continuation・Structured Concurrency・Dispatcher
kaseken
3
2.2k
Other Decks in Programming
See All in Programming
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
150
[DroidKnights 2026] Workflow AX 적용기 — 자동 정책 정리부터 E2E까지
dayeon
0
130
vue-tsc x TypeScript7
koukimiura
0
100
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
3
350
[Kotlin Fest 2026] eBPF Tracing for Kotlin
takehaya
1
410
例外からRich Errorsまで Kotlinエラーハンドリングの進化を読み解く
shiita0903
0
250
Canvas 2D Context Next
petamoriken
0
620
Kotlin Fest 2026: Kotlin コンパイラに Contribute してみよう! - Kotlin/Wasm で深い再帰を書けるようにした話
ternbusty
1
420
Claude Code ハーネスDeep Dive – 君はどこまで制御する? -
takateeen_knj
6
6.4k
ruby/uri meets WHATWG
jinroq
0
170
LLM 101: Exploring LLMs, Starting with Tokens.
dalinaum
0
120
エラーチャンネルのボールを拾い続けて鍛えるエンジニアの地力 / phpcon-niigata2026
meihei3
1
520
Featured
See All Featured
Designing for Timeless Needs
cassininazir
1
570
Rebuilding a faster, lazier Slack
samanthasiow
85
9.8k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.9k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3.1k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
500
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
4
4.4k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.7k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
490
Music & Morning Musume
bryan
48
7.5k
A designer walks into a library…
pauljervisheath
211
25k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
790
Between Models and Reality
mayunak
4
610