简体   繁体   中英

MySQL/InnoDB Plugin: Will NULL values for VARCHAR fields still take up storage spaces?

I'm using InnoDB Plugin in the Barracuda file format with:

ROW_FORMAT=DYNAMIC

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

On a related note, if I define a field as INT then presumably every record will still use 32 bits for that field even if the value for it is NULL . Is that correct?

Thanks

I think this should answer your question -

An SQL NULL value reserves one or two bytes in the record directory. Besides that, an SQL NULL value reserves zero bytes in the data part of the record if stored in a variable length column. In a fixed-length column, it reserves the fixed length of the column in the data part of the record. Reserving the fixed space for NULL values enables an update of the column from NULL to a non-NULL value to be done in place without causing fragmentation of the index page.

Please check more on data-type storage requirements and InnoDB physical row structure

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM