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
160
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
70
Other Decks in Programming
See All in Programming
ローカルLLMでどこまでコードが書けるか -縮小版 / How much code can be written on a local LLM Shortened
kishida
2
200
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
4
1.7k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
340
信頼性について考えてみる(SRE NEXT 2026 miniLT)
hayama17
0
200
共通化で考えるべきは、実装より公開する型だった
codeegg
0
270
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
270
act2-costs.pdf
sumedhbala
0
120
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
530
どこまでゆるくて許されるのか
tk3fftk
0
520
Built Our Own Background Agent at LayerX #aidevex_findy
layerx
PRO
7
2.8k
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
830
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
2
600
Featured
See All Featured
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
We Have a Design System, Now What?
morganepeng
55
8.2k
How to Ace a Technical Interview
jacobian
281
24k
YesSQL, Process and Tooling at Scale
rocio
174
15k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
180
Practical Orchestrator
shlominoach
191
11k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
From π to Pie charts
rasagy
0
240
Heart Work Chapter 1 - Part 1
lfama
PRO
8
36k
AI: The stuff that nobody shows you
jnunemaker
PRO
9
840
Automating Front-end Workflow
addyosmani
1370
210k
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の実行計画を読み解くための参考資料集