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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:54:08+00:00 2026-06-14T23:54:08+00:00

I am storing timestamps and some associated user data sent up by android devices

  • 0

I am storing timestamps and some associated user data sent up by android devices in a MySQL table, the structure of which is as follows:

CREATE TABLE IF NOT EXISTS `breadcrumbs` (   
  `breadcrumbs_id` bigint(20) NOT NULL AUTO_INCREMENT,   
  `users_id` int(10) NOT NULL,   
  `timestamp` bigint(20) NOT NULL,   
  `data` text,   
  PRIMARY KEY (`breadcrumbs_id`,`users_id`),   
  KEY `fk_breadcrumbs_users1` (`users_id`)   
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=468792 ;   

The android devices are sending up the timestamps in milliseconds and is following the UTC time standard to build the timestamps.
I have been trying to remove breadcrumbs older than one month. As MySQL does not have milliseconds format, I have been using the following query:

DELETE FROM breadcrumbs WHERE ((`timestamp`)/1000) < UNIX_TIMESTAMP() - 2592000;

It takes quite some time to delete the records. Below is the result of running the delete query:

/*382,580 rows affected, 0 rows found. Duration for 1 query: 36.894 sec. */

My questions are:

  1. Am I picking up the breadcrumbs correctly?
  2. Can I optimize the DELETE query so it runs faster than currently it is.
  • 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-14T23:54:10+00:00Added an answer on June 14, 2026 at 11:54 pm

    Your query logic is correct, but I would suggest not storing the milliseconds format in the first place, and instead, divide by 1000 on INSERT (or store both the milliseconds and the plain UNIX timestamp format). Or, store it as a DATETIME using FROM_UNIXTIME(timestamp / 1000) when you INSERT it. Then, create an index on the timestamp column and deletions should be much faster.

    CREATE TABLE IF NOT EXISTS `breadcrumbs` (   
      `breadcrumbs_id` bigint(20) NOT NULL AUTO_INCREMENT,   
      `users_id` int(10) NOT NULL, 
      `timestamp` bigint(20) NOT NULL,
      /* Also consider storing `timestamp` as a DATETIME */
      /* `timestamp` DATETIME NOT NULL, */
      `data` text,   
      PRIMARY KEY (`breadcrumbs_id`,`users_id`),
      KEY `fk_breadcrumbs_users1` (`users_id`),
      /* index on timestamp */
      INDEX `idx_timestamp` (`timestamp`) 
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=468792 ;   
    
    /* Store the timestamp without the milliseconds (or store it both ways in 2 columns) */
    INSERT INTO breadcrumbs (`breadcrumbs_id`, `users_id`, `timestamp`, `data`) VALUES (123,123, input_timestamp / 1000, data)
    /* Or even better, store it as a MySQL DATETIME */
    INSERT INTO breadcrumbs (`breadcrumbs_id`, `users_id`, `timestamp`, `data`) VALUES (123,123, FROM_UNIXTIME(input_timestamp / 1000), data)
    

    As an indexed DATETIME column, your DELETE query would look like:

    DELETE FROM breadcrumbs WHERE `timestamp` < NOW() - INTERVAL 1 MONTH;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am storing some days and hours as timestamp in my MySQL table. What
I am looking at storing some JMX data from JVMs on many servers for
I'm storing a timestamp in a mysql table every time somebody visits the site
I'm thinking about trying MongoDB to use for storing our stats but have some
I need some help to understand how can I track the data to insert
I am using strtotime to get some relative timestamps using a string description of
I am storing some records in a database. A record has a 'last visited'
My rails app has a simple model Links which tracks all the Urls associated
I am building a query that performs some filtering on rating data. Suppose I
I'm working on some animatronics for an art installation which will use several stepper

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.