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
RDB(ぽすぐれ)チューニング入門/rdb-tuning-introduction-for-p...
Search
aono
October 09, 2024
Programming
170
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RDB(ぽすぐれ)チューニング入門/rdb-tuning-introduction-for-postgresql
aono
October 09, 2024
More Decks by aono
See All by aono
Dockerfileチョットカケルになろう/dockerfile-next-steps
awonosuke
0
76
Other Decks in Programming
See All in Programming
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
260
『コードを書く以外の』エンジニアリング〜課金基盤移行プロジェクト推進のためのTips4選
yuriko1211
0
590
継続モナドとリアクティブプログラミング
yukikurage
3
700
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
400
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
3
770
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
140
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
670
源内ハンズオン概要編
hideg
0
130
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
1.7k
PHP初心者セッション2026 〜生成AIでは見えない裏側を知る:今だからLAMPを通して仕組みを学ぶ〜
kashioka
0
870
Apache Hive: そしてCloud Native Lakehouseへ
okumin
1
210
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
210
Featured
See All Featured
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
790
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.4k
Color Theory Basics | Prateek | Gurzu
gurzu
0
410
The SEO Collaboration Effect
kristinabergwall1
1
520
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
290
Docker and Python
trallard
47
4.1k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
410
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.3k
The browser strikes back
jonoalderson
0
1.5k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
490
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
200
Are puppies a ranking factor?
jonoalderson
1
3.8k
Transcript
RDB(ぽすぐれ)チューニング入門
目次 1. RDBチューニング_戦略編 2. RDBチューニング_戦術編 3. まとめ 4. 補足
RDBチューニング_戦略編 • 早めに削る • 効率的に削る • チートで削る
RDBチューニング_戦略編 • ep. 0: 遅いクエリはEXPLAINで実行計画を見る ◦ 遅い原因を特定してから適切な対応をする ◦ そもそも遅いクエリを検知できないといけない→スロークエリの監視をする •
早めに削る • 効率的に削る • チートで削る
RDBチューニング_戦術編 • 早めに削る ◦ テーブルを小さくする ▪ テーブル分割 • パーティション(RANGE・LIST・HASH) •
シャーディング ◦ SQLの評価順を意識して削る(細かいとこは割愛) ▪ FROM→サブクエリとかとか ▪ ON, JOIN ▪ WHERE ▪ GROUP BY ▪ HAVING ▪ SELECT ▪ DISTINCT ▪ ORDER BY ▪ LIMIT
RDBチューニング_戦術編 • 早めに削る • 効率的に削る ◦ joinしない→サマリテーブル(=非正規化) ◦ 不要データを削ぐ ▪
ON句、WHERE句 ▪ SELECT句でカラム選択 ◦ パーティショニング ◦ ページネーション • チートで削る
RDBチューニング_戦術編 • 早めに削る • 効率的に削る • チートで削る ◦ クエリ呼び出しを減らす ▪
アプリケーション側での制御 ◦ indexを張る ▪ 複合indexのカラム順番大事→ユースケースを意識(参考) • CREATE INDEX hoge_index ON fuga USING btree (c3, c1, c2 DESC) ▪ カバリングインデックス ◦ RDBMSのパラメータチューニング(参考:DBサーバのスペックで推奨値を算出) ▪ shared_buffers、work_mem、effective_cache_sizeとかがパフォーマンス直結 ◦ お金で解決(💸👋) ▪ DBサーバのスペック上げる ▪ リードレプリカを増やす ◦ RDBを利用しない ▪ NoSQL ▪ NewSQL(SQLがインターフェース)
まとめ • 戦略を立てるの大事 ◦ 初手index張って改善しようとしてあまりうまく行かなかった ▪ 敵を知って戦う準備を整える • 調査と泥臭い検証 ◦
実行計画見よう ◦ 何か試す→実行計画見よう ▪ データ量によっても実行計画が変わる→統計情報を定期的にアップデート
補足 • 機械学習を利用したパラメータチューニングとかもあるらしい ◦ https://pgecons-sec-tech.github.io/tech-report/html_wg3_ml_tuning/wg3_ml_tun ing.html
参考 • PostgreSQL 日本語ドキュメント • [富士通] PostgreSQL技術インデックス • 複合indexの正しい順序 •
Where狙いのキー、order by狙いのキー • PostgreSQLの実行計画を読み解くための参考資料集