Declare fields NOT NULL

Each time you declare a field, MySQL needs one extra bit of data to store whether or not the value is NULL. This is because NULL is not 0, or indeed any value, so the only way for MySQL to know whether a value is NULL or not is to use this special bit.

If you know for a fact that a column will not be NULL, declare it as NOT NULL - this will allow you to save the bit, and stop MySQL from checking that bit every time it checks the value. For example:

CREATE TABLE MyNotNull (ID INT NOT NULL, Name CHAR(20) NOT NULL);

 

Next chapter: Load data intelligently >>

Previous chapter: Size vs. Speed

Jump to:

 

Home: Table of Contents

Follow us on Identi.ca or Twitter

Username:   Password:
Create Account | About TuxRadar