2

I'm using 5.6 MySQL database to insert tens of millions records between multiple tables.

Before the insertion I send all my data into a temp memory table, for that reason I have increased both tmp_table_size and max_heap_table_size to 15GB.

It works well so far, but after I explicitly drop the temp table and after my connection is closed MySQL keeps using the memory allocated for the temp table and the only way I'm able to free that memory is to restart the service.

My application runs every few hours and I eventually run out of memory after 2-3 runs. Is there another way to fix this without restarting the service?

UPD: here's the structure of the temp table:

Temp table DDL

CREATE TEMPORARY TABLE ids_temp (
  AAID binary(16) NOT NULL,
  GroupID int(10) NOT NULL,
  INDEX temp_GroupID_idx (GroupID)
) ENGINE = MEMORY

Inserts into the temp table (using MySQLCursor.executemany())

INSERT INTO ids_temp (ID, GroupID) VALUES (%s, %s)

Drop statement

DROP TEMPORARY TABLE IF EXISTS ids_temp

Inserts to other tables

INSERT IGNORE INTO data.{GroupID} (`ID`)
SELECT T.ID
FROM ids_temp T WHERE T.GroupID = {GroupId}
1
  • 1
    I think it would be useful if you provided the actual commands you run to create, populate, and drop the temporary table.
    – mustaccio
    Commented Feb 9, 2023 at 19:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.