开发者

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

开发者 https://www.devze.com 2023-03-15 21:50 出处:网络
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 st

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 byte开发者_如何转开发s 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

0

精彩评论

暂无评论...
验证码 换一张
取 消