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
190
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
190
Coding Challenge Advent of Code 2019
ma2gedev
0
120
Developer Experience in GraphQL Schema-first Development
ma2gedev
0
2.1k
Dependency Inversion Principle in Keyboard Firmware
ma2gedev
0
410
OSSの歩き方 / Walking with OSS
ma2gedev
10
2.5k
GraphQL 開発で必要になったこと / What we needed for GraphQL development
ma2gedev
0
1k
キーボードをカスタムしてプログラミング環境を良くした話 / Improved programming environment with customizing keybords
ma2gedev
0
1.2k
Translating "Erlang in Anger" with Erlang & Elixir community members
ma2gedev
0
2.7k
Dive into Elixir v1.6 Code Formatter
ma2gedev
1
150
Other Decks in Programming
See All in Programming
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
7
2.8k
Progressive Web Apps für Desktop und Mobile mit Angular (Hands-on)
christianliebel
PRO
0
110
Universal Linksの実装方法と陥りがちな罠
kaitokudou
1
220
hotwire_or_react
harunatsujita
8
4k
Synchronizationを支える技術
s_shimotori
1
150
Googleのテストサイズを活用したテスト環境の構築
toms74209200
0
270
Importmapを使ったJavaScriptの 読み込みとブラウザアドオンの影響
swamp09
4
1.2k
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
23k
Dev ContainersとGitHub Codespacesの素敵な関係
ymd65536
1
130
Nuxtベースの「WXT」でChrome拡張を作成する | Vue Fes 2024 ランチセッション
moshi1121
1
510
カラム追加で増えるActiveRecordのメモリサイズ イメージできますか?
asayamakk
4
1.5k
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
390
Featured
See All Featured
For a Future-Friendly Web
brad_frost
175
9.4k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Adopting Sorbet at Scale
ufuk
73
9k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
41
2.1k
Typedesign – Prime Four
hannesfritz
39
2.4k
Producing Creativity
orderedlist
PRO
341
39k
We Have a Design System, Now What?
morganepeng
50
7.2k
Visualization
eitanlees
144
15k
Side Projects
sachag
452
42k
The Pragmatic Product Professional
lauravandoore
31
6.3k
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