RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

A new gem to detect unnecessarily selected database columns

https://github.com/fatkodima/columns_trace

You know how SELECT * can be bad for performance, right? Extra serialization/deserialization, more disc and network IO, no index-only scans etc 😑 (a good detailed read on this topic https://tanelpoder.com/posts/reasons-why-select-star-is-bad-for-sql-performance/ ).

I created a small gem to tackle exactly this problem - show unused selected columns. Works for controllers, ActiveJob and sidekiq jobs.

The logged output looks like this:

ImportsController#create
  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'

ImportProjectJob
  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'

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in