Please help with following strange issue.I defined in memory table but insert of 600.000 rows takes 13 minutes and causes heavy write to disk. The CPU is underutilized and I have enough free memory. What's wrong and why I see the I/O?
1. I defined max_heap_table_size as 1GB and restarted the DB.
2. I created the table as:
CREATE TABLE `data`
(
`id` bigint(20) DEFAULT NULL,
`datetime` timestamp DEFAULT CURRENT_TIMESTAMP,
`channel` int(11) DEFAULT NULL,
`value` bigint(20) DEFAULT NULL
) ENGINE = MEMORY;
- I created the procedure to insert data.
DELIMITER $$ CREATE PROCEDURE generate_data() BEGIN DECLARE i INT DEFAULT 0; WHILE i < 600001 DO INSERT INTO `data` (`id`, `datetime`,`value`,`channel`) VALUES ( i, FROM_UNIXTIME(UNIX_TIMESTAMP('2014-01-01 01:00:00')+FLOOR(RAND()*31536000)), ROUND(RAND()*100,2), i ); SET i = i + 1; END WHILE; END$$
Best Answer
Look
SHOW PROCESSLIST
- the most time the process state is 'waiting for handler commit'.If your server version is 8 use recursive CTE instead:
If you have 5+ server, use synthetic number tables:
At the same system (server version 8.0.18):