---
title: Use pluck for selecting specific columns
impact: MEDIUM
impactDescription: Improve query performance by selecting only needed columns.
tags: rails, performance, database, active-record
---

## Use pluck for selecting specific columns

Improve query performance by selecting only needed columns. Use `pluck` to select columns from multiple records. Use `pick` for a single value from a single record.

**Incorrect:**

```ruby
# Loads whole User objects into memory just to get ids
User.all.map(&:id)
```

**Correct:**

```ruby
# Only selects 'id' in SQL
User.pluck(:id)

# Even better for IDs specifically
User.ids
```

**Tools:** RuboCop (`Rails/Pluck`, `Rails/PluckId`)
