Optimize Queries
Prerequisites
Add Database Indexes
Single Column Index
class AddIndexes < CQL::Migration(1)
def up
add_index :users, :email
add_index :posts, :user_id
add_index :posts, :published_at
end
def down
remove_index :users, :email
remove_index :posts, :user_id
remove_index :posts, :published_at
end
endComposite Index
Unique Index
Use Select to Limit Columns
Use Pluck for Single Values
Limit Result Sets
Use Count Instead of Size
Batch Processing
Use Exists Instead of Count
Optimize Ordering
Analyze Slow Queries
Verify Optimization
See Also
Last updated
Was this helpful?