This is probably related to another question I had, but not sure.
So my table url_meta
is 25 GB including data and indexes, 70 million records.
Data 18.3 GiB
Index 7.3 GiB
Overhead 5.0 MiB
Effective 25.5 GiB
Total 25.5 GiB
I wanted to change a index column url_hash
to be primary, so I ran this query:
ALTER TABLE url_meta DROP INDEX url_hash, ADD PRIMARY KEY (url_hash) USING BTREE
And it runs for 7 hours and counting, the ssd ls almost out of space and I assume query will fail.
To me it seems that it takes way to long to process 25GB
Server has 128 GB ram, 12 threads Ryzen CPU, nvme ssd.
Only options in /etc/my.cnf:
skip-log-bin
innodb_buffer_pool_size = 100G
sort_buffer_size = 1G
PhpMyAdmin says:
Many temporary tables are being written to disk instead of being kept in memory. Recommendation: Increasing max_heap_table_size and tmp_table_size might help
So these are the two variables:
tmp_table_size 16,777,216
max_heap_table_size 16,777,216
- Are the two above variables related to my slow
ALTER TABLE
queries? - If yes, what values should these two be in my situation ?
- If not these 2, what variables should I tune to make this alter tables faster ?
- What other variables should I check / edit in order to use more memory and less of the SSD ?
- Table contains a full text index that I assume it got really big, is that wahat causes my problems ?
This is the table fomat:
CREATE TABLE `url_meta` (
`url_hash` char(16) NOT NULL,
`url_sharding` char(2) DEFAULT NULL,
`url` varchar(512) NOT NULL,
`url_title` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
`url_description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
`url_keywords` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
`url_paragraphs` mediumtext,
`url_total_links_in` smallint NOT NULL DEFAULT '0' COMMENT 'max SMALLINT is 65535',
`url_meta_date` int NOT NULL DEFAULT '0',
`url_misc` tinyint DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- Indexes
ALTER TABLE `url_meta`
ADD UNIQUE KEY `url_hash` (`url_hash`),
ADD KEY `url_total_links_in` (`url_total_links_in`) USING BTREE,
ADD KEY `url_sharding` (`url_sharding`),
ADD KEY `url_misc` (`url_misc`);
ALTER TABLE `url_meta` ADD FULLTEXT KEY `url_meta_index` (`url_title`,`url_description`,`url_keywords`,`url_paragraphs`);
COMMIT;
My large files in /var/lib/mysql/db_name
ls -lhaS /var/lib/mysql/my_db/fts*
-rw-r----- 1 mysql mysql 81G Dec 24 18:24 /var/lib/mysql/my_db/fts_0000000000000961_0000000000000a57_index_1.ibd
-rw-r----- 1 mysql mysql 40G Dec 25 23:58 /var/lib/mysql/my_db/fts_0000000000000a3d_0000000000000bae_index_1.ibd
-rw-r----- 1 mysql mysql 13G Dec 23 23:06 /var/lib/mysql/my_db/fts_0000000000000961_0000000000000a57_index_6.ibd
-rw-r----- 1 mysql mysql 9.3G Dec 25 04:15 /var/lib/mysql/my_db/fts_0000000000000a31_0000000000000b9b_index_1.ibd
-rw-r----- 1 mysql mysql 6.5G Dec 22 04:30 /var/lib/mysql/my_db/fts_00000000000009ec_0000000000000b2f_index_1.ibd
-rw-r----- 1 mysql mysql 6.5G Dec 23 04:37 /var/lib/mysql/my_db/fts_0000000000000a20_0000000000000b7d_index_1.ibd
-rw-r----- 1 mysql mysql 6.4G Dec 25 23:58 /var/lib/mysql/my_db/fts_0000000000000a3d_0000000000000bae_index_6.ibd
-rw-r----- 1 mysql mysql 1.1G Dec 25 04:15 /var/lib/mysql/my_db/fts_0000000000000a31_0000000000000b9b_index_6.ibd
-rw-r----- 1 mysql mysql 844M Dec 22 04:30 /var/lib/mysql/my_db/fts_00000000000009ec_0000000000000b2f_index_6.ibd
# more smaller ones ...
My current memory usage during this long query, not sure, but maybe it has room to use more memory and write less to disk ? It shows it is swapping too, no ? I assume this is bad.
free -h
total used free shared buff/cache available
Mem: 124Gi 91Gi 804Mi 60Mi 33Gi 33Gi
Swap: 31Gi 22Gi 8.3Gi