1

I was created table and pushed 10000 rows:

//id = int(10) not null auto_increment
// test = varchar(1) 
id | test
---------
 1 |  a
 2 |  a
 3 |  a
 4 |  a
...

Was download this sql file - his weight ~ 0.1m

Then i was added a column test_2 (varchar(1))with NULL as default:

after sql file weight = +30%

null does occupy memory?

bsbak
  • 719
  • 1
  • 6
  • 18

1 Answers1

0

If the field is fixed width storing NULL takes the same space as any other value - the width of the field.

If the field is variable width the NULL value takes up no space.

In addition to the space required to store a null value there is also an overhead for having a nullable column. For each row one bit is used per nullable column to mark whether the value for that column is null or not. This is true whether the column is fixed or variable length.

Please read this SQL: Using NULL values vs. default values

Community
  • 1
  • 1
Parth Chavda
  • 1,819
  • 1
  • 23
  • 30
  • what thats mean "In addition to the space required to store"? thats mean like not varchar(100), but date, or int without values? – bsbak Nov 23 '15 at 09:56
  • to define a value,where value is null or what ever one bit is used. – Parth Chavda Nov 23 '15 at 10:01
  • for varchar null required to 1 bit but in char(4) if you define like this it means null value required 4 byte in char....because char is fixed size and varchar is variable size......so why 1 bit ? because for define a vlaue is null or what ever they must need 1 bit – Parth Chavda Nov 23 '15 at 10:11