Description
In CockroachDB v21.1.x, v21.2.0 to v21.2.12, and v22.1.0, adding a column which:- is not null,
- has a volatile default expression,
- and is present in one or more secondary indexes,
b to contain different values in the primary index t_pkey and the secondary index t_b_key:
SELECT b FROM t@t_pkey and SELECT b FROM t@t_b_key, which will have different results.
Statement
This is resolved in CockroachDB by a fix that addresses the incorrect backfill logic. The fix is applied to CockroachDB maintenance version v22.1.1, and is expected to be applied to maintenance version v21.2.13.Mitigation
Users of CockroachDB v21.2.0-21.2.12 and v22.1.0 are encouraged to upgrade to v21.2.13 or v22.1.1, or to a later version. Alternatively, and re-using the earlier example:-
Drop and recreate all secondary indexes containing the added column:
-
Or, instead, add the new column and then add and backfill the default value in a separate transaction:

