> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cockroachlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Technical Advisory 99796

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

Publication date: April 17, 2023

## Description

Starting in <InternalLink version="releases" path="v22.2">CockroachDB v22.2.0</InternalLink>, the implementation for [`ALTER TABLE..ADD COLUMN`](https://www.cockroachlabs.com/docs/v22.2/alter-table#add-column) began using the new [declarative schema changer](https://www.cockroachlabs.com/docs/v22.2/online-schema-changes#declarative-schema-changer). However, this implementation introduced a bug when a specific [Data Manipulation Language (DML) schema change operation](https://developer.ibm.com/tutorials/perform-dml-operations-on-cockroachdb) occurs concurrently with an [`UPDATE`](https://www.cockroachlabs.com/docs/v22.2/update) or [`INSERT`](https://www.cockroachlabs.com/docs/v22.2/insert) command, and the schema change fails and is rolled back.

If a new [column family](https://www.cockroachlabs.com/docs/v22.2/column-families) with a single column was created using an [`ALTER TABLE..ADD COLUMN`](https://www.cockroachlabs.com/docs/v22.2/alter-table#add-column) command that was executed concurrently with an [`UPDATE`](https://www.cockroachlabs.com/docs/v22.2/update) or [`INSERT`](https://www.cockroachlabs.com/docs/v22.2/insert) command, this new column family could be written within any primary index. This only became an issue if the schema change failed and was rolled back. This bug could cause corruption in the primary index, because the primary index would still contain the new data after the added column or column family was cleaned up from the table descriptor. In this situation, the table could become inaccessible.

This vulnerability affects all of the following CockroachDB versions: v22.2.0 to v22.2.7.

## Statement

This is resolved in CockroachDB by a fix that adds validation to rollback operations to account for this situation.

The fix has been applied to maintenance releases of CockroachDB: <InternalLink version="releases" path="v22.2">v22.2.8</InternalLink>.

## Mitigation

Users of CockroachDB v22.2.0 to v22.2.7 are encouraged to upgrade to <InternalLink version="releases" path="v22.2">v22.2.8</InternalLink> or a later version.

Until such an upgrade, if you are impacted by this issue, you can temporarily disable the declarative schema changer before executing an ALTER TABLE..ADD COLUMN statement using a [session variable](https://www.cockroachlabs.com/docs/v22.2/set-vars):

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SET use_declarative_schema_changer='off'
```

To permanently disable the declarative schema changer for all users, use a [cluster setting](https://www.cockroachlabs.com/docs/v22.2/cluster-settings):

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SET CLUSTER SETTINGS sql.defaults.use_declarative_schema_changer = off
```

## Impact

After upgrading to CockroachDB <InternalLink version="releases" path="v22.2">v22.2.0</InternalLink>-<InternalLink version="releases" path="v22.2">v22.2.7</InternalLink>, a bug could cause primary index corruption when an `ALTER TABLE..ADD COLUMN` statement executes concurrently with an `UPDATE` or `INSERT` command, and the schema change fails and is rolled back.

Questions about any technical alert can be directed to our [support team](https://support.cockroachlabs.com/).
