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 9097459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:07:22+00:00 2026-06-17T00:07:22+00:00

I have a table that holds all system users. As time passes some user

  • 0

I have a table that holds all system users. As time passes some user accounts end up dormant and unused in this table.

If I had a large number of users it could be good to partition the table by date (last logon date) and then query for users based on date. eg: you login and your lastlogondate is updated which is what the partitioning uses.

Question: would this mean all the current users would be say in the first partition as their date stamp is current. Could this be a good way to keep the current pool of active users in one partition and the reset of obsolute accounts would end up residing in other partitions depending on there last active date. (Note: if the user logged in again they would become active again).

Would this be a good way to speed up queries?

  • 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-06-17T00:07:24+00:00Added an answer on June 17, 2026 at 12:07 am

    No, I would not use this method of partitioning.

    To benefit from MySQL partition pruning, your queries must reference the column of the partition key. So for your proposed partitioning scheme to give any benefit, all your queries for users would need to reference the last_login column, and you would need to update the value you compare against the last_login column continually:

    SELECT ... FROM users WHERE user_name = 'Adam' AND last_login >= '2013-01-01'
    -- remember to change this to '2013-02-01' by next month
    

    Without the term searching for specific last_login, the query would have to scan all the partitions.

    I’d also be worried about “partition churn” that is, rows moving from one partition to another frequently.

    Also recall that in MySQL, the partition column must be part of every primary or unique key in the table. So using last_login as the partition key would require you to define your table:

    CREATE TABLE Users (
      user_name VARCHAR(12) NOT NULL,
      last_login DATETIME NOT NULL,
      ...
      PRIMARY KEY (user_name, last_login)
    );
    

    This opens up the possible data anomaly of another user creating account “Adam”, as long as they have a distinct last login time. Both accounts could exist in the same table for an indefinite length of time, until the two Adams happen to log in at the exact same time. Then one may be denied login because of a primary key violation. That would be a very puzzling reason to be denied a login.

    A slightly better partitioning scheme would be this:

    CREATE TABLE Users (
      user_name VARCHAR(12) NOT NULL,
      last_login DATETIME NOT NULL,
      is_archived TINYINT(1) NOT NULL DEFAULT 0,
      ...
      PRIMARY KEY (user_name, is_archived)
    ) PARTITION BY HASH(is_archived) PARTITIONS 2;
    

    The intent is that you periodically run a job to manually archive users:

    UPDATE Users SET is_archived=1 WHERE last_login < CURDATE() - INTERVAL 30 DAY;
    

    This solves the partition churn problem and the partition-creation chore problem. It still potentially allows more than one “Adam” to exist, but if you carefully control the instances of moving a row from one partition to the other, that should be lower risk.

    You’d still have to reference the partition key in your queries, but the value you compare against would be fixed:

    SELECT ... FROM users WHERE user_name = 'Adam' AND is_archived = 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a table that holds my users information like username , password ,
I have a configuration table, that holds the values selected by a specific user.
I happen to have a database with a table that holds all possible combination
I am using PHP/MySQLin my project, and I have a table that holds time
I have a dropdown list that holds all the columns name from the table.
Given that I have a table that holds vehicle information and one of those
I have a MySQL table that holds many entries with repeated IDs (for various
Hi I have a datatables based table that holds data. I need to be
I have a table (table variable in-fact) that holds several thousand (50k approx) rows
Lets suppose that I have a Category table with a column that holds the

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.