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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:13:40+00:00 2026-05-26T16:13:40+00:00

I have a table named events , which contains in-game events such as construction

  • 0

I have a table named events, which contains in-game events such as construction of buildings, research, etc.. Each event has a timestamp indicating when it completes. Engine: innoDB

Every pageload, the program runs a quick search of the events table for rows where timestamp is in the past (ie. the event has been completed). It selects these rows then deletes them so any other runs don’t see and process the same events.

What I’m worried about is what would happen if two pagelods happened so that both of them read the same rows before one or the other has a chance to delete the read rows, and what if an event happens right between selecting and deleting.

What I’m thinking should fix it is:

SET @now=NOW();
SELECT * FROM `events` WHERE `timestamp` < @now FOR UPDATE
DELETE FROM `events` WHERE `timestamp` < @now

But I’m having some trouble testing it. How would I go about testing whether or not this is working as it should?

  • 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-26T16:13:40+00:00Added an answer on May 26, 2026 at 4:13 pm

    Going to answer my own question here :p

    Use sleep() between the select and delete, and have two calls at the same time.

    Final code:

    START TRANSACTION
    SET @now=NOW()
    SELECT * FROM `events` WHERE `timestamp` < @now FOR UPDATE
    -- SLEEP(5)
    DELETE FROM `events` WHERE `timestamp` < @now
    

    Results:

    0.000: Starting transaction
    0.001: Query run, returned 5 rows.
    5.002: Deleted 5 rows.
    5.008: Ending transaction
    ===== Second call, started a couple seconds after the first:
    0.000: Starting transaction
    2.562: Query run, returned 0 rows.
    2.562: Deleted 0 rows.
    2.562: Ending transaction

    That’s with the sleep. Without the sleep both end in under 0.002 seconds.

    • 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 lists all events on a debating calendar. Each row
I have a table row which contains a textbox and it has an onclick
I have a table which contains event and its end date as follows -
Let's say you have three tables named Item, Event, and Seat, constructed as such:
i have a table that has event name and event date. if i want
I have a table named tbl_Subjects_Taken which lists all the subjects taken by the
I have a db with events from a event table that selects a eventid,
I have a form(table view) which contains textfields and textview as subviews,I need to
I have Event model which contains following fields string name date start_at date end_at
I have a generated table that contains multiple rows with each row containing a

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.