Released a new gem to detect unnecessary selected database columns

You know how SELECT * can be bad for performance, right? Extra serialization/deserialization, more disc and network IO, no index-only scans etc :expressionless: (a good detailed read on this topic Reasons why SELECT * is bad for SQL performance | Tanel Poder Consulting).

I created a small gem to tackle exactly this problem - show unused selected columns. Works for controllers, ActiveJob and sidekiq jobs - GitHub - fatkodima/columns_trace: Find unnecessary selected database columns

The logged output looks like this:

  1 User record: unused columns - "bio", "settings"; used columns - "id", "email", "name",
  "account_id", "created_at", "updated_at"
  ↳ app/controllers/application_controller.rb:32:in `block in <class:ApplicationController>'

  1 Account record: unused columns - "settings", "logo", "updated_at";
  used columns - "id", "plan_id"
  ↳ app/controllers/application_controller.rb:33:in `block in <class:ApplicationController>'

  10 Project records: unused columns - "description", "avatar", "url", "created_at", "updated_at";
  used columns - "id", "user_id"
  ↳ app/models/user.rb:46: in `projects'
    app/services/imports_service.rb:129: in `import_projects'
    app/controllers/imports_controller.rb:49:in `index'

  1 User record: unused columns - "email", "name", "bio", "created_at", "updated_at";
  used columns - "id", "settings"
  ↳ app/jobs/import_project_job.rb:23:in `perform'

  1 Project record: unused columns - "description", "avatar", "settings", "created_at",
  "updated_at"; used columns - "id", "user_id", "url"
  ↳ app/jobs/import_project_job.rb:24:in `perform'
1 Like

Released a new version with tracing mailers and ability to trace custom code.