performance
Last updated
Was this helpful?
Last updated
Was this helpful?
select
, pluck
pluck
will load an array of column, and is faster than select
.
select
is ~10X slower than pluck
, because of creating objects.
10.4ms for db query, but total 143ms for the whole process.
preload
, eager_load
, includes
= eager loading (prevent n+1)
Preload
loads the association data in a separate query.
Since preload
always generates two sql, we can’t use posts table in where condition.
eager_loading
loads all association in a single query using LEFT OUTER JOIN.
Includes
Behaves based on situations, intelligent!
includes
+ references
= eager_loading
Joins
brings association data using inner join.
Array
DB query
sort_by
order
.select { c c.label != 'All' }
.where.not(label: 'All')