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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:26:06+00:00 2026-05-19T11:26:06+00:00

My task is to delete all entities that were not affected during an operation

  • 0

My task is to delete all entities that were not affected during an operation from the database. I created a separate table which have two columns, first represets the name of the table and second is the id of the record in that table.

CREATE TABLE edited_entities (
        table VARCHAR(50) not null, 
        id BIGINT(20) not null)

For example if I have table

CREATE TABLE puppy(
        id BIGINT(20) not null, 
        name VARCHAR(20) not null)

and a record in it

id | name
1  | Rex

If I edit this record i will put the following data into edited_entities:

table | id
puppy | 1

Then I need to delete all non affected entities (which ids are not in edited_entities table) and I do following:

delete from puppy where id not in 
    (select ee.id from edited_entities ee where ee.table= 'puppy');

I wonder what is the best engine for such kind of operation (MySql)? The default db engine is InnoDB. I thought about Memory (Heap) but I am not sure if it can faster the delete operation.

If you have suggestion how can I optimise the required operation I will be glad to here it.

I don’t whant to add additional columns into puppy table.

  • 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-19T11:26:07+00:00Added an answer on May 19, 2026 at 11:26 am

    Memory will be faster, since it doesn’t have to go to disk at the end of the transaction. In this case I’d try first BTREE and not HASH index, because it lets you use partial composite indexes, just like on-disk tables.

    Also try with prepared statements for insert and delete operations: prepare one of each before processing and then invoke with the relevant parameters. It might be faster since it doesn’t have to parse the SQL; but there are some cases where the whole system gets a little slower because they take non-trivial amounts of memory.

    Another option is the experimental ‘HandlerSocket‘ feature, available in several forks of MySQL like Percona server, it lets you access a MySQL table as a NoSQL store, with huge performance benefits, but full ACID compliance. (The Percona people are performance fanatics; even if you can’t use HandlerSocket, be sure to test their fork)

    Finally, a viable (but more work for you) option is a separate in-memory database. I’d tend to go with Redis, which is a very high-speed in-memory key-value store with the added twist that the ‘values’ are useful data structures. In your case, you could store a set of IDs for each table, something like

    tokeep:puppy => 1,4,6,76.....
    

    it’s a simple (and atomic) operation to add an element to the set (SADD tokeep:puppy 76), and at the end you fetch them all to create the SQL DELETE WITH id NOT IN (...) operation

    And, the very last option I think of (and still more work for you), would be to put everything in the same store: there’s a fork of Redis, previously called redisql, but now it’s now Alchemy Database; it adds SQL tables to Redis, keeping most of the performance benefits of NoSQL. So, you could have your ‘regular’ tables as SQL tables in Alchemy, store your ‘tokeep’ sets on NoSQL on the same server, and at the end do a:

    DELETE FROM puppy WHERE id NOT IN ($SMEMBERS tokeep:puppy );
    

    Bam!

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

Sidebar

Related Questions

I am using MSBuild and have a Delete task that deletes all the files
Unlike the other posts about the task delete all tables, this question is specifically
Im trying to find a way to delete all duplicated entries in a table
I am looking for the best approach to delete records from a table. For
I have created a thread pool in C++ which stores all tasks in a
I have files that I want to delete. Connection can be from file sharing,
I have such task - to create control that union two controls (DataGrid from
How can I delete a regular Task or PeriodicTask in celery?
TASK : I have an existing xml document (UTF-8) which uses xml namespaces and
Task: I have a camera mounted on the end of our assembly line, which

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.