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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Takayuki Matsubara
December 22, 2015
Programming
210
1
Share
ActiveRecord::PostgreSQLAnalyzer gem を作った話 #m3dev
M3 Tech Talk で「ActiveRecord::PostgreSQLAnalyzer gem を作った話」というタイトルで LT したときの資料です。
#m3dev
Takayuki Matsubara
December 22, 2015
More Decks by Takayuki Matsubara
See All by Takayuki Matsubara
Rails Web Development with AWS Lambda
ma2gedev
0
340
Coding Challenge Advent of Code 2019
ma2gedev
0
160
Developer Experience in GraphQL Schema-first Development
ma2gedev
0
2.4k
Dependency Inversion Principle in Keyboard Firmware
ma2gedev
0
540
OSSの歩き方 / Walking with OSS
ma2gedev
10
2.6k
GraphQL 開発で必要になったこと / What we needed for GraphQL development
ma2gedev
0
1.3k
キーボードをカスタムしてプログラミング環境を良くした話 / Improved programming environment with customizing keybords
ma2gedev
0
1.4k
Translating "Erlang in Anger" with Erlang & Elixir community members
ma2gedev
0
2.9k
Dive into Elixir v1.6 Code Formatter
ma2gedev
1
200
Other Decks in Programming
See All in Programming
アーキテクチャモダナイゼーションとは何か
nwiizo
19
5.3k
〜バイブコーディングを超えて〜 チームで実験し続けたAI駆動開発
tigertora7571
0
110
クラウドネイティブなエンジニアに向ける Raycastの魅力と実際の活用事例
nealle
2
200
(Re)make Regexp in Ruby: Democratizing internals for the JIT
makenowjust
2
180
Don't Prompt Harder, Structure Better
kitasuke
0
770
10 Tips of AWS ~Gen AI on AWS~
licux
5
410
検索設計から 推論設計への重心移動と Recall-First Retrieval
po3rin
0
110
Claude Code × Gemini × Ebitengine ゲーム制作素人WebエンジニアがGoでゲームを作った話
webzawa
0
140
Making the RBS Parser Faster
soutaro
0
380
Coding as Prompting Since 2025
ragingwind
0
830
「Linuxサーバー構築標準教科書」を読んでみた #ツナギメオフライン.7
akase244
0
1.4k
의존성 주입과 모듈화
fornewid
0
140
Featured
See All Featured
Mind Mapping
helmedeiros
PRO
1
150
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
150
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Writing Fast Ruby
sferik
630
63k
Typedesign – Prime Four
hannesfritz
42
3k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
100
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
110k
ラッコキーワード サービス紹介資料
rakko
1
3.1M
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
150
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
270
Done Done
chrislema
186
16k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
730
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