Monday, October 09, 2017

How to Speed Up Your SQL Queries With ActiveRecord

DZone Database Zone
How to Speed Up Your SQL Queries With ActiveRecord
How to Speed Up Your SQL Queries With ActiveRecord

At PhraseApp, we provide weekly Brownbag sessions get new developers on board and share knowledge across the team. Last week, I held a Brownbag session about how to improve and debug ActiveRecord-generated SQL queries. This blog post series presents the basics of working with Rails and ActiveRecord to write a more performant code.

Today, I want to share some knowledge about improving the performance of ActiveRecord queries by selecting only the needed data and reduce the number of instantiated objects. There are many cases in your Rails application when you only need a small subset of data and not the whole record. For example, if you want to render a user select box where you only need the id” and name fields, you can use something similar to the following code:

No comments:

Fun With SQL: Functions in Postgres

DZone Database Zone Fun With SQL: Functions in Postgres In our previous  Fun with SQL  post on the  Citus Data  blog, we covered w...