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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:58:31+00:00 2026-05-23T15:58:31+00:00

I have a table which gets around 10-15k entries per minute. Each one is

  • 0

I have a table which gets around 10-15k entries per minute. Each one is marked with the current timestamp upon entry. The table is a MEMORY table, since losing data is not a concern.

Every minute, I have a script which runs the following query:

DELETE FROM tracker WHERE post_time < DATE_SUB(NOW(), INTERVAL 15 MINUTE)

This query is taking about 1-2 seconds to run, which isn’t bad, but it seems that this type of query (deleting everything older than X) should be able to perform much faster when being run against a MEMORY table. It also has a corresponding spike to the CPU which sticks out like a sore thumb every minute.

Are there any optimizations I can do to my query to run this query more efficiently?

  • 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-23T15:58:31+00:00Added an answer on May 23, 2026 at 3:58 pm

    As always, you should view the query plan, and post it here. You do that by issuing EXPLAIN DELETE FROM tracker WHERE post_time < DATE_SUB(NOW(), INTERVAL 15 MINUTE)

    Now, the problem is likely that the DELETE query can’t use an index, and have to loop through all of your rows.

    Even if you already have an index on post_time , it will likely not be used, as by default indexes on MEMORY tables are hash indexes.
    Hash indexes can only be used for equality checks, and not ranges such as post_time < DATE_SUB(NOW(), INTERVAL 15 MINUTE)

    Create a BTREE index on your post_time column,

    CREATE INDEX post_time_idx ON tracker (post_time) USING BTREE;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which contains around 400 000 records and which gets called
I have a innoDB table which records online users. It gets updated on every
I have a table which has several one to many relationships with other tables.
I have a table which needs to link one of three seperate tables, but
I have an invoices table which stores a single record for each invoice, with
I have table which contains double values stored in mysql database ...I need to
I have a table which has codes and is linked with a table of
I have a table which looks like this: Column | Type | ----------------------+-------------------------+ ...
I have a table which will have a date/time column to store create date
I have a table which is full of arbitrarily formatted phone numbers, like this

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.