I have a table with two simple columns and two mediumtext
columns that looks like this:
create table page (
id bigint auto_increment primary key,
status tinyint not null,
content mediumtext,
screenshot mediumtext
) row_format=compressed;
The table stores a web page's entire source and an encoded screenshot with the former being as large as 7mb and the latter around 5mb (but the average value for both columns is about 500kb to 2mb).
The page
table only has 50k records, which isn't much these days, but is about 20GB in size. When I tried to add a new simple column it took almost an hour:
alter table page add column comment varchar(255);
Meanwhile, when I add the same comment
column to another table with 50k records and no text
columns it happens within seconds.
Here's where I'm curious: I thought that text
columns were more like pointers to the actual data, so adding a new column should not take long because we're not touching the text
data. But given the long duration it's almost like we're restructuring the entire table, which is concerning because it'll make future DDL difficult. What might be happening in this case, and can I query for transactional, lock, or metadata to get more insight? I have innodb_file_per_table=on
.
Another curiosity is I recall adding a new column to the same big table but it was a nearly instant operation. Assuming I remembered correctly, are there certain operations that restructure the entire table vs ones that do not?