Twenty Thousand Leagues Under ActiveRecord
summary
A Rails call like user.where(name: 'Captain Nemo').first builds an ActiveRecordRelation that constructs an Arel gem abstract syntax tree; a Postgres visitor then generates SQL with a $1 bind. Postgres parses that SQL back to its own AST, makes a plan and executes it; without an index a sequence scan reads the whole table and sort pulls all rows, but adding an index creates a sorted copy so an index scan replaces sequential scan and uses binary search/B‑tree logic with Lehman & Yao sibling pointers to allow concurrent inserts; run EXPLAIN to confirm.
AI-written summary · about
chapters (17)
- 0:00Start
- 3:41Agenda
- 11:38Relational Algebra
- 12:46The Abstract Syntax Tree
- 14:37Visitor Pattern
- 16:04Join Source
- 18:47How Database Servers Work
- 19:21Parser Generator Engine
- 20:23Abstract Syntax Tree
- 21:40Analyzed and Rewrite
- 24:26Sequence Scan
- 25:57Captain Nemo
- 32:09B-Tree Algorithm
- 36:15Balance Tree Algorithm
- 36:40Indexes in Postgres
- 37:12Recap
- 38:03Ruby under a Microscope
related talks
25mActiveRecord can't do it? Arel can!
32mArel: The Ruby Relational Algebra Library
21mActiveRecord can't do it? Arel can!
28mActive Record Scopes and Arel
38mSequel: When ActiveRecord is not enough
35mAdvanced aRel: When ActiveRecord Just Isn't Enough
30mBuilding an ORM with AReL: Walking up the (AS)Tree.
17mWrangle Your SQL With Arel
