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
0
7
アーキテクチャから学ぶ分散SQL TiDB の強み・弱み
Yukio
August 17, 2025
Tweet
Share
Other Decks in Programming
See All in Programming
AIの誤りが許されない業務システムにおいて“信頼されるAI” を目指す / building-trusted-ai-systems
yuya4
7
4.3k
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
5.1k
SQL Server 2025 LT
odashinsuke
0
140
ZJIT: The Ruby 4 JIT Compiler / Ruby Release 30th Anniversary Party
k0kubun
1
320
[AtCoder Conference 2025] LLMを使った業務AHCの上⼿な解き⽅
terryu16
6
1k
Basic Architectures
denyspoltorak
0
190
從冷知識到漏洞,你不懂的 Web,駭客懂 - Huli @ WebConf Taiwan 2025
aszx87410
2
3.3k
Grafana:建立系統全知視角的捷徑
blueswen
0
280
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
4
730
ELYZA_Findy AI Engineering Summit登壇資料_AIコーディング時代に「ちゃんと」やること_toB LLMプロダクト開発舞台裏_20251216
elyza
2
1k
疑似コードによるプロンプト記述、どのくらい正確に実行される?
kokuyouwind
0
160
Unicodeどうしてる? PHPから見たUnicode対応と他言語での対応についてのお伺い
youkidearitai
PRO
0
460
Featured
See All Featured
Believing is Seeing
oripsolob
1
29
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
1.8k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
0
3.4k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.6k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
1.8k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
We Are The Robots
honzajavorek
0
130
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
790
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Why Our Code Smells
bkeepers
PRO
340
58k
Six Lessons from altMBA
skipperchong
29
4.1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
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