Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6057071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:26:52+00:00 2026-05-23T08:26:52+00:00

Environment: MySql, Rails 3.0.7 In my user table I have a ‘last_activity_date’ column which

  • 0

Environment: MySql, Rails 3.0.7

In my user table I have a ‘last_activity_date’ column which is kept up to date using various after_save hooks scattered throughout the app.

I currently have the following named scope:

scope :active, lambda { where('last_activity_date >= ?', 1.month.ago) }

which is used very frequently. It had not seemed worth indexing that column given it’s lack of selectivity and because it is updated fairly frequently (daily for some users, very seldom for others).

As the number of users grows, queries using the ‘active’ scope are taking longer and longer, though. Will indexing the ‘last_activity_date’ column be worth it in the long run?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:26:52+00:00Added an answer on May 23, 2026 at 8:26 am

    If the queries you have look like your comment:

    SELECT users.* 
    FROM users
    WHERE (last_activity_date >= '2011-05-22 00:26:52')
      AND (users.id >= 0)
    ORDER BY users.id ASC
    LIMIT 1000
    

    then definitely, yes, the performance of these queries will greatly improve with a simple index on last_activity_date

    I guess that users.id is the PRIMARY KEY of the table, so there is already an index on it.


    When you don’t have an index, the query has to scan the whole users table, to check which rows satisfy the condition last_activity_date >= 1 month ago. With a small numbers of users that goes unnoticable. With thousands (or millions) of users, it will be real slow.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Environment: Rails 3.0.1, MySQL I have a Users table, and I want to search
We're using MySQL with Innodb Engine storage. We have an evented environment that sends
I have been using mysql in a new rails application, but now I wanted
we have developed an rails project using rails 3 and mysql, it has images,
In a Rails app, I have foreign key constraints in MySQL which I set
First the environment: Rails 2.1.0, Ruby 1.8.7, Mysql 5.1.54, Ubuntu 11.04 I have a
I have a Ruby/Rails devvelopment environment using rbenv, MRI Ruby (1.9.2-p290), rails 3.0.9, and
My development environment: Ubuntu 9 Ruby 1.9.1/1.8.7 (rvm) Rails 2.3.5 Mysql 5.0 Apache Passenger
Mysql's environment is following: character_set_database=big5 And when I send a SQL which contains tranditional
I have a problem with MySql.Data in a partial trusted environment. I've added MySql.Data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.