MySQL / InnoDB Plugin: Will NULL Values ​​for VARCHAR Fields Occupy Storage Space?

I am using the InnoDB plugin in Barracuda format with:

ROW_FORMAT=DYNAMIC

If I define the field as VARCHAR(255) , and then insert a record that is NULL for this field, will this record still use 255 bytes in storage for the VARCHAR field? Or there will be no lost storage space?

In the corresponding note, if I define the field as INT , then, apparently, each record will still use 32 bits for this field, even if it is NULL . It is right?

thanks

+6
source share
1 answer

I think this should answer your question -

An SQL NULL value reserves one or two bytes in the write directory. In addition, a NULL SQL value reserves zero bytes in the record data part if they are stored in a variable-length column. In a fixed-length column, it stores a fixed-length column in the record data part. Storing fixed space for NULL values ​​allows you to update a column from NULL to a non-NULL value that must be executed in place without causing fragmentation of the index page.

Details on data type requirements and physical string InnoDB structure

+6
source

Source: https://habr.com/ru/post/891458/


All Articles