How to find the oldest or most recent record associated with a particular foreign key.
What do you do when indexes aren’t enough?
Take a guided tour through a query plan for a “simple” SQL query.
How can you plug complex, multi-model SQL queries into ActiveRecord models so that you can use them in your views?
Take your queries to the next level with window functions.
Use SQL EXPLAIN to understand when and why indexes are used (or not).
An in-depth overview of INSERT, SELECT, UPDATE, and DELETE statements,
ORDER BY, INNER JOIN, LEFT OUTER JOIN, WHERE, GROUP BY, and HAVING clauses,
and topics such as join tables and sub-queries.
Calculations across objects are ripe for using a map and an inject but frequently, with ActiveRecord, the solution is more elegant and faster if we can have SQL do the work instead.
How moving some data out of the database and into your codebase
as well-named constants can decouple your code and improve performance.
Thoughts on safe indexes to add to Rails app databases.