> ## 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 84144

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: July 19, 2022

## Description

The problem affects multi-region tables whose locality has been altered to [`REGIONAL BY ROW`](https://www.cockroachlabs.com/docs/v22.1/multiregion-overview#regional-by-row-tables) in clusters running versions <InternalLink version="releases" path="v22.1">v22.1.0</InternalLink> to <InternalLink version="releases" path="v22.1">v22.1.3</InternalLink>. The problem occurs when [dropping a region](https://www.cockroachlabs.com/docs/v22.1/alter-database#drop-region): the drop may proceed when instead it should have yielded an error. Any subsequent attempt at changing the locality of the table will fail with an internal error.

This can be reproduced as follows in `cockroach demo --multitenant=false --global --nodes 9 --insecure --empty`:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> CREATE DATABASE mr PRIMARY REGION "us-east1" REGIONS "us-west1";
> USE mr;
> CREATE TABLE kv(k INT PRIMARY KEY, v INT) LOCALITY REGIONAL BY TABLE IN PRIMARY REGION;
> ALTER TABLE kv SET LOCALITY REGIONAL BY ROW;
> INSERT INTO kv (crdb_region, k, v) VALUES ('us-east1', 1, 1);
> INSERT INTO kv (crdb_region, k, v) VALUES ('us-west1', 2, 2);
```

At this point the following statement should fail but instead succeeds:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> ALTER DATABASE mr DROP REGION "us-west1";
```

After which the following statement fails instead of succeeding:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> ALTER TABLE kv SET LOCALITY GLOBAL;
ERROR: failed to construct index entries during backfill: error decoding 4 bytes: could not find [128] in enum "public.crdb_internal_region" representation PhysicalReps: [[64]]; LogicalReps: [us-east1] goroutine 45657 [running]:
```

## Statement

This is resolved in CockroachDB by fixes which ensure that: back-references to tables using the [region enum](https://www.cockroachlabs.com/docs/v22.1/alter-table#crdb_region) type are correctly updated in the region enum type descriptor when performing `ALTER TABLE … SET LOCALITY REGIONAL BY ROW;` any existing type descriptors which are already missing these back-references are updated prior to `ALTER DATABASE … DROP [SUPER] REGION` so as to ensure its correct behavior.

The fix has been applied to the maintenance release of CockroachDB <InternalLink version="releases" path="v22.1">v22.1.4</InternalLink>.

## Mitigation

Users of CockroachDB v22.1.0 to v22.1.3 with multi-region databases are encouraged to upgrade to the maintenance version <InternalLink version="releases" path="v22.1">v22.1.4</InternalLink> or above.

## Impact

Versions v22.1.0 to v22.1.3 are affected. In these versions, multi-region tables whose locality has been altered to `REGIONAL BY ROW` are at risk of being corrupted.

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