← Back to all stagesStage 6
Stage 6: Null Handling
Stage Objective
Add support for NULL values, nullable column definitions, and IS NULL / IS NOT NULL conditions.
Conceptual Algorithms
- Extend the
CREATE TABLEparser to acceptNULLorNOT NULLconstraints (defaulting to nullable). - Modify the serialization format. Since we have fixed-size and varlen pages,
NULLcan be represented using a null-bitmap at the start of the row header. 1 bit per column. - Update the SQL Lexer/Parser to recognize
NULLas a value literal. - Add support for
IS NULLandIS NOT NULLin theWHEREclause parser and executor logic. - Ensure aggregate functions ignore
NULLvalues correctly (exceptCOUNT(*)).
Implementation Checklist
- Add
NULL,IS,NOTtokens. - Support
IS NULLandIS NOT NULLin the AST. - Implement a null-bitmap in the tuple serialization layer.
- Update
insertlogic to handle null constraints. - Update filter logic in Sequential/Index Scans.
Expected Contract
When inserting a row missing nullable columns, it should be stored as NULL. SELECT ... WHERE col IS NULL should return the correct rows. NOT NULL constraints should raise an error when violated.