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
ActiveRecord::PostgreSQLAnalyzer gem を作った話 #m3dev
Search
Takayuki Matsubara
December 22, 2015
Programming
1
200
ActiveRecord::PostgreSQLAnalyzer gem を作った話 #m3dev
M3 Tech Talk で「ActiveRecord::PostgreSQLAnalyzer gem を作った話」というタイトルで LT したときの資料です。
#m3dev
Takayuki Matsubara
December 22, 2015
Tweet
Share
More Decks by Takayuki Matsubara
See All by Takayuki Matsubara
Rails Web Development with AWS Lambda
ma2gedev
0
280
Coding Challenge Advent of Code 2019
ma2gedev
0
130
Developer Experience in GraphQL Schema-first Development
ma2gedev
0
2.2k
Dependency Inversion Principle in Keyboard Firmware
ma2gedev
0
480
OSSの歩き方 / Walking with OSS
ma2gedev
10
2.6k
GraphQL 開発で必要になったこと / What we needed for GraphQL development
ma2gedev
0
1.2k
キーボードをカスタムしてプログラミング環境を良くした話 / Improved programming environment with customizing keybords
ma2gedev
0
1.3k
Translating "Erlang in Anger" with Erlang & Elixir community members
ma2gedev
0
2.8k
Dive into Elixir v1.6 Code Formatter
ma2gedev
1
170
Other Decks in Programming
See All in Programming
機械学習って何? 5分で解説頑張ってみる
kuroneko2828
0
220
C++20 射影変換
faithandbrave
0
500
単体テストの始め方/作り方
toms74209200
0
510
Development of an App for Intuitive AI Learning - Blockly Summit 2025
teba_eleven
0
120
XSLTで作るBrainfuck処理系
makki_d
0
210
Select API from Kotlin Coroutine
jmatsu
1
180
WindowInsetsだってテストしたい
ryunen344
1
190
Javaのルールをねじ曲げろ!禁断の操作とその代償から学ぶメタプログラミング入門 / A Guide to Metaprogramming: Lessons from Forbidden Techniques and Their Price
nrslib
3
2k
データベースコネクションプール(DBCP)の変遷と理解
fujikawa8
1
270
AIコーディング道場勉強会#2 君(エンジニア)たちはどう生きるか
misakiotb
1
240
今ならAmazon ECSのサービス間通信をどう選ぶか / Selection of ECS Interservice Communication 2025
tkikuc
11
2.7k
Gleamという選択肢
comamoca
6
740
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
920
Automating Front-end Workflow
addyosmani
1370
200k
Why You Should Never Use an ORM
jnunemaker
PRO
56
9.4k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Stop Working from a Prison Cell
hatefulcrawdad
270
20k
The Straight Up "How To Draw Better" Workshop
denniskardys
233
140k
Designing for humans not robots
tammielis
253
25k
4 Signs Your Business is Dying
shpigford
184
22k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.8k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
43
2.4k
Thoughts on Productivity
jonyablonski
69
4.7k
YesSQL, Process and Tooling at Scale
rocio
173
14k
Transcript
ActiveRecord::Postgr eSQLAnalyzer gem Λ࡞ͬͨ !
ࣗݾհ
TODO: !
⭐ github.com/ma2gedev/ power_assert_ex
ActiveRecord::PostgreSQLAnalyzer https://github.com/m3dev/ active_record- postgresql_analyzer
͖͔͚ͬ
m3 advent calendar
SAStruts + S2JDBC ͷࢥ͍ग़ʹ͍ͭͯ ଘʹޠΔ #m3dev — @seratch http://qiita.com/ seratch@github/items/
826f1b4a89993d3b0804
Sequential Scan ݕ
ศརͦ͏ ͪͳΈʹ͜ͷΞΠσΞࣗମ S2JDBC ʹݶఆ͞Ε·ͤΜɻࠓͬͨϓϩδ ΣΫτͰ Scala ͷΞϓϦέʔγϣϯ Ͱಉ͡Α͏ͳίʔυΛॻ͍ͨͷͰ͢ ͕ɺඇৗʹ༗༻Ͱͨ͠ɻ —
@seratch
Ruby(RoR)ʁ
ͳ͚Ε࡞Ζ ͏ OSS
ActiveRecord::PostgreSQLAnalyzer https://github.com/m3dev/ active_record- postgresql_analyzer
Rails ͰγʔέϯγϟϧεΩ ϟϯ͍ͯ͠ΔΫΤϦΛݟ ͚ͭͯḿΓ͍ͨ - PostgreSQL ݶ ఆ http://qiita.com/ma2ge/ items/0df91b0fbd90808f40d5
όζͬ ͨʂʁ
όζͬͯͳ ͍
ͩ͞·͞͠ऑऀ͗ͯ͢ࠔͬͨͷͰ Scala ͰίϯύΠϧ͢Δ͜ͱʹͨ͠ — @seratch http://qiita.com/ seratch@github/items/ 3be26b584f3d74aa1150
͍ํ
Gemfile gem 'active_record-postgresql_analyzer', group: :development
Output logfile if sequential scan is detected ------------ find Seq
Scan query ------------ SELECT "todo".* FROM "todo" WHERE "todo"."user_id" = $1 LIMIT 1 QUERY PLAN --------------------------------------------------------------------------------------------- Limit (cost=10000000000.00..10000000001.67 rows=1 width=81) -> Seq Scan on todo (cost=10000000000.00..10000000001.67 rows=1 width=81) Filter: (user_id = 13) (3 rows)
Έ
ActiveSupport::Notifications ActiveRecord::PostgreSQLAnalyzer::LogSubscriber.attach_to :active_record https://github.com/m3dev/ active_record-postgresql_analyzer/ blob/master/lib/active_record/ postgresql_analyzer.rb#L42
Explain ActiveRecord::Base.connection.explain(payload[:sql], payload[:binds]) https://github.com/m3dev/ active_record-postgresql_analyzer/ blob/master/lib/active_record/ postgresql_analyzer.rb#L22
Detect Sequential Scan SELECT "todo".* FROM "todo" WHERE "todo"."user_id" =
$1 LIMIT 1 QUERY PLAN --------------------------------------------------------------------------------------------- Limit (cost=10000000000.00..10000000001.67 rows=1 width=81) -> Seq Scan on todo (cost=10000000000.00..10000000001.67 rows=1 width=81) Filter: (user_id = 13) (3 rows) https://github.com/m3dev/ active_record-postgresql_analyzer/ blob/master/lib/active_record/ postgresql_analyzer.rb#L23
index షΓΕ ࢭ
ActiveRecord::PostgreSQLAnalyzer https://github.com/m3dev/ active_record- postgresql_analyzer
⭐ github.com/ma2gedev/ power_assert_ex
end