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
アーキテクチャから学ぶ分散SQL TiDB の強み・弱み
Search
Yukio
August 17, 2025
Programming
38
0
Share
アーキテクチャから学ぶ分散SQL TiDB の強み・弱み
Yukio
August 17, 2025
Other Decks in Programming
See All in Programming
検索設計から 推論設計への重心移動と Recall-First Retrieval
po3rin
5
1.7k
Surviving Black Friday: 329 billion requests with Falcon!
ioquatix
0
3.2k
SkillsをS3 Filesに置く時のあれこれ
watany
3
1.6k
「なんか〇〇ライブラリで脆弱性あるみたいなんだけど。。。」から始める脆弱性対応 / First Steps in Vulnerability Response
mackey0225
2
130
なぜあなたのコードには「コシ」がないのか?〜AI時代に問う、最後まで美味しい設計と戦略〜 #phpconkagawa / phpconkagawa2026
shogogg
0
210
GoogleCloudとterraform完全に理解した
terisuke
1
200
Spec-Driven Development with AI Agents (Workshop, May 2026)
antonarhipov
3
360
開発とはなにか、Essenceカーネルで見えるもの
ukin0k0
0
170
エラー処理の温故知新 / history of error handling technic
ryotanakaya
7
1.9k
t *testing.T は どこからやってくるの?
otakakot
1
940
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
470
密結合なバックエンドから TypeScript のコードを生成する
kemuridama
0
140
Featured
See All Featured
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.5k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
740
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
210
Building the Perfect Custom Keyboard
takai
2
760
Heart Work Chapter 1 - Part 1
lfama
PRO
7
35k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
370
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
800
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
180
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
190
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.3k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
200
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
380
Transcript
アーキテクチャから学ぶ 分散SQL「TiDB」 の強み・弱み Yukio
目次 ・分散SQL「TiDB」とは? ・RDB/TiDBのアーキテクチャ ・RDB/TiDBのデータの持ち方 ・クエリ実行時の挙動 ・TiDBの強み/弱み ・まとめ ・参考資料
分散SQL「TiDB」とは? ACIDトランザクションをサポートしつつ、更新系を水平スケール可能な次世代の分散 データベース ・👍MySQL互換 ・👍RDBレベルのデータ整合性 (ACID) ・👍参照/更新系の両方を水平スケール可能 ・👍無停止でDBバージョンアップ可能 ・👎レイテンシはやや高まる
RDB Architecture 参考「詳説データベース」 , p9, DBMSアーキテクチャ クエリ プロセッサ 実行 エンジン
ストレージ エンジン RDB Client ディスク
TiDB Architecture https://docs.pingcap.com/ja/tidb/stable/tidb-architecture/
RDBのデータの持ち方 (通常時) id 1 … 1000 1001 … 2000 2001
… 3000 users Table Master
RDBのデータの持ち方 (データ複製時) id 1 … 1000 1001 … 2000 2001
… 3000 users Table Master Replica 1 Replica 2 複製 複製
RDBのデータの持ち方 (データ分割時) id 1 … 1000 1001 … 2000 2001
… 3000 users Table DB 1 DB 2 DB 3
id 1 … 1000 1001 … 2000 2001 … 3000
★Leader users Table TiKV Node A Follower ★Leader TiKV Node B Follower Follower Follower TiKV Node C ★Leader Follower TiKV Node D Follower TiDBのデータの持ち方 (データ分割 & 複製が基本系)
クエリ実行時の挙動 (INSERT文) id 1 … 1000 1001 … 2000 ★Leader
★Leader users Table TiKV Node A TiKV Node B ① INSERT users (id) VALUES (5); ②log replication ③commit ③commit
クエリ実行時の挙動 (INSERT文) id 1 … 1000 1001 … 2000 ★Leader
★Leader users Table TiKV Node A TiKV Node B ① INSERT users (id) VALUES (1005); ②log replication ③commit ③commit
クエリ実行時の挙動 (SELECT文) id 1 … 1000 1001 … 2000 ★Leader
★Leader users Table TiKV Node A TiKV Node B ① SELECT * FROM users WHERE id = 5;
クエリ実行時の挙動 (SELECT文) id 1 … 1000 1001 … 2000 ★Leader
★Leader users Table TiKV Node A TiKV Node B ① SELECT * FROM users WHERE id = 1005;
クエリ実行時の挙動 (SELECT文) id 1 … 1000 1001 … 2000 ★Leader
★Leader users Table TiKV Node A TiKV Node B ① SELECT * FROM users
TiDBの強み (1) 分散システムならではの強み ・水平スケーラビリティ ・ローリングアップデートによるゼロダウンタイムでのDBバージョンアップ
TiDBの強み (2) レコードのバージョン管理を元にした機能 ・タイムトラベルクエリ SELECT ... FROM ... AS OF
$(timestamp) ・DROPしたオブジェクト(Table / Database)のFLASHBACK FLASHBACK DATABASE $(db_name)
TiDBの強み (3) 柔軟なリソース制御機能
TiDBの強み (4) インデックス断片化の解消が不要 イミュータブルなデータ構造(LSM Tree)をインデックスとして利用することでディスク断片 化の発生を抑えている https://tikv.org/docs/4.0/tasks/configure/titan/
TiDBの弱み (1) ミリ秒レベルでのレイテンシ増 id 1 … 1000 1001 … 2000
★Leader ★Leader users Table TiKV Node A TiKV Node B SELECT * FROM users
TiDBの弱み (2) 外部キー制約利用時の性能問題 https://tech-blog.tokyo-gas.co.jp/entry/2025/02/26/123110 参照制約を指定している子テーブルにレコードを挿入すると、親テーブルの排他ロッ クを取り合うことになり、ロック待ち状態が発生 子テーブル 親テーブル
TiDBの弱み (3) オートインクリメント時のホットスポット問題 id 1 … 1000 1001 … 2000
★Leader ★Leader users Table TiKV Node A TiKV Node B INSERT users (id) VALUES (5); INSERT users (id) VALUES (6);
まとめ ・TiDBでは、RDBの各モジュールを複数のマシンに分散させることでスループットを向上させている ・分散体制を取ることでローリングアップデートを可能にし、メンテナンス時の他処理への影響を抑えてい る ・分散システム特有の課題は TiDBにおいても存在する (レイテンシ増加、ホットスポット問題 ) ・マルチプロダクト、マルチテナントプロダクトである弊社製品に一定有用な DB
参考書籍 ・TiDB実践入門 (easy) ・データ指向アプリケーションデザイン (hard) ・詳説データベース (hard)
Q 「テナントごとにDBインスタンスを作成するインスタンス分離した DBを1つのTiDBクラスタで管理する場合 データの持ち方はどうなるのか? 」 A. MySQLではDatabaseはSQL ServerでいうところのSchemaに相当します。 TiDBクラスタで複数DBを運用する際は、テナントごとに Schema(Database)を作成し、そこにテーブルデータを
作成していくことを想定しています。 したがって、論理的には Databaseごとにデータは別れますが、 物理的なデータ配置としては同じ TiKVノードに 別々のテナントのデータが同居する可能性 があります。 ★ t1.users TiKV Node A t1.users ★t2.users TiKV Node B t3.users t1.users t2.users TiKV Node C ★t3.users t2.users TiKV Node D t3.users