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

  • Home
  • SEARCH
  • 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 4013776
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:24:49+00:00 2026-05-20T09:24:49+00:00

I am working on a social network type project, as most social networks have,

  • 0

I am working on a social network type project, as most social networks have, a user feed that will show things that YOUR friends have done on the site.

So let’s say I have a MySQL table for these items with these fields;

// user_actions  
auto_id = auto increment ID  
type = a number (1 = photo upload, 2 = friend added, 3 = status post, 4 = so other action, etc..)  
user_id = The id of the user who did the action  
datetime = date and time  
action_id = this could be the ID of the action, so if it is for a status post, it could be the ID of the actual status  post record  

Now in my PHP script, I would query this table to get all friend actions of a user.

I think this is the perfect type of table to use the MySQL partitioning, so instead of showing all actions from your friends and having it query every action ever posted on the site, which could be in the millions of records based off a previous site I had done, I think it would be good to partition bye date, maybe have all actions partioned into 6 month partitions, so it is less records to query.

I have never worked with the partitions but have been looking for a sollution similar to this for a few years, I just discovered the built in MySQL partitions and they seem like the ticket here.

Can someone show me how I could go about creating a table like that into partitions, also since I would need a new partition created every 6 months, is there a way to automate new partitions? Please help

  • 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-20T09:24:50+00:00Added an answer on May 20, 2026 at 9:24 am

    This is untested, but should be close.

    CREATE TABLE user_actions (
        auto_id         INT NOT NULL AUTO_INCREMENT,
        type            INT NOT NULL,
        user_id         INT NOT NULL,
        insert_datetime DATE NOT NULL,
        action_id       INT NOT NULL) 
    PARTITION BY RANGE(TO_DAYS(insert_datetime))
    (
        PARTITION p0  VALUES LESS THAN (to_days('2011-06-01')),
        PARTITION p1  VALUES LESS THAN (to_days('2012-01-01')) ,
        PARTITION p11 VALUES LESS THAN MAXVALUE 
    );
    

    You can manage this in the following way:

    You can have the MAXVALUE partition always represent your “active” (in your case current 6 month period) partition. When the period is up, you can split/reorg that MAXVALUE partition where the period that past goes into a new partition with the MAXVALUE partition representing again the current/active partition.

    For example, Jan 1st of 2011 you would have one partition, let’s call it pM and it would store everything as it would have the LESS THAN MAXVALUE clause. Then after 6 months have passed, you would reorg/split that single partition creating a new partition that holds all the data for the previous 6 months and the MAXVALUE partition again representing the current/active period.

    -- Untested, but again should be close
    ALTER TABLE t1 REORGANIZE PARTITION (pM) INTO
    (PARTITION p20110101 VALUES LESS THAN (to_days('2011-07-01'), 
     PARTITION pM VALUES LESS THAN MAXVALUE); 
    

    You may also consider sub-partitioning. You could sub-partition your user_id by HASH and therefore further reduce I/O and cost on queries for data based on the user_id.

    Check out the following links for more information on partitioning.

    MySQL Partitioning

    Partition Managment

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

Sidebar

Related Questions

I am working on a research project that deals with social networks. I have
I have an idea of a social network website and I will be working
I have a pet project I am working on that is a social concept.
I have a social network type app I have been working on for at
I have a pretty large social network type site I have working on for
I am working on a social network project in PHP/MySQL. If you have ever
I'm working on a social networking system that will have comments coming from several
I am working on a user based social network. I am building the site
I'm working on a Rails app that implements some social network features as relationships,
I'm working on a website that will use features of social networking (like facebook

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.