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
210
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
350
Coding Challenge Advent of Code 2019
ma2gedev
0
170
Developer Experience in GraphQL Schema-first Development
ma2gedev
0
2.4k
Dependency Inversion Principle in Keyboard Firmware
ma2gedev
0
560
OSSの歩き方 / Walking with OSS
ma2gedev
10
2.7k
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
210
Other Decks in Programming
See All in Programming
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.2k
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
730
AIチームを指揮するOSS「TAKT」活用術 / How to Use “TAKT,” an OSS Tool for Orchestrating AI Teams
nrslib
6
890
AIだと陥りがちなJakarta EE最新技術への移行時の落とし穴と解決策
tnagao7
0
100
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
120
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
780
Agentic UI
manfredsteyer
PRO
0
150
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
230
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
2k
AutonomyとControlのあいだ:Graflowで記述するAIエージェント協調
myui
0
120
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
330
Featured
See All Featured
Utilizing Notion as your number one productivity tool
mfonobong
4
320
Prompt Engineering for Job Search
mfonobong
0
340
Design in an AI World
tapps
1
240
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
23k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
Un-Boring Meetings
codingconduct
0
310
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
300
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
160
Become a Pro
speakerdeck
PRO
31
6k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
140
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.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