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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Yukio
August 17, 2025
Programming
0
8
アーキテクチャから学ぶ分散SQL TiDB の強み・弱み
Yukio
August 17, 2025
Tweet
Share
Other Decks in Programming
See All in Programming
Metaprogramming isn't real, it can't hurt you
okuramasafumi
0
130
個人開発は儲からない - それでも開発開始1ヶ月で300万円売り上げた方法
taishiyade
0
110
iOSアプリでフロントエンドと仲良くする
ryunakayama
0
120
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
310
AIと一緒にレガシーに向き合ってみた
nyafunta9858
0
430
Python’s True Superpower
hynek
0
190
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
22
8k
浮動小数の比較について
kishikawakatsumi
0
340
NOT A HOTEL - 建築や人と融合し、自由を創り出すソフトウェア
not_a_hokuts
2
460
今更考える「単一責任原則」 / Thinking about the Single Responsibility Principle
tooppoo
2
930
Agent Skills Workshop - AIへの頼み方を仕組み化する
gotalab555
12
6.7k
nilとは何か 〜interfaceの構造とnil!=nilから理解する〜 / Understanding nil in Go Interface Representation and Why nil != nil
kuro_kurorrr
2
1.1k
Featured
See All Featured
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
200
Rails Girls Zürich Keynote
gr2m
96
14k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Between Models and Reality
mayunak
1
210
Claude Code のすすめ
schroneko
67
210k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Ruling the World: When Life Gets Gamed
codingconduct
0
160
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.1k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
190
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
130
Skip the Path - Find Your Career Trail
mkilby
0
67
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
420
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) 柔軟なリソース制御機能 https://infcurion-jira.atlassian.net/wiki/spaces/ABNI/pages/789415153/Wallet+Station
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