Column Schema Change

In PostgreSQL, the adding and dropping a column is an instant ddl(This name seems only to be used in mysql, but I like it). In this article, I try to explain the implement of that.

The reference:

Basic Concepts

For the heap page representation

instant ddl

For a table with $n$ tuples, if a ddl post can be performed in time $O(1)$ ,we call this ddl instant. So to implement an instant ddl, the data organization must remain unchanged. Instead, only the schema information can be changed, along withthe method to used to interpret the table’s binary data according to the schema.

In this scenario, pg only changes the pg_attribute catalog, which records the attributes[#todo is this OK] of each relations.

heap page representation

page representation

Before illustrate the situation where interpreting the binary data with two different schemas, we figure out the way to organize the heap pages.

image-20240407223441847