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

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 12, 2022

## Description

In a multi-region database, calling [`IMPORT INTO`](https://www.cockroachlabs.com/docs/v22.1/import-into) on a [`REGIONAL BY ROW` table](https://www.cockroachlabs.com/docs/v22.1/regional-tables) could violate [`UNIQUE`](https://www.cockroachlabs.com/docs/v22.1/unique) constraints, including [`PRIMARY KEY`](https://www.cockroachlabs.com/docs/v22.1/primary-key) constraints, resulting in duplicate keys.

Affected versions: v21.2.0 to v21.2.7

## Statement

The fix was applied in the maintenance release of <InternalLink version="releases" path="v21.2">CockroachDB v21.2.8</InternalLink>.

## Mitigation

Users of CockroachDB v21.2.0 to v21.2.7 who have used [`IMPORT INTO`](https://www.cockroachlabs.com/docs/v22.1/import-into) must audit their [`REGIONAL BY ROW`](https://www.cockroachlabs.com/docs/v22.1/regional-tables) tables with `UNIQUE` constraints to ensure these tables do not contain `UNIQUE` constraint violations.

Users should also upgrade to v21.2.8 or a later version.

### v21.2.6 or later

Users of CockroachDB v21.2.6 and later have access to the following [built-in functions](https://www.cockroachlabs.com/docs/v22.1/functions-and-operators), which can be used to easily validate `UNIQUE` constraints:

* `SELECT crdb_internal.revalidate_unique_constraints_in_all_tables();`
* `SELECT crdb_internal.revalidate_unique_constraints_in_table('table_name');`
* `SELECT crdb_internal.revalidate_unique_constraint('table_name', 'constraint_name');`

If any constraint fails validation, the functions will return an error with a hint about which data caused the constraint violation. These violations can then be resolved manually by updating or deleting the rows in violation.

### Prior to v21.2.6

Users of CockroachDB releases prior to v21.2.6 may audit the table for duplicate keys by running a query of the following form, for each [`UNIQUE`](https://www.cockroachlabs.com/docs/v22.1/unique) constraint that may have been affected:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SELECT * FROM t GROUP BY unique_col1 [, unique_col2 ...] HAVING count(*) > 1;
```

If a query returns any results, this indicates that the table contains `UNIQUE` constraint violations. To fix the violations, update all but one of the duplicate keys with a different value.

## Impact

[`REGIONAL BY ROW`](https://www.cockroachlabs.com/docs/v22.1/regional-tables) tables spanning multiple regions could contain non-unique data in unique columns if [`IMPORT INTO`](https://www.cockroachlabs.com/docs/v22.1/import-into) was used to import data with duplicate keys. Versions affected include v21.2.0 to v21.2.7, v22.1.0-alpha.1 to v22.1.0-alpha.5, and v22.1.0-beta.1.

Please reach out to the [support team](https://support.cockroachlabs.com/) for more information.
