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

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: May 11, 2023

## Description

In CockroachDB versions v22.1.19 and v22.2.8, some customers may experience spurious [privilege](https://www.cockroachlabs.com/docs/v22.2/security-reference/authorization#privileges) errors when trying to run queries due to a bug in the query cache. This can happen if two or more databases exist on the same cluster with tables that have the same name and at least one [foreign key reference](https://www.cockroachlabs.com/docs/v22.2/foreign-key). If identical queries are used to query the tables in the two different databases by users with different permissions, they may experience errors due to insufficient privileges.

## Statement

This is resolved in CockroachDB by a fix which ensures that privilege checks happen after staleness checks when attempting to use the query cache.

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

This fix will be applied to the maintenance release of CockroachDB v22.1.20.

## Mitigation

Users of CockroachDB v22.1.19 and v22.2.8 who experience spurious [privilege](https://www.cockroachlabs.com/docs/v22.2/security-reference/authorization#privileges) errors with the query cache enabled are encouraged to upgrade to v22.1.20, v22.2.9, or a later version.

If an upgrade is not possible, the issue can be avoided by updating the SQL queries to qualify table names with the database name so there is no collision in the query cache. For example, `SELECT * FROM table_name` can be rewritten using [partially qualified](https://www.cockroachlabs.com/docs/v22.2/sql-name-resolution#lookup-with-partially-qualified-names) or [fully qualified](https://www.cockroachlabs.com/docs/v22.2/sql-name-resolution#lookup-with-fully-qualified-names) names as follows:

* `SELECT * FROM database_name.table_name`
* `SELECT * FROM database_name.schema_name.table_name`

Another option, if an upgrade is not possible, is to disable the query cache with the following command:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SET CLUSTER SETTING sql.query_cache.enabled = false;
```

Disabling the query cache may degrade the performance of the cluster, however.

## Impact

Some customers running identical queries with different roles to access tables with the same name in different databases could experience spurious [privilege](https://www.cockroachlabs.com/docs/v22.2/security-reference/authorization#privileges) errors on CockroachDB v22.1.19 and v22.2.8 with the query cache enabled.

Please reach out to the [support team](https://support.cockroachlabs.com/) if more information or assistance is needed.
