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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:10:02+00:00 2026-05-12T17:10:02+00:00

I have a large table (several million rows) in a MySQL (version 5.0) database

  • 0

I have a large table (several million rows) in a MySQL (version 5.0) database that has data inserted into it at a very frequent rate.

There are also less frequent select statements done against the database that only required the latest data (i.e. the newest 10000 rows), is there a way to create a table that would keep a copy of data from the main table and would dynamically add new rows whenever a new row was added to the main table (I can delete the old data periodically so that’s not too much of an issue) without causing much of an impact to the main table.

If possible I would also like to Index rows in the 2nd table slightly differently.

  • 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-12T17:10:02+00:00Added an answer on May 12, 2026 at 5:10 pm

    It sounds like you should use triggers.

    You’ll need three triggers on the large table:

    • AFTER INSERT, for each row you’ll need to copy the new row into the smaller table and delete the oldest row from the smaller table
    • AFTER UPDATE, for each row you’ll need to check whether that row is in the smaller table and if it is, make the same updates to it
    • AFTER DELETE, for each row you’ll need to check whether that row is in the smaller table and if it is, remove it.

    For example:

    DELIMITER //
    CREATE TRIGGER after_insert AFTER INSERT ON big_table
    FOR EACH ROW
    BEGIN
        DECLARE small_table_rows INTEGER;
        INSERT INTO small_table (field1, field2) VALUES (NEW.field1, NEW.field2);
        SELECT COUNT(*) INTO small_table_rows FROM small_table;
        IF small_table_rows > 10000 THEN
            DELETE FROM small_table ORDER BY id ASC LIMIT 1;
        END IF
    END;//
    DELIMITER ;
    
    DELIMITER //
    CREATE TRIGGER after_update AFTER UPDATE ON big_table
    FOR EACH ROW
    BEGIN
        UPDATE small_table
        SET field1 = NEW.field1, field2 = NEW.field2
        WHERE small_table.id = NEW.id;
    END;//
    DELIMITER ;
    
    DELIMITER //
    CREATE TRIGGER after_delete AFTER DELETE ON big_table
    FOR EACH ROW
    BEGIN
        DELETE FROM small_table WHERE small_table.id = OLD.id;
    END;//
    DELIMITER ;
    

    It’s fairly straightforward, though the triggers can get unwieldy if the tables have a lot of columns. You may want to consider the performance characteristics of MyISAM vs InnoDB; InnoDB may offer better overall performance depending on what sorts of queries you are running.

    You don’t want to use views; views in MySQL are not materialized, so you won’t generally get any performance benefit (which is what it sounds like you want) and you won’t be able to index the view differently from the table(s) on which the view is based.

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

Sidebar

Ask A Question

Stats

  • Questions 354k
  • Answers 354k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to do this through VBScript and load in… May 14, 2026 at 7:52 am
  • Editorial Team
    Editorial Team added an answer EDIT: I tried to clarify I bit more ... 1.… May 14, 2026 at 7:52 am
  • Editorial Team
    Editorial Team added an answer Read each line, stick the contents of the line into… May 14, 2026 at 7:52 am

Related Questions

I need to store a large table (several millions or rows) that contains a
I have a question about the SQL standard which I'm hoping a SQL language
I have a SQL query that takes a very long time to run on
I have a very simple linq to sql query in C#: int acctNum =

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.