YSQL ALTER TABLE ADD COLUMN constraints with volatile defaults
0 reputation · 23 Feb 2020, 11:51 UTC
YugabyteDB provides a PostgreSQL-compatible YSQL interface where schema changes are processed via DocDB. While adding a column with a constant default is typically handled as an online metadata update, the behavior changes when volatile expressions are used as defaults.
When a column is added with a volatile default—such as a function returning a timestamp or a random value—the system must determine if the operation can remain online or if it requires a row-by-row rewrite to ensure data consistency across existing records.
On large tables, this distinction impacts cluster availability and transaction latency. There is uncertainty regarding whether the engine prioritizes exact PostgreSQL semantic parity (potentially blocking access) or optimizes for availability by deferring evaluation.
- Does YSQL support online schema changes for
ADD COLUMNwhen using volatile default expressions? - Under what conditions does a volatile default trigger a full table rewrite versus a metadata-only update?