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
180
Coding Challenge Advent of Code 2019
ma2gedev
0
110
Developer Experience in GraphQL Schema-first Development
ma2gedev
0
2.1k
Dependency Inversion Principle in Keyboard Firmware
ma2gedev
0
400
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
140
Other Decks in Programming
See All in Programming
From Idea to IDE: Developing Plugins for Android Studio
thisaay
1
140
How to Break into Reading Open Source
kaspth
1
210
Swift Concurrencyとレースコンディション
objectiveaudio
1
410
いまから追い上げる、Jetpack Compose トレーニング
nyafunta9858
0
300
僕が思い描くTypeScriptの未来を勝手に先取りする
yukukotani
9
2.4k
null or undefined
susisu
24
6.2k
GraphQLの魅力を引き出すAndroidクライアント実装
morux2
3
410
[DroidKaigi 2024] Android ViewからJetpack Composeへ 〜Jetpack Compose移行のすゝめ〜 / From Android View to Jetpack Compose: A Guide to Migration
syarihu
1
340
1人で挑むSwiftコンパイラ 〜型システム入門編〜
s_shimotori
0
340
2024 컴포즈 정원사
jisungbin
0
150
REXML改善のその後
naitoh
0
190
Using Livebook to build and deploy internal tools @ ElixirConf 2024
hugobarauna
0
250
Featured
See All Featured
Practical Orchestrator
shlominoach
185
10k
Principles of Awesome APIs and How to Build Them.
keavy
125
16k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
29
2.6k
Mobile First: as difficult as doing things right
swwweet
221
8.8k
Learning to Love Humans: Emotional Interface Design
aarron
270
40k
Building Flexible Design Systems
yeseniaperezcruz
325
37k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
502
140k
The Cost Of JavaScript in 2023
addyosmani
42
5.5k
Testing 201, or: Great Expectations
jmmastey
36
7k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
45
4.8k
RailsConf 2023
tenderlove
28
810
What's new in Ruby 2.0
geeforr
340
31k
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