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

# Known Limitations in CockroachDB v24.1

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>;
};

## New limitations in v24.1

This section describes newly identified limitations in CockroachDB v24.1.

### PL/pgSQL

* It is not possible to use a variable as a target more than once in the same `INTO` clause. For example, `SELECT 1, 2 INTO x, x;`.
* PLpgSQL variable declarations cannot inherit the type of a table row or column using `%TYPE` or `%ROWTYPE` syntax.

### UDFs and stored procedures

* Routines cannot be invoked with named arguments, e.g., `SELECT foo(a => 1, b => 2);` or `SELECT foo(b := 1, a := 2);`.
* Routines cannot be created if they reference temporary tables.
* Routines cannot be created with unnamed `INOUT` parameters. For example, `CREATE PROCEDURE p(INOUT INT) AS $$ BEGIN NULL; END; $$ LANGUAGE PLpgSQL;`.
* Routines cannot be created if they return fewer columns than declared. For example, `CREATE FUNCTION f(OUT sum INT, INOUT a INT, INOUT b INT) LANGUAGE SQL AS $$ SELECT (a + b, b); $$;`.
* A `RECORD`-returning UDF cannot be created without a `RETURN` statement in the root block, which would restrict the wildcard type to a concrete one.

### Physical cluster replication fail back to primary cluster

When you <InternalLink path="failover-replication#failback">fail back</InternalLink> to a cluster that was previously the primary cluster, you should fail over to the `LATEST` timestamp. Using a <InternalLink path="as-of-system-time">historical timestamp</InternalLink> may lead to the failback failing.

### Generic query plans

* Because <InternalLink path="cost-based-optimizer#query-plan-cache">generic query plans</InternalLink> use lookup joins instead of the scans and revscans used by custom query plans, generic query plans do not perform as well as custom query plans in some cases.
* <InternalLink path="cost-based-optimizer#query-plan-type">Generic query plans</InternalLink> are not included in the <InternalLink path="cost-based-optimizer#query-plan-cache">plan cache</InternalLink>. This means a generic query plan built and optimized for a prepared statement in one session cannot be used by another session. To reuse generic query plans for maximum performance, a prepared statement should be executed multiple times instead of prepared and executed once.

<a id="best-practices" />

## Limitations from v23.2 and earlier

This section describes limitations from previous CockroachDB versions that still impact v24.1.

### SQL statements

#### Syntax and behavior differences from PostgreSQL

CockroachDB supports the [PostgreSQL wire protocol](https://www.postgresql.org/docs/current/protocol.html) and the majority of its syntax. For a list of known differences in syntax and behavior between CockroachDB and PostgreSQL, see <InternalLink path="postgresql-compatibility#features-that-differ-from-postgresql">Features that differ from PostgreSQL</InternalLink>.

#### `AS OF SYSTEM TIME` limitations

* CockroachDB does not support placeholders in <InternalLink path="as-of-system-time">`AS OF SYSTEM TIME`</InternalLink>. The time value must be a constant value embedded in the SQL string.
* The `ANALYZE` alias of <InternalLink path="create-statistics">`CREATE STATISTICS`</InternalLink> does not support specifying an <InternalLink path="as-of-system-time">`AS OF SYSTEM TIME`</InternalLink> timestamp. `ANALYZE` statements use `AS OF SYSTEM TIME '-0.001ms'` automatically. For more control over the statistics interval, use the `CREATE STATISTICS` syntax instead.

#### `COPY` syntax not supported by CockroachDB

CockroachDB does not yet support the following `COPY` syntax:

* `COPY ... WITH FREEZE`.
* `COPY ... WITH QUOTE`.
* `COPY ... FROM ... WHERE <expr>`.

#### `IMPORT INTO` limitations

<InternalLink path="import-into">`IMPORT INTO`</InternalLink> has the following limitations:

* While importing into an existing table, the table is taken offline.
* After importing into an existing table, <InternalLink path="constraints">constraints</InternalLink> will be un-validated and need to be <InternalLink path="alter-table#validate-constraint">re-validated</InternalLink>.
* Imported rows must not conflict with existing rows in the table or any unique secondary indexes.
* `IMPORT INTO` works for only a single existing table.
* `IMPORT INTO` can sometimes fail with a "context canceled" error, or can restart itself many times without ever finishing. If this is happening, it is likely due to a high amount of disk contention. This can be mitigated by setting the `kv.bulk_io_write.max_rate` <InternalLink path="cluster-settings">cluster setting</InternalLink> to a value below your max disk write speed. For example, to set it to 10MB/s, execute:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  SET CLUSTER SETTING kv.bulk_io_write.max_rate = '10MB';
  ```

#### `ALTER VIEW` limitations

`ALTER VIEW` does not currently support:

* Changing the <InternalLink path="select-clause">`SELECT`</InternalLink> statement executed by a view. Instead, you must drop the existing view and create a new view.
* Renaming a view that other views depend on. This feature may be added in the future.

#### Row-Level TTL limitations

* Any queries you run against tables with Row-Level TTL enabled (or against tables that have <InternalLink path="foreign-key">foreign keys</InternalLink> that reference TTL-enabled tables) do not filter out expired rows from the result set (this includes <InternalLink path="update">`UPDATE`s</InternalLink> and <InternalLink path="delete">`DELETE`s</InternalLink>). This feature may be added in a future release. For now, follow the instructions in <InternalLink path="row-level-ttl#filter-out-expired-rows-from-a-selection-query">Filter out expired rows from a selection query</InternalLink>.
* Tables with Row-Level TTL can be referenced by <InternalLink path="foreign-key">foreign keys</InternalLink>. TTL deletes are issued as regular <InternalLink path="delete">`DELETE`</InternalLink> statements, so inbound foreign keys apply. If an inbound foreign key uses `ON DELETE RESTRICT` and referencing rows exist, the TTL job fails with a foreign key violation.
* Enabling Row-Level TTL on a table with multiple <InternalLink path="indexes">secondary indexes</InternalLink> can have negative performance impacts on a cluster, including increased <InternalLink path="common-issues-to-monitor#service-latency">latency</InternalLink> and <InternalLink path="performance-best-practices-overview#transaction-contention">contention</InternalLink>. This is particularly true for large tables with terabytes of data and billions of rows that are split up into multiple ranges across separate nodes.
  * Increased latency may occur because secondary indexes aren't necessarily stored on the same underlying <InternalLink path="architecture/overview">ranges</InternalLink> as a table's <InternalLink path="indexes">primary indexes</InternalLink>. Further, the secondary indexes' ranges may have <InternalLink path="architecture/overview">leaseholders</InternalLink> located on different nodes than the primary index.
  * Increased contention may occur because <InternalLink path="architecture/transaction-layer#write-intents">intents</InternalLink> must be written as part of performing the deletions.
  * Finally, secondary indexes can also have a negative impact on the overall performance of <InternalLink path="row-level-ttl#view-running-ttl-jobs">TTL jobs</InternalLink>. According to internal testing, the <InternalLink path="ui-ttl-dashboard#processing-rate">TTL job processing rate</InternalLink> is worse on tables with secondary indexes. If you encounter this situation, decreasing the <InternalLink path="row-level-ttl">`ttl_delete_batch_size` storage parameter</InternalLink> may help by decreasing the number of ranges that need to be accessed by the job.

#### `CAST` expressions containing a subquery with an `ENUM` target are not supported

Casting subqueries to ENUMs in views and UDFs is not supported.

#### Statements containing multiple modification subqueries of the same table are disallowed

Statements containing multiple modification subqueries mutating the same row could cause corruption. These statements are disallowed by default, but you can enable multiple modification subqueries with one the following:

* Set the `sql.multiple_modifications_of_table.enabled` <InternalLink path="cluster-settings">cluster setting</InternalLink> to `true`.
* Use the `enable_multiple_modifications_of_table` <InternalLink path="set-vars">session variable</InternalLink>.

If multiple mutations inside the same statement affect different tables with <InternalLink path="foreign-key">`FOREIGN KEY`</InternalLink> relations and `ON CASCADE` clauses between them, the results will be different from what is expected in PostgreSQL.

#### Using `default_int_size` session variable in batch of statements

When setting the `default_int_size` <InternalLink path="set-vars">session variable</InternalLink> in a batch of statements such as `SET default_int_size='int4'; SELECT 1::IN`, the `default_int_size` variable will not take effect until the next statement. Statement parsing is asynchronous with statement execution.

As a workaround, set `default_int_size` via your database driver, or ensure that `SET default_int_size` is in its own statement.

#### Overload resolution for collated strings

Many string operations are not properly overloaded for <InternalLink path="collate">collated strings</InternalLink>, for example:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SELECT 'string1' || 'string2';
```

```
?column?
------------------
  string1string2
(1 row)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SELECT ('string1' collate en) || ('string2' collate en);
```

```
pq: unsupported binary operator: <collatedstring{en} || <collatedstring{en}
```

#### Current sequence value not checked when updating min/max value

Altering the minimum or maximum value of a series does not check the current value of a series. This means that it is possible to silently set the maximum to a value less than, or a minimum value greater than, the current value.

#### `null_ordered_last` does not produce correct results with tuples

By default, CockroachDB orders `NULL`s before all other values. For compatibility with PostgreSQL, the `null_ordered_last` <InternalLink path="set-vars">session variable</InternalLink> was added, which changes the default to order `NULL` values after all other values. This works in most cases, due to some transformations CockroachDB makes in the optimizer to add extra ordering columns. However, it does not work when the ordering column is a tuple.

### Functions and procedures

#### PL/pgSQL support

* PL/pgSQL arguments cannot be referenced with ordinals (e.g., `$1`, `$2`).
* The following statements are not supported:
  * `FOR` loops, including `FOR` cursor loops, `FOR` query loops, and `FOREACH` loops.
  * `RETURN NEXT` and `RETURN QUERY`.
  * `PERFORM`, `EXECUTE`, `GET DIAGNOSTICS`, and `CASE`.
* PL/pgSQL exception blocks cannot catch <InternalLink path="transaction-retry-error-reference">transaction retry errors</InternalLink>.
* `RAISE` statements cannot be annotated with names of schema objects related to the error (i.e., using `COLUMN`, `CONSTRAINT`, `DATATYPE`, `TABLE`, or `SCHEMA`).
* `RAISE` statements message the client directly, and do not produce log output.
* `ASSERT` debugging checks are not supported.
* `RECORD` parameters and variables are not supported in <InternalLink path="user-defined-functions">user-defined functions</InternalLink>.
* Variable shadowing (e.g., declaring a variable with the same name in an inner block) is not supported in PL/pgSQL.
* Syntax for accessing members of composite types without parentheses is not supported.
* `NOT NULL` variable declarations are not supported.
* Cursors opened in PL/pgSQL execute their queries on opening, affecting performance and resource usage.
* Cursors in PL/pgSQL cannot be declared with arguments.
* `OPEN FOR EXECUTE` is not supported for opening cursors.
* The `print_strict_params` option is not supported in PL/pgSQL.
* The `FOUND` local variable, which checks whether a statement affected any rows, is not supported in PL/pgSQL.
* By default, when a PL/pgSQL variable conflicts with a column name, CockroachDB resolves the ambiguity by treating it as a column reference rather than a variable reference. This behavior differs from PostgreSQL, where an ambiguous column error is reported, and it is possible to change the `plpgsql.variable_conflict` setting in order to prefer either columns or variables.
* It is not possible to define a `RECORD`-returning PL/pgSQL function that returns different-typed expressions from different `RETURN` statements. CockroachDB requires a consistent return type for `RECORD`-returning functions.
* Variables cannot be declared with an associated collation using the `COLLATE` keyword.
* Variables cannot be accessed using the `label.var_name` pattern.

#### UDF and stored procedure support

* Routines cannot be created with an `OUT` parameter of type `RECORD`.

* DDL statements (e.g., `CREATE TABLE`, `CREATE INDEX`) are not allowed within UDFs or stored procedures.

* Polymorphic types cannot be cast to other types (e.g., `TEXT`) within routine parameters.

* `COMMIT` and `ROLLBACK` statements are not supported within nested procedures.

* User-defined functions are not currently supported in:

  * Expressions (column, index, constraint) in tables.
  * Views.

* User-defined functions cannot call themselves recursively.

* <InternalLink path="common-table-expressions">Common table expressions</InternalLink> (CTE), recursive or non-recursive, are not supported in <InternalLink path="user-defined-functions">user-defined functions</InternalLink> (UDF). That is, you cannot use a `WITH` clause in the body of a UDF.

* The `setval` function cannot be resolved when used inside UDF bodies.

* Casting subqueries to <InternalLink path="create-type">user-defined types</InternalLink> in UDFs is not supported.

### Transactions

#### Read Committed features and performance

<InternalLink path="read-committed">Read Committed isolation</InternalLink> has the following limitations:

* Schema changes (e.g., <InternalLink path="create-table">`CREATE TABLE`</InternalLink>, <InternalLink path="create-schema">`CREATE SCHEMA`</InternalLink>, <InternalLink path="create-index">`CREATE INDEX`</InternalLink>) cannot be performed within explicit `READ COMMITTED` transactions, and will cause transactions to abort. As a workaround, <InternalLink path="read-committed#set-the-current-transaction-to-read-committed">set the transaction's isolation level</InternalLink> to `SERIALIZABLE`.
* `READ COMMITTED` transactions performing `INSERT`, `UPDATE`, or `UPSERT` cannot access <InternalLink path="table-localities#regional-by-row-tables">`REGIONAL BY ROW`</InternalLink> tables in which <InternalLink path="unique">`UNIQUE`</InternalLink> and <InternalLink path="primary-key">`PRIMARY KEY`</InternalLink> constraints exist, the region is not included in the constraint, and the region cannot be computed from the constraint columns.
* Multi-column-family checks during updates are not supported under `READ COMMITTED` isolation.
* Because locks acquired by <InternalLink path="foreign-key">foreign key</InternalLink> checks, <InternalLink path="select-for-update">`SELECT FOR UPDATE`</InternalLink>, and <InternalLink path="select-for-update">`SELECT FOR SHARE`</InternalLink> are fully replicated under `READ COMMITTED` isolation, some queries experience a delay for Raft replication.
* <InternalLink path="foreign-key">Foreign key</InternalLink> checks are not performed in parallel under `READ COMMITTED` isolation.
* <InternalLink path="select-for-update">`SELECT FOR UPDATE` and `SELECT FOR SHARE`</InternalLink> statements are less optimized under `READ COMMITTED` isolation than under `SERIALIZABLE` isolation. Under `READ COMMITTED` isolation, `SELECT FOR UPDATE` and `SELECT FOR SHARE` usually perform an extra lookup join for every locked table when compared to the same queries under `SERIALIZABLE`. In addition, some optimization steps (such as de-correlation of correlated <InternalLink path="subqueries">subqueries</InternalLink>) are not currently performed on these queries.
* Regardless of isolation level, <InternalLink path="select-for-update">`SELECT FOR UPDATE` and `SELECT FOR SHARE`</InternalLink> statements in CockroachDB do not prevent insertion of new rows matching the search condition (i.e., <InternalLink path="read-committed#non-repeatable-reads-and-phantom-reads">phantom reads</InternalLink>). This matches PostgreSQL behavior at all isolation levels.

#### Follower reads

<a id="exact-staleness-reads-and-long-running-writes" />

##### Exact staleness reads and long-running writes

Long-running write transactions will create <InternalLink path="architecture/transaction-layer#write-intents">write intents</InternalLink> with a timestamp near when the transaction began. When an exact staleness follower read encounters a write intent, it will often end up in a <InternalLink path="architecture/transaction-layer#txnwaitqueue">"transaction wait queue"</InternalLink>, waiting for the operation to complete; however, this runs counter to the benefit exact staleness reads provide.

To counteract this, you can issue all follower reads in explicit <InternalLink path="transactions#transaction-priorities">transactions set with `HIGH` priority</InternalLink>:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
BEGIN PRIORITY HIGH AS OF SYSTEM TIME follower_read_timestamp();
SELECT ...
SELECT ...
COMMIT;
```

<a id="exact-staleness-read-timestamps-must-be-far-enough-in-the-past" />

##### Exact staleness read timestamps must be far enough in the past

If an exact staleness read is not using an <InternalLink path="as-of-system-time">`AS OF SYSTEM TIME`</InternalLink> value far enough in the past, CockroachDB cannot perform a follower read. Instead, the read must access the <InternalLink path="architecture/overview">leaseholder replica</InternalLink>. This adds network latency if the leaseholder is not the closest replica to the gateway node. Most users will <InternalLink path="follower-reads#run-queries-that-use-exact-staleness-follower-reads">use the `follower_read_timestamp()` function</InternalLink> to get a timestamp far enough in the past that there is a high probability of getting a follower read.

<a id="bounded-staleness-read-limitations" />

##### Bounded staleness read limitations

Bounded staleness reads have the following limitations:

* They must be used in a <InternalLink path="transactions#individual-statements">single-statement (aka implicit) transaction</InternalLink>.
* They must read from a single row.
* They must not require an <InternalLink path="indexes">index</InternalLink> <InternalLink path="joins">join</InternalLink>. In other words, the index used by the read query must be either a <InternalLink path="primary-key">primary</InternalLink> <InternalLink path="indexes">index</InternalLink>, or some other index that covers the entire query by <InternalLink path="create-index#store-columns">`STORING`</InternalLink> all columns.

For example, let's look at a read query that cannot be served as a bounded staleness read. We will use a <InternalLink path="cockroach-demo">demo cluster</InternalLink>, which automatically loads the <InternalLink path="movr">MovR dataset</InternalLink>.

```bash theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
cockroach demo
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SELECT code FROM promo_codes AS OF SYSTEM TIME with_max_staleness('10s') LIMIT 1;
ERROR: unimplemented: cannot use bounded staleness for queries that may touch more than one row or require an index join
SQLSTATE: 0A000
HINT: You have attempted to use a feature that is not yet implemented.
See: https://go.crdb.dev/issue-v/67562/v23.2
```

As noted by the error message, this query cannot be served as a bounded staleness read because in this case it would touch more than one row. Even though we used a <InternalLink path="limit-offset">`LIMIT 1` clause</InternalLink>, the query would still have to touch more than one row in order to filter out the additional results.

We can verify that more than one row would be touched by issuing <InternalLink path="explain">`EXPLAIN`</InternalLink> on the same query, but without the <InternalLink path="as-of-system-time">`AS OF SYSTEM TIME`</InternalLink> clause:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
EXPLAIN SELECT code FROM promo_codes LIMIT 5;
```

```
info
-------------------------------------------------------------------------------
  distribution: full
  vectorized: true

  • scan
    estimated row count: 1 (0.10% of the table; stats collected 1 minute ago)
    table: promo_codes@primary
    spans: LIMITED SCAN
    limit: 1
(8 rows)
```

The output verifies that this query performs a scan of the primary <InternalLink path="indexes">index</InternalLink> on the `promo_codes` table, which is why it cannot be used for a bounded staleness read.

For an example showing how to successfully perform a bounded staleness read, see <InternalLink path="follower-reads#run-queries-that-use-bounded-staleness-follower-reads">Run queries that use bounded staleness follower reads</InternalLink>.

#### `SELECT FOR UPDATE` locks are dropped on lease transfers and range splits/merges

* `SKIP LOCKED` cannot be used for tables with multiple <InternalLink path="column-families">column families</InternalLink>.
* By default under `SERIALIZABLE` isolation, locks acquired using `SELECT ... FOR UPDATE` and `SELECT ... FOR SHARE` are implemented as fast, in-memory <InternalLink path="architecture/transaction-layer">unreplicated locks</InternalLink>. If a <InternalLink path="architecture/replication-layer#epoch-based-leases-table-data">lease transfer</InternalLink> or <InternalLink path="architecture/distribution-layer#range-merges">range split/merge</InternalLink> occurs on a range held by an unreplicated lock, the lock is dropped. The following behaviors can occur:

  * The desired ordering of concurrent accesses to one or more rows of a table expressed by your use of `SELECT ... FOR UPDATE` may not be preserved (that is, a transaction *B* against some table *T* that was supposed to wait behind another transaction *A* operating on *T* may not wait for transaction *A*).
  * The transaction that acquired the (now dropped) unreplicated lock may fail to commit, leading to <InternalLink path="transaction-retry-error-reference">transaction retry errors with code `40001`</InternalLink> and the <InternalLink path="common-errors#restart-transaction">`restart transaction` error message</InternalLink>.

  When running under `SERIALIZABLE` isolation, `SELECT ... FOR UPDATE` and `SELECT ... FOR SHARE` locks should be thought of as best-effort, and should not be relied upon for correctness. Note that <InternalLink path="demo-serializable">serialization</InternalLink> is preserved despite this limitation. This limitation is fixed when the `enable_durable_locking_for_serializable` <InternalLink path="session-variables">session setting</InternalLink> is set to `true`. This limitation does **not** apply to <InternalLink path="read-committed">`READ COMMITTED`</InternalLink> transactions.

#### `SET` does not `ROLLBACK` in a transaction

<InternalLink path="set-vars">`SET`</InternalLink> does not properly apply <InternalLink path="rollback-transaction">`ROLLBACK`</InternalLink> within a transaction. For example, in the following transaction, showing the `TIME ZONE` <InternalLink path="set-vars#supported-variables">variable</InternalLink> does not return `2` as expected after the rollback:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SET TIME ZONE +2;
BEGIN;
SET TIME ZONE +3;
ROLLBACK;
SHOW TIME ZONE;
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
timezone
------------
3
```

#### `ROLLBACK TO SAVEPOINT` in high-priority transactions containing DDL

1 Transactions with <InternalLink path="transactions#transaction-priorities">priority `HIGH`</InternalLink> that contain DDL and `ROLLBACK TO SAVEPOINT` are not supported, as they could result in a deadlock. For example:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> BEGIN PRIORITY HIGH; SAVEPOINT s; CREATE TABLE t(x INT); ROLLBACK TO SAVEPOINT s;
```

```
ERROR: unimplemented: cannot use ROLLBACK TO SAVEPOINT in a HIGH PRIORITY transaction containing DDL
SQLSTATE: 0A000
HINT: You have attempted to use a feature that is not yet implemented.
```

#### `CANCEL JOB` limitations

* To avoid transaction states that cannot properly <InternalLink path="rollback-transaction">roll back</InternalLink>, the following statements cannot be cancelled with <InternalLink path="cancel-job">`CANCEL JOB`</InternalLink>:

  * `DROP` statements (e.g., <InternalLink path="drop-table">`DROP TABLE`</InternalLink>).
  * `ALTER ... RENAME` statements (e.g., <InternalLink path="alter-table#rename-to">`ALTER TABLE ... RENAME TO`</InternalLink>).
  * <InternalLink path="create-table-as">`CREATE TABLE ... AS`</InternalLink> statements.
  * <InternalLink path="alter-type">`ALTER TYPE`</InternalLink> statements, except for those that drop values.
* When an Enterprise <InternalLink path="restore">`RESTORE`</InternalLink> is canceled, partially restored data is properly cleaned up. This can have a minor, temporary impact on cluster performance.

#### SQL cursor support

CockroachDB implements SQL <InternalLink path="cursors">cursor</InternalLink> support with the following limitations:

* `DECLARE` only supports forward cursors. Reverse cursors created with `DECLARE SCROLL` are not supported.

* `FETCH` supports forward, relative, and absolute variants, but only for forward cursors.

* `BINARY CURSOR`, which returns data in the Postgres binary format, is not supported.

* `WITH HOLD`, which allows keeping a cursor open for longer than a transaction by writing its results into a buffer, is accepted as valid syntax within a single transaction but is not supported. It acts as a no-op and does not actually perform the function of `WITH HOLD`, which is to make the cursor live outside its parent transaction. Instead, if you are using `WITH HOLD`, you will be forced to close that cursor within the transaction it was created in.

  * This syntax is accepted (but does not have any effect):

    ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
    BEGIN;
    DECLARE test_cur CURSOR WITH HOLD FOR SELECT * FROM foo ORDER BY bar;
    CLOSE test_cur;
    COMMIT;
    ```

  * This syntax is not accepted, and will result in an error:

    ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
    BEGIN;
    DECLARE test_cur CURSOR WITH HOLD FOR SELECT * FROM foo ORDER BY bar;
    COMMIT; -- This will fail with an error because CLOSE test_cur was not called inside the transaction.
    ```

* Scrollable cursor (also known as reverse `FETCH`) is not supported.

* <InternalLink path="select-for-update">`SELECT ... FOR UPDATE`</InternalLink> with a cursor is not supported.

* Respect for <InternalLink path="savepoint">`SAVEPOINT`s</InternalLink> is not supported. Cursor definitions do not disappear properly if rolled back to a `SAVEPOINT` from before they were created.

#### Materialized views inside transactions

* CockroachDB cannot refresh <InternalLink path="views#materialized-views">materialized views</InternalLink> inside <InternalLink path="begin-transaction">explicit transactions</InternalLink>. Trying to refresh a materialized view inside an explicit transaction will result in an error.

  1. Start <InternalLink path="cockroach-demo">`cockroach demo`</InternalLink> with the sample `bank` data set:

     ```bash theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
     cockroach demo bank
     ```

  2. Create the materialized view described in <InternalLink path="views#usage">Usage</InternalLink>.

  3. Start a new multi-statement transaction with <InternalLink path="begin-transaction">`BEGIN TRANSACTION`</InternalLink>:

     ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
     BEGIN TRANSACTION;
     ```

  4. Inside the open transaction, attempt to <InternalLink path="refresh">refresh the view</InternalLink>. This will result in an error.

     ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
     REFRESH MATERIALIZED VIEW overdrawn_accounts;
     ```

     ```
     ERROR: cannot refresh view in an explicit transaction
       SQLSTATE: 25000
     ```

### Schemas and indexes

#### Online schema change limitations

<a id="schema-changes-within-transactions" />

##### Schema changes within transactions

Most schema changes should not be performed within an explicit transaction with multiple statements, as they do not have the same atomicity guarantees as other SQL statements. Execute schema changes either as single statements (as an implicit transaction), or in an explicit transaction consisting of the single schema change statement. There are some exceptions to this, detailed below.

Schema changes keep your data consistent at all times, but they do not run inside \[transactions]\[txns] in the general case. Making schema changes transactional would mean requiring a given schema change to propagate across all the nodes of a cluster. This would block all user-initiated transactions being run by your application, since the schema change would have to commit before any other transactions could make progress. This would prevent the cluster from servicing reads and writes during the schema change, requiring application downtime.

<Tip>
  New in v24.1: Some tools and applications may be able to workaround CockroachDB's lack of transactional schema changes by <InternalLink path="online-schema-changes#enable-automatic-commit-before-running-schema-changes-inside-transactions">enabling a setting that automatically commits before running schema changes inside transactions</InternalLink>.
</Tip>

Some schema change operations can be run within explicit, multiple statement transactions. `CREATE TABLE` and `CREATE INDEX` statements can be run within the same transaction with the same atomicity guarantees as other SQL statements. There are no performance or rollback issues when using these statements within a multiple statement transaction.

Within a single <InternalLink path="transactions">transaction</InternalLink>:

* You can run schema changes inside the same transaction as a <InternalLink path="create-table">`CREATE TABLE`</InternalLink> statement. For more information, see <InternalLink path="online-schema-changes#run-schema-changes-inside-a-transaction-with-create-table">Run schema changes inside a transaction with `CREATE TABLE`</InternalLink>. However, a `CREATE TABLE` statement containing <InternalLink path="foreign-key">`FOREIGN KEY`</InternalLink> clauses cannot be followed by statements that reference the new table.
* [Schema change DDL statements inside a multi-statement transaction can fail while other statements succeed](#schema-change-ddl-statements-inside-a-multi-statement-transaction-can-fail-while-other-statements-succeed).
* <InternalLink path="alter-table#drop-column">`DROP COLUMN`</InternalLink> can result in data loss if one of the other schema changes in the transaction fails or is canceled. To work around this, move the `DROP COLUMN` statement to its own explicit transaction or run it in a single statement outside the existing transaction.

If a schema change within a transaction fails, manual intervention may be needed to determine which statement has failed. After determining which schema change(s) failed, you can then retry the schema change.

<a id="schema-change-ddl-statements-inside-a-multi-statement-transaction-can-fail-while-other-statements-succeed-2" />

##### Schema change DDL statements inside a multi-statement transaction can fail while other statements succeed

Most schema change [DDL](https://wikipedia.org/wiki/Data_definition_language#ALTER_statement) statements that run inside a multi-statement transaction with non-DDL statements can fail at <InternalLink path="commit-transaction">`COMMIT`</InternalLink> time, even if other statements in the transaction succeed. This leaves such transactions in a "partially committed, partially aborted" state that may require manual intervention to determine whether the DDL statements succeeded.

Some DDL statements do not have this limitation. `CREATE TABLE` and `CREATE INDEX` statements have the same atomicity guarantees as other statements within a transaction.

If such a failure occurs, CockroachDB will emit a CockroachDB-specific error code, `XXA00`, and the following error message:

```
transaction committed but schema change aborted with error: <description of error>
HINT: Some of the non-DDL statements may have committed successfully, but some of the DDL statement(s) failed.
Manual inspection may be required to determine the actual state of the database.
```

<Danger>
  <Danger>
    If you must execute schema change DDL statements inside a multi-statement transaction, we **strongly recommend** checking for this error code and handling it appropriately every time you execute such transactions.
  </Danger>
</Danger>

This error will occur in various scenarios, including but not limited to:

* Creating a unique index fails because values aren't unique.
* The evaluation of a computed value fails.
* Adding a constraint (or a column with a constraint) fails because the constraint is violated for the default/computed values in the column.

To see an example of this error, start by creating the following table.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
CREATE TABLE T(x INT);
INSERT INTO T(x) VALUES (1), (2), (3);
```

Then, enter the following multi-statement transaction, which will trigger the error.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
BEGIN;
ALTER TABLE t ADD CONSTRAINT unique_x UNIQUE(x);
INSERT INTO T(x) VALUES (3);
COMMIT;
```

```
pq: transaction committed but schema change aborted with error: (23505): duplicate key value (x)=(3) violates unique constraint "unique_x"
HINT: Some of the non-DDL statements may have committed successfully, but some of the DDL statement(s) failed.
Manual inspection may be required to determine the actual state of the database.
```

In this example, the <InternalLink path="insert">`INSERT`</InternalLink> statement committed, but the <InternalLink path="alter-table">`ALTER TABLE`</InternalLink> statement adding a <InternalLink path="unique">`UNIQUE` constraint</InternalLink> failed. We can verify this by looking at the data in table `t` and seeing that the additional non-unique value `3` was successfully inserted.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SELECT * FROM t;
```

```
x
+---+
  1
  2
  3
  3
(4 rows)
```

<a id="no-online-schema-changes-if-primary-key-change-in-progress" />

##### No online schema changes if primary key change in progress

You cannot start an online schema change on a table if a <InternalLink path="alter-table#alter-primary-key">primary key change</InternalLink> is currently in progress on the same table.

<a id="no-online-schema-changes-between-executions-of-prepared-statements" />

##### No online schema changes between executions of prepared statements

When the schema of a table targeted by a prepared statement changes after the prepared statement is created, future executions of the prepared statement could result in an error. For example, adding a column to a table referenced in a prepared statement with a `SELECT *` clause will result in an error:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
CREATE TABLE users (id INT PRIMARY KEY);
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
PREPARE prep1 AS SELECT * FROM users;
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
ALTER TABLE users ADD COLUMN name STRING;
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
INSERT INTO users VALUES (1, 'Max Roach');
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
EXECUTE prep1;
```

```
ERROR: cached plan must not change result type
SQLSTATE: 0A000
```

It's therefore recommended to explicitly list result columns instead of using `SELECT *` in prepared statements, when possible.

#### Adding a column with sequence-based `DEFAULT` values

It is currently not possible to <InternalLink path="alter-table#add-column">add a column</InternalLink> to a table when the column uses a <InternalLink path="create-sequence">sequence</InternalLink> as the <InternalLink path="default-value">`DEFAULT`</InternalLink> value, for example:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> CREATE TABLE t (x INT);
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> INSERT INTO t(x) VALUES (1), (2), (3);
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> CREATE SEQUENCE s;
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> ALTER TABLE t ADD COLUMN y INT DEFAULT nextval('s');
```

```
ERROR: failed to construct index entries during backfill: nextval(): unimplemented: cannot evaluate scalar expressions containing sequence operations in this context
SQLSTATE: 0A000
HINT: You have attempted to use a feature that is not yet implemented.
See: https://go.crdb.dev/issue-v/42508/v24.1
```

#### Dropping a column referenced by a partial index

CockroachDB prevents a column from being dropped using <InternalLink path="alter-table#drop-column">`ALTER TABLE ... DROP COLUMN`</InternalLink> if it is referenced by a partial index predicate. To drop such a column, the partial indexes need to be dropped first using <InternalLink path="drop-index">`DROP INDEX`</InternalLink>.

#### Schema change DDL statements inside a multi-statement transaction can fail while other statements succeed

Most schema change [DDL](https://wikipedia.org/wiki/Data_definition_language#ALTER_statement) statements that run inside a multi-statement transaction with non-DDL statements can fail at <InternalLink path="commit-transaction">`COMMIT`</InternalLink> time, even if other statements in the transaction succeed. This leaves such transactions in a "partially committed, partially aborted" state that may require manual intervention to determine whether the DDL statements succeeded.

Some DDL statements do not have this limitation. `CREATE TABLE` and `CREATE INDEX` statements have the same atomicity guarantees as other statements within a transaction.

If such a failure occurs, CockroachDB will emit a CockroachDB-specific error code, `XXA00`, and the following error message:

```
transaction committed but schema change aborted with error: <description of error>
HINT: Some of the non-DDL statements may have committed successfully, but some of the DDL statement(s) failed.
Manual inspection may be required to determine the actual state of the database.
```

<Danger>
  If you must execute schema change DDL statements inside a multi-statement transaction, we **strongly recommend** checking for this error code and handling it appropriately every time you execute such transactions.
</Danger>

This error will occur in various scenarios, including but not limited to:

* Creating a unique index fails because values aren't unique.
* The evaluation of a computed value fails.
* Adding a constraint (or a column with a constraint) fails because the constraint is violated for the default/computed values in the column.

To see an example of this error, start by creating the following table.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
CREATE TABLE T(x INT);
INSERT INTO T(x) VALUES (1), (2), (3);
```

Then, enter the following multi-statement transaction, which will trigger the error.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
BEGIN;
ALTER TABLE t ADD CONSTRAINT unique_x UNIQUE(x);
INSERT INTO T(x) VALUES (3);
COMMIT;
```

```
pq: transaction committed but schema change aborted with error: (23505): duplicate key value (x)=(3) violates unique constraint "unique_x"
HINT: Some of the non-DDL statements may have committed successfully, but some of the DDL statement(s) failed.
Manual inspection may be required to determine the actual state of the database.
```

In this example, the <InternalLink path="insert">`INSERT`</InternalLink> statement committed, but the <InternalLink path="alter-table">`ALTER TABLE`</InternalLink> statement adding a <InternalLink path="unique">`UNIQUE` constraint</InternalLink> failed. We can verify this by looking at the data in table `t` and seeing that the additional non-unique value `3` was successfully inserted.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SELECT * FROM t;
```

```
x
+---+
  1
  2
  3
  3
(4 rows)
```

#### Schema changes between executions of prepared statements

When the schema of a table targeted by a prepared statement changes after the prepared statement is created, future executions of the prepared statement could result in an error. For example, adding a column to a table referenced in a prepared statement with a `SELECT *` clause will result in an error:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
CREATE TABLE users (id INT PRIMARY KEY);
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
PREPARE prep1 AS SELECT * FROM users;
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
ALTER TABLE users ADD COLUMN name STRING;
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
INSERT INTO users VALUES (1, 'Max Roach');
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
EXECUTE prep1;
```

```
ERROR: cached plan must not change result type
SQLSTATE: 0A000
```

It's therefore recommended to explicitly list result columns instead of using `SELECT *` in prepared statements, when possible.

#### New values generated by `DEFAULT` expressions during `ALTER TABLE ADD COLUMN`

When executing an <InternalLink path="alter-table#add-column">`ALTER TABLE ADD COLUMN`</InternalLink> statement with a <InternalLink path="default-value">`DEFAULT`</InternalLink> expression, new values generated:

* use the default <InternalLink path="sql-name-resolution#search-path">search path</InternalLink> regardless of the search path configured in the current session via `SET SEARCH_PATH`.
* use the UTC time zone regardless of the time zone configured in the current session via <InternalLink path="set-vars">`SET TIME ZONE`</InternalLink>.
* have no default database regardless of the default database configured in the current session via <InternalLink path="set-vars">`SET DATABASE`</InternalLink>, so you must specify the database of any tables they reference.
* use the transaction timestamp for the `statement_timestamp()` function regardless of the time at which the `ALTER` statement was issued.

#### Some column-dropping schema changes do not roll back properly

Some <InternalLink path="online-schema-changes">schema changes</InternalLink> that <InternalLink path="alter-table#drop-column">drop columns</InternalLink> cannot be <InternalLink path="rollback-transaction">rolled back</InternalLink> properly.

In some cases, the rollback will succeed, but the column data might be partially or totally missing, or stale due to the asynchronous nature of the schema change.

In other cases, the rollback will fail in such a way that will never be cleaned up properly, leaving the table descriptor in a state where no other schema changes can be run successfully.

To reduce the chance that a column drop will roll back incorrectly:

* Perform column drops in transactions separate from other schema changes. This ensures that other schema change failures will not cause the column drop to be rolled back.

* Drop all <InternalLink path="constraints">constraints</InternalLink> (including <InternalLink path="unique">unique indexes</InternalLink>) on the column in a separate transaction, before dropping the column.

* Drop any <InternalLink path="default-value">default values</InternalLink> or <InternalLink path="computed-columns">computed expressions</InternalLink> on a column before attempting to drop the column. This prevents conflicts between constraints and default/computed values during a column drop rollback.

If you think a rollback of a column-dropping schema change has occurred, check the <InternalLink path="show-jobs">jobs table</InternalLink>. Schema changes with an error prefaced by `cannot be reverted, manual cleanup may be required` might require manual intervention.

#### `ALTER COLUMN` limitations

You cannot alter the data type of a column if:

* The column is part of an <InternalLink path="indexes">index</InternalLink>.
* The column has <InternalLink path="check">`CHECK` constraints</InternalLink>.
* The column owns a <InternalLink path="create-sequence">sequence</InternalLink>.
* The column has a <InternalLink path="default-value">`DEFAULT` expression</InternalLink>. This will result in an `ERROR: ... column ... cannot also have a DEFAULT expression` with `SQLSTATE: 42P16`.
* The `ALTER COLUMN TYPE` statement is part of a combined `ALTER TABLE` statement.
* The `ALTER COLUMN TYPE` statement is inside an <InternalLink path="begin-transaction">explicit transaction</InternalLink>.

<Note>
  Most `ALTER COLUMN TYPE` changes are finalized asynchronously. Schema changes on the table with the altered column may be restricted, and writes to the altered column may be rejected until the schema change is finalized.
</Note>

#### `CREATE TABLE AS` limitations

The <InternalLink path="primary-key">primary key</InternalLink> of tables created with `CREATE TABLE ... AS` is not automatically derived from the query results. You must specify new primary keys at table creation. For examples, see <InternalLink path="create-table-as#specify-a-primary-key">Specify a primary key</InternalLink>.

#### Remove a `UNIQUE` index created as part of `CREATE TABLE`

<InternalLink path="create-index">`UNIQUE` indexes</InternalLink> created as part of a <InternalLink path="create-table">`CREATE TABLE`</InternalLink> statement cannot be removed without using <InternalLink path="drop-index#remove-an-index-and-dependent-objects-with-cascade">`CASCADE`</InternalLink>. Unique indexes created with <InternalLink path="create-index">`CREATE INDEX`</InternalLink> do not have this limitation.

#### Max size of a single column family

When creating or updating a row, if the combined size of all values in a single <InternalLink path="column-families">column family</InternalLink> exceeds the <InternalLink path="configure-replication-zones">max range size</InternalLink> for the table, the operation may fail, or cluster performance may suffer.

As a workaround, you can either <InternalLink path="column-families#manual-override">manually split a table's columns into multiple column families</InternalLink>, or you can <InternalLink path="configure-replication-zones#create-a-replication-zone-for-a-table">create a table-specific zone configuration</InternalLink> with an increased max range size.

#### Dropping a single partition

CockroachDB does not currently support dropping a single partition from a table. In order to remove partitions, you can <InternalLink path="partitioning#repartition-a-table">repartition</InternalLink> the table.

#### Placeholders in `PARTITION BY`

When defining a <InternalLink path="partitioning">table partition</InternalLink>, either during table creation or table alteration, it is not possible to use placeholders in the `PARTITION BY` clause.

#### Unsupported trigram syntax

The following PostgreSQL syntax and features are currently unsupported for <InternalLink path="trigram-indexes">trigrams</InternalLink>:

* `word_similarity()` built-in function.
* `strict_word_similarity()` built-in function.
* `%>` and `<%` comparisons and acceleration.
* `<<%` and `%>>` comparisons and acceleration.
* `<->`, `<<->`, `<->>`, `<<<->`, and `<->>>` comparisons.
* Acceleration on <InternalLink path="scalar-expressions#string-matching-using-posix-regular-expressions">regex string matching</InternalLink>.
* `%` comparisons, `show_trgm`, and trigram index creation on <InternalLink path="collate">collated strings</InternalLink>.

#### Unsupported full-text search features

The following PostgreSQL syntax and features are currently unsupported for <InternalLink path="full-text-search">full-text search</InternalLink>:

* Aspects of <InternalLink path="full-text-search#text-search-configuration">text search configurations</InternalLink> other than the specified dictionary.
* `websearch_to_tsquery()` built-in function.
* `tsquery_phrase()` built-in function.
* `ts_rank_cd()` built-in function.
* `setweight()` built-in function.
* Inverted joins on `TSVECTOR` values.
* `tsvector || tsvector` comparisons.
* `tsquery || tsquery` comparisons.
* `tsquery && tsquery` comparisons.
* `tsquery <-> tsquery` comparisons.
* `!! tsquery` comparisons.
* `tsquery @> tsquery` and `tsquery <@ tsquery` comparisons.

#### CockroachDB does not allow inverted indexes with `STORING`

CockroachDB does not allow inverted indexes with a <InternalLink path="create-index#store-columns">`STORING` column</InternalLink>.

#### Multiple arbiter indexes for `INSERT ON CONFLICT DO UPDATE`

CockroachDB does not currently support multiple arbiter indexes for <InternalLink path="insert#on-conflict-clause">`INSERT ON CONFLICT DO UPDATE`</InternalLink>, and will return an error if there are multiple unique or exclusion constraints matching the `ON CONFLICT DO UPDATE` specification.

#### Expression index limitations

* The expression cannot reference columns outside the index's table.
* Functional expression output must be determined by the input arguments. For example, you can't use the <InternalLink path="functions-and-operators#function-volatility">volatile function</InternalLink> `now()` to create an index because its output depends on more than just the function arguments.
* CockroachDB does not allow <InternalLink path="expression-indexes">expression indexes</InternalLink> to reference <InternalLink path="computed-columns">computed columns</InternalLink>.
* CockroachDB does not support expressions as `ON CONFLICT` targets. This means that unique <InternalLink path="expression-indexes">expression indexes</InternalLink> cannot be selected as arbiters for <InternalLink path="insert#on-conflict-clause">`INSERT .. ON CONFLICT`</InternalLink> statements. For example:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  CREATE TABLE t (a INT, b INT, UNIQUE INDEX ((a + b)));
  ```

  ```
  CREATE TABLE
  ```

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  INSERT INTO t VALUES (1, 2) ON CONFLICT ((a + b)) DO NOTHING;
  ```

  ```
  invalid syntax: statement ignored: at or near "(": syntax error
  SQLSTATE: 42601
  DETAIL: source SQL:
  INSERT INTO t VALUES (1, 2) ON CONFLICT ((a + b)) DO NOTHING
                                      ^
  HINT: try \h INSERT
  ```

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  INSERT INTO t VALUES (1, 2) ON CONFLICT ((a + b)) DO UPDATE SET a = 10;
  ```

  ```
  invalid syntax: statement ignored: at or near "(": syntax error
  SQLSTATE: 42601
  DETAIL: source SQL:
  INSERT INTO t VALUES (1, 2) ON CONFLICT ((a + b)) DO UPDATE SET a = 10
                                      ^
  HINT: try \h INSERT
  ```

#### Secondary regions and regional by row tables

<InternalLink path="multiregion-overview#secondary-regions">Secondary regions</InternalLink> are not compatible with databases containing <InternalLink path="table-localities#regional-by-row-tables">`REGIONAL BY ROW`</InternalLink> tables. CockroachDB does not prevent you from defining secondary regions on databases with regional by row tables, but the interaction of these features is not supported.

Therefore, Cockroach Labs recommends that you avoid defining secondary regions on databases that use regional by row table configurations.

### Data types

#### Spatial support limitations

CockroachDB supports efficiently storing and querying <InternalLink path="export-spatial-data">spatial data</InternalLink>, with the following limitations:

* Not all [PostGIS spatial functions](https://postgis.net/docs/reference.html) are supported.

* The `AddGeometryColumn` <InternalLink path="functions-and-operators#spatial-functions">spatial function</InternalLink> only allows constant arguments.

* The `AddGeometryColumn` spatial function only allows the `true` value for its `use_typmod` parameter.

* CockroachDB does not support the `@` operator. Instead of using `@` in spatial expressions, we recommend using the inverse, with `~`. For example, instead of `a @ b`, use `b ~ a`.

* CockroachDB does not yet support <InternalLink path="insert">`INSERT`</InternalLink>s into the <InternalLink path="architecture/glossary#spatial-system-tables">`spatial_ref_sys` table</InternalLink>. This limitation also blocks the [`ogr2ogr -f PostgreSQL` file conversion command](https://gdal.org/programs/ogr2ogr.html#cmdoption-ogr2ogr-f).

* CockroachDB does not yet support [k-nearest neighbors](https://wikipedia.org/wiki/K-nearest_neighbors_algorithm).

* CockroachDB does not support using <InternalLink path="sql-name-resolution#how-name-resolution-works">schema name prefixes</InternalLink> to refer to <InternalLink path="data-types">data types</InternalLink> with type modifiers (e.g., `public.geometry(linestring, 4326)`). Instead, use fully-unqualified names to refer to data types with type modifiers (e.g., `geometry(linestring,4326)`).

* Defining a custom SRID by inserting rows into <InternalLink path="architecture/glossary#spatial_ref_sys">`spatial_ref_sys`</InternalLink> is not currently supported.

#### `OID` limitations

Refer to <InternalLink path="oid#best-practices">`OID` best practices</InternalLink>.

#### Limitations for composite types

* Changefeed types are not fully integrated with <InternalLink path="create-type">user-defined composite types</InternalLink>. Running changefeeds with user-defined composite types is in <InternalLink version="releases" path="cockroachdb-feature-availability#feature-availability-phases">Preview</InternalLink>. Certain changefeed types do not support user-defined composite types. Refer to the change data capture <InternalLink path="create-and-configure-changefeeds#known-limitations">Known Limitations</InternalLink> for more detail. The following limitations apply:

  * A changefeed in <InternalLink path="changefeed-messages#avro">Avro format</InternalLink> will not be able to serialize <InternalLink path="create-type">user-defined composite (tuple) types</InternalLink>.
  * A changefeed emitting <InternalLink path="changefeed-messages#csv">CSV</InternalLink> will include `AS` labels in the message format when the changefeed serializes a <InternalLink path="create-type">user-defined composite type</InternalLink>.

* Updating subfields of composite types using dot syntax results in a syntax error.

* Tuple elements cannot be accessed without enclosing the <InternalLink path="create-type#create-a-composite-data-type">composite variable</InternalLink> name in parentheses. For example, `(v).x`.

#### `ALTER TYPE` limitations

* When running the <InternalLink path="alter-type">`ALTER TYPE`</InternalLink> statement, you can only reference a user-defined type from the database that contains the type.
* You can only <InternalLink path="cancel-job">cancel</InternalLink> `ALTER TYPE` <InternalLink path="online-schema-changes">schema change jobs</InternalLink> that drop values. This is because when you drop a value, CockroachDB searches through every row that could contain the type's value, which could take a long time. All other `ALTER TYPE` schema change jobs are <InternalLink path="cancel-job#known-limitations">non-cancellable</InternalLink>.

#### `JSONB` limitations

* You cannot use <InternalLink path="primary-key">primary key</InternalLink>, <InternalLink path="foreign-key">foreign key</InternalLink>, and <InternalLink path="unique">unique</InternalLink> <InternalLink path="constraints">constraints</InternalLink> on `JSONB` values.

### Security and privileges

#### `GRANT`/`REVOKE` limitations

User/role management operations (such as <InternalLink path="grant">`GRANT`</InternalLink> and <InternalLink path="revoke">`REVOKE`</InternalLink>) are <InternalLink path="online-schema-changes">schema changes</InternalLink>. As such, they inherit the <InternalLink path="online-schema-changes#known-limitations">limitations of schema changes</InternalLink>.

For example, schema changes wait for concurrent <InternalLink path="transactions">transactions</InternalLink> using the same resources as the schema changes to complete. In the case of <InternalLink path="security-reference/authorization#roles">role memberships</InternalLink> being modified inside a transaction, most transactions need access to the set of role memberships. Using the default settings, role modifications require schema leases to expire, which can take up to 5 minutes.

This means that <InternalLink path="query-behavior-troubleshooting#hanging-or-stuck-queries">long-running transactions</InternalLink> elsewhere in the system can cause user/role management operations inside transactions to take several minutes to complete. This can have a cascading effect. When a user/role management operation inside a transaction takes a long time to complete, it can in turn block all user-initiated transactions being run by your application, since the user/role management operation in the transaction has to commit before any other transactions that access role memberships (i.e., most transactions) can make progress.

If you want user/role management operations to finish more quickly, and do not care whether concurrent transactions will immediately see the side effects of those operations, set the <InternalLink path="set-vars">session variable</InternalLink> `allow_role_memberships_to_change_during_transaction` to `true`.

When this session variable is enabled, any user/role management operations issued in the current session will only need to wait for the completion of statements in other sessions where `allow_role_memberships_to_change_during_transaction` is not enabled.

To accelerate user/role management operations across your entire application, you have the following options:

1. Set the session variable in all sessions by <InternalLink path="connection-parameters#supported-options-parameters">passing it in the client connection string</InternalLink>.
2. Apply the `allow_role_memberships_to_change_during_transaction` setting globally to an entire cluster using the <InternalLink path="alter-role#set-default-session-variable-values-for-all-users">`ALTER ROLE ALL`</InternalLink> statement:

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   ALTER ROLE ALL SET allow_role_memberships_to_change_during_transaction = true;
   ```

#### `DROP OWNED BY` limitations

* <InternalLink path="enum">`ENUM`</InternalLink> types are not dropped.
* <InternalLink path="drop-owned-by">`DROP OWNED BY`</InternalLink> drops all owned objects as well as any <InternalLink path="grant">grants</InternalLink> on objects not owned by the <InternalLink path="security-reference/authorization#roles">role</InternalLink>.
* If the <InternalLink path="security-reference/authorization#roles">role</InternalLink> for which you are trying to `DROP OWNED BY` was granted a <InternalLink path="security-reference/authorization#supported-privileges">system-level privilege</InternalLink> (i.e., using the <InternalLink path="grant#grant-system-level-privileges-on-the-entire-cluster">`GRANT SYSTEM ...`</InternalLink> statement), the following error will be signalled:

  ```
  ERROR: cannot perform drop owned by if role has synthetic privileges; foo has entries in system.privileges
  SQLSTATE: 0A000
  HINT: perform REVOKE SYSTEM ... for the relevant privileges foo has in system.privileges
  ```

  The phrase "synthetic privileges" in the error message refers to <InternalLink path="security-reference/authorization#supported-privileges">system-level privileges</InternalLink>.

  The workaround is to use <InternalLink path="show-system-grants">`SHOW SYSTEM GRANTS FOR {role}`</InternalLink> and then use <InternalLink path="revoke#revoke-system-level-privileges-on-the-entire-cluster">`REVOKE SYSTEM ...`</InternalLink> for each privilege in the result.

#### Privileges for `DELETE` and `UPDATE`

Every <InternalLink path="delete">`DELETE`</InternalLink> or <InternalLink path="update">`UPDATE`</InternalLink> statement constructs a `SELECT` statement, even when no `WHERE` clause is involved. As a result, the user executing `DELETE` or `UPDATE` requires both the `DELETE` and `SELECT` or `UPDATE` and `SELECT` <InternalLink path="security-reference/authorization#managing-privileges">privileges</InternalLink> on the table.

### Deployment and operations

#### Admission control

Admission control works on the level of each node, not at the cluster level. The admission control system queues requests until the operations are processed or the request exceeds the timeout value (for example by using <InternalLink path="set-vars#supported-variables">`SET statement_timeout`</InternalLink>). If you specify aggressive timeout values, the system may operate correctly but have low throughput as the operations exceed the timeout value while only completing part of the work. There is no mechanism for preemptively rejecting requests when the work queues are long.

Organizing operations by priority can mean that higher priority operations consume all the available resources while lower priority operations remain in the queue until the operation times out.

#### Data domiciling

* When columns are <InternalLink path="indexes">indexed</InternalLink>, a subset of data from the indexed columns may appear in <InternalLink path="architecture/distribution-layer#meta-ranges">meta ranges</InternalLink> or other system tables. CockroachDB synchronizes these system ranges and system tables across nodes. This synchronization does not respect any multi-region settings applied via either the <InternalLink path="multiregion-overview">multi-region SQL statements</InternalLink>, or the low-level <InternalLink path="configure-replication-zones">zone configs</InternalLink> mechanism.
* <InternalLink path="configure-replication-zones">Zone configs</InternalLink> can be used for data placement but these features were historically built for performance, not for domiciling. The replication system's top priority is to prevent the loss of data and it may override the zone configurations if necessary to ensure data durability. For more information, see <InternalLink path="configure-replication-zones#types-of-constraints">Replication Controls</InternalLink>.
* If your <InternalLink path="logging-overview">log files</InternalLink> are kept in the region where they were generated, there is some cross-region leakage (like the system tables described previously), but the majority of user data that makes it into the logs is going to be homed in that region. If that's not strong enough, you can use the <InternalLink path="configure-logs#redact-logs">log redaction functionality</InternalLink> to strip all raw data from the logs. You can also limit your log retention entirely.
* If you start a node with a <InternalLink path="cockroach-start#locality">`--locality`</InternalLink> flag that says the node is in region *A*, but the node is actually running in some region *B*, data domiciling based on the inferred node placement will not work. A CockroachDB node only knows its locality based on the text supplied to the `--locality` flag; it can not ensure that it is actually running in that physical location.

#### CockroachDB does not test for all connection failure scenarios

CockroachDB servers rely on the network to report when a TCP connection fails. In most scenarios when a connection fails, the network immediately reports a connection failure, resulting in a `Connection refused` error.

However, if there is no host at the target IP address, or if a firewall rule blocks traffic to the target address and port, a TCP handshake can linger while the client network stack waits for a TCP packet in response to network requests. To work around this kind of scenario, we recommend the following:

* When migrating a node to a new machine, keep the server listening at the previous IP address until the cluster has completed the migration.
* Configure any active network firewalls to allow node-to-node traffic.
* Verify that orchestration tools (e.g., Kubernetes) are configured to use the correct network connection information.

#### No guaranteed state switch from `DECOMMISSIONING` to `DECOMMISSIONED` if `node decommission` is interrupted

There is no guaranteed state switch from `DECOMMISSIONING` to `DECOMMISSIONED` if <InternalLink path="cockroach-node">`node decommission`</InternalLink> is interrupted in one of the following ways:

* The `cockroach node decommission --wait-all` command was run and then interrupted
* The `cockroach node decommission --wait=none` command was run

This is because the state flip is effected by the CLI program at the end. Only the CLI (or its underlying API call) is able to finalize the "decommissioned" state. If the command is interrupted, or `--wait=none` is used, the state will only flip to "decommissioned" when the CLI program is run again after decommissioning has done all its work.

#### Simultaneous client connections and running queries on a single node

When a node has both a high number of client connections and running queries, the node may crash due to memory exhaustion. This is due to CockroachDB not accurately limiting the number of clients and queries based on the amount of available RAM on the node.

To prevent memory exhaustion, monitor each node's memory usage and ensure there is some margin between maximum CockroachDB memory usage and available system RAM. For more details about memory usage in CockroachDB, see [this blog post](https://www.cockroachlabs.com/blog/memory-usage-cockroachdb/).

To control the maximum number of non-superuser (<InternalLink path="security-reference/authorization">`root`</InternalLink> user or other <InternalLink path="security-reference/authorization#admin-role">`admin` role</InternalLink>) connections a <InternalLink path="architecture/sql-layer">gateway node</InternalLink> can have open at one time, use the `server.max_connections_per_gateway` <InternalLink path="cluster-settings">cluster setting</InternalLink>. If a new non-superuser connection would exceed this limit, the error message `"sorry, too many clients already"` is returned, along with error code `53300`. This may be useful in addition to your memory monitoring.

#### Load-based lease rebalancing in uneven latency deployments

When nodes are started with the <InternalLink path="cockroach-start#flags">`--locality`</InternalLink> flag, CockroachDB attempts to place the replica lease holder (the replica that client requests are forwarded to) on the node closest to the source of the request. This means as client requests move geographically, so too does the replica lease holder.

However, you might see increased latency caused by a consistently high rate of lease transfers between datacenters in the following case:

* Your cluster runs in datacenters which are very different distances away from each other.
* Each node was started with a single tier of `--locality`, e.g., `--locality=datacenter=a`.
* Most client requests get sent to a single datacenter because that's where all your application traffic is.

To detect if this is happening, open the <InternalLink path="ui-overview">DB Console</InternalLink>, select the **Queues** dashboard, hover over the **Replication Queue** graph, and check the **Leases Transferred / second** data point. If the value is consistently larger than 0, you should consider stopping and restarting each node with additional tiers of locality to improve request latency.

For example, let's say that latency is 10ms from nodes in datacenter A to nodes in datacenter B but is 100ms from nodes in datacenter A to nodes in datacenter C. To ensure A's and B's relative proximity is factored into lease holder rebalancing, you could restart the nodes in datacenter A and B with a common region, `--locality=region=foo,datacenter=a` and `--locality=region=foo,datacenter=b`, while restarting nodes in datacenter C with a different region, `--locality=region=bar,datacenter=c`.

#### Size limits on statement input from SQL clients

CockroachDB imposes a hard limit of 16MiB on the data input for a single statement passed to CockroachDB from a client (including the SQL shell). We do not recommend attempting to execute statements from clients with large input.

#### Using `\|` to perform a large input in the SQL shell

In the <InternalLink path="cockroach-sql">built-in SQL shell</InternalLink>, using the <InternalLink path="cockroach-sql#commands">`\|`</InternalLink> operator to perform a large number of inputs from a file can cause the server to close the connection. This is because `\|` sends the entire file as a single query to the server, which can exceed the upper bound on the size of a packet the server can accept from any client (16MB).

As a workaround, <InternalLink path="cockroach-sql#execute-sql-statements-from-a-file">execute the file from the command line</InternalLink> with `cat data.sql | cockroach sql` instead of from within the interactive shell.

#### Spatial features disabled for ARM Macs

<InternalLink path="spatial-data-overview">Spatial features</InternalLink> are disabled due to an issue with macOS code signing for the [GEOS](https://libgeos.org/) libraries. Users needing spatial features on an ARM Mac may instead [use Rosetta](https://developer.apple.com/documentation/virtualization/running_intel_binaries_in_linux_vms_with_rosetta) to <InternalLink path="install-cockroachdb">run the Intel binary</InternalLink> or use the <InternalLink path="install-cockroachdb#use-docker">Docker image</InternalLink> distribution.

#### Logging system limitations

Log files can only be accessed in the DB Console if they are stored in the same directory as the file sink for the `DEV` channel.

#### Per-replica circuit breaker limitations

<InternalLink path="architecture/replication-layer#per-replica-circuit-breakers">Per-replica circuit breakers</InternalLink> have the following limitations:

* They cannot prevent requests from hanging when the node's <InternalLink path="architecture/replication-layer#epoch-based-leases-table-data">liveness range</InternalLink> is unavailable. For more information about troubleshooting a cluster that's having node liveness issues, see <InternalLink path="cluster-setup-troubleshooting#node-liveness-issues">Node liveness issues</InternalLink>.
* They are not tripped if *all* replicas of a range <InternalLink path="cluster-setup-troubleshooting">become unavailable</InternalLink>, because the circuit breaker mechanism operates per-replica. This means at least one replica needs to be available to receive the request in order for the breaker to trip.

#### Kubernetes limitations

Refer to <InternalLink path="deploy-cockroachdb-with-kubernetes#best-practices">Kubernetes best practices</InternalLink>.

### Observability

#### Datadog

The integration of your CockroachDB self-hosted cluster with Datadog only supports displaying cluster-wide averages of reported metrics. Filtering by a specific node is unsupported.

#### DB Console may become inaccessible for secure clusters

Accessing the DB Console for a secure cluster now requires login information (i.e., username and password). This login information is stored in a system table that is replicated like other data in the cluster. If a majority of the nodes with the replicas of the system table data go down, users will be locked out of the DB Console.

#### Available capacity metric in the DB Console

If you are testing your deployment locally with multiple CockroachDB nodes running on a single machine (this is <InternalLink path="recommended-production-settings#topology">not recommended in production</InternalLink>), you must explicitly <InternalLink path="cockroach-start#store">set the store size</InternalLink> per node in order to display the correct capacity. Otherwise, the machine's actual disk capacity will be counted as a separate store for each node, thus inflating the computed capacity.

### Disaster recovery

#### Physical cluster replication

* Physical cluster replication is supported in CockroachDB self-hosted clusters on v23.2 or later. The primary cluster can be a <InternalLink path="set-up-physical-cluster-replication#step-1-create-the-primary-cluster">new</InternalLink> or <InternalLink path="set-up-physical-cluster-replication#set-up-pcr-from-an-existing-cluster">existing</InternalLink> cluster. The standby cluster must be a <InternalLink path="set-up-physical-cluster-replication#step-2-create-the-standby-cluster">new cluster started with the `--virtualized-empty` flag</InternalLink>.

* Read queries are not supported on the standby cluster before <InternalLink path="failover-replication">failover</InternalLink>.

* In CockroachDB self-hosted, the primary and standby clusters must have the same <InternalLink path="configure-replication-zones">zone configurations</InternalLink> in order to respect data placement configurations.

* After the <InternalLink path="failover-replication">failover process</InternalLink> for <InternalLink path="physical-cluster-replication-overview">physical cluster replication</InternalLink>, <InternalLink path="create-schedule-for-changefeed">scheduled changefeeds</InternalLink> will continue on the promoted cluster. You will need to manage <InternalLink path="pause-schedules">pausing</InternalLink> or <InternalLink path="drop-schedules">canceling</InternalLink> the schedule on the promoted standby cluster to avoid two clusters running the same changefeed to one sink.

* After a cutover, there is no mechanism to stop applications from connecting to the original primary cluster. It is necessary to redirect application traffic manually, such as by using a network load balancer or adjusting DNS records.

#### `RESTORE` limitations

* `RESTORE` will not restore a table that references a <InternalLink path="user-defined-functions">UDF</InternalLink>, unless you skip restoring the function with the <InternalLink path="restore">`skip_missing_udfs`</InternalLink> option. Alternatively, take a <InternalLink path="backup#back-up-a-database">database-level backup</InternalLink> to include everything needed to restore the table.

* Restoring <InternalLink path="table-localities#global-tables">`GLOBAL`</InternalLink> and <InternalLink path="table-localities#regional-tables">`REGIONAL BY TABLE`</InternalLink> tables into a **non**-multi-region database is not supported.

* <InternalLink path="table-localities#regional-tables">`REGIONAL BY TABLE`</InternalLink> and <InternalLink path="table-localities#regional-by-row-tables">`REGIONAL BY ROW`</InternalLink> tables can be restored **only** if the regions of the backed-up table match those of the destination database. All of the following must be true for `RESTORE` to be successful:

  * The <InternalLink path="multiregion-overview#database-regions">regions</InternalLink> of the source database and the regions of the destination database have the same set of regions.
  * The regions were added to each of the databases in the same order.
  * The databases have the same <InternalLink path="alter-database#set-primary-region">primary region</InternalLink>.

  The following example would be considered as having **mismatched** regions because the database regions were not added in the same order and the primary regions do not match.

  Running on the source database:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  ALTER DATABASE source_database SET PRIMARY REGION "us-east1";
  ```

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  ALTER DATABASE source_database ADD region "us-west1";
  ```

  Running on the destination database:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  ALTER DATABASE destination_database SET PRIMARY REGION "us-west1";
  ```

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  ALTER DATABASE destination_database ADD region "us-east1";
  ```

  In addition, the following scenario has mismatched regions between the databases since the regions were not added to the database in the same order.

  Running on the source database:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  ALTER DATABASE source_database SET PRIMARY REGION "us-east1";
  ```

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  ALTER DATABASE source_database ADD region "us-west1";
  ```

  Running on the destination database:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  ALTER DATABASE destination_database SET PRIMARY REGION "us-west1";
  ```

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  ALTER DATABASE destination_database ADD region "us-east1";
  ```

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  ALTER DATABASE destination_database SET PRIMARY REGION "us-east1";
  ```

#### Enterprise `BACKUP` does not capture database/table/column comments

The <InternalLink path="comment-on">`COMMENT ON`</InternalLink> statement associates comments to databases, tables, or columns. However, the internal table (`system.comments`) in which these comments are stored is not captured by a <InternalLink path="backup">`BACKUP`</InternalLink> of a table or database.

As a workaround, take a cluster backup instead, as the `system.comments` table is included in cluster backups.

#### `SHOW BACKUP` does not support symlinks for nodelocal

<InternalLink path="show-backup">`SHOW BACKUP`</InternalLink> does not support listing backups if the <InternalLink path="cockroach-nodelocal-upload">`nodelocal`</InternalLink> storage location is a symlink.

### Change data capture

Change data capture (CDC) provides efficient, distributed, row-level changefeeds into Apache Kafka for downstream processing such as reporting, caching, or full-text indexing. It has the following known limitations:

* Changefeed target options are limited to tables and <InternalLink path="changefeeds-on-tables-with-column-families">column families</InternalLink>.

* <InternalLink version="cockroachcloud" path="network-authorization">VPC Peering</InternalLink> and <InternalLink version="cockroachcloud" path="network-authorization">AWS PrivateLink</InternalLink> in CockroachDB Advanced clusters do **not** support connecting to a <InternalLink path="changefeed-sinks#kafka">Kafka</InternalLink> sink's internal IP addresses for <InternalLink path="change-data-capture-overview">changefeeds</InternalLink>. To connect to a Kafka sink from CockroachDB Advanced, it is necessary to expose the Kafka cluster's external IP address and open ports with firewall rules to allow access from a CockroachDB Advanced cluster.

* Webhook sinks only support HTTPS. Use the <InternalLink path="create-changefeed">`insecure_tls_skip_verify`</InternalLink> parameter when testing to disable certificate verification; however, this still requires HTTPS and certificates.

* Formats for changefeed messages are not supported by all changefeed sinks. Refer to the <InternalLink path="changefeed-sinks">Changefeed Sinks</InternalLink> page for details on compatible formats with each sink and the <InternalLink path="create-changefeed">`format`</InternalLink> option to specify a changefeed message format.

* Using the <InternalLink path="create-changefeed">`split_column_families`</InternalLink> and <InternalLink path="create-changefeed">`resolved`</InternalLink> options on the same changefeed will cause an error when using the following <InternalLink path="changefeed-sinks">sinks</InternalLink>: Kafka and Google Cloud Pub/Sub. Instead, use the individual `FAMILY` keyword to specify column families when creating a changefeed.

* Changefeed types are not fully integrated with <InternalLink path="create-type">user-defined composite types</InternalLink>. Running changefeeds with user-defined composite types is in <InternalLink version="releases" path="cockroachdb-feature-availability#feature-availability-phases">Preview</InternalLink>. Certain changefeed types do not support user-defined composite types. Refer to the change data capture <InternalLink path="create-and-configure-changefeeds#known-limitations">Known Limitations</InternalLink> for more detail. The following limitations apply:

  * A changefeed in <InternalLink path="changefeed-messages#avro">Avro format</InternalLink> will not be able to serialize <InternalLink path="create-type">user-defined composite (tuple) types</InternalLink>.
  * A changefeed emitting <InternalLink path="changefeed-messages#csv">CSV</InternalLink> will include `AS` labels in the message format when the changefeed serializes a <InternalLink path="create-type">user-defined composite type</InternalLink>.

* After the <InternalLink path="failover-replication">failover process</InternalLink> for <InternalLink path="physical-cluster-replication-overview">physical cluster replication</InternalLink>, <InternalLink path="create-schedule-for-changefeed">scheduled changefeeds</InternalLink> will continue on the promoted cluster. You will need to manage <InternalLink path="pause-schedules">pausing</InternalLink> or <InternalLink path="drop-schedules">canceling</InternalLink> the schedule on the promoted standby cluster to avoid two clusters running the same changefeed to one sink.

* You can only apply CDC queries on a single table in each statement.

* Some <InternalLink path="functions-and-operators#built-in-functions">stable functions</InternalLink>, notably functions that return MVCC timestamps, are overridden to return the MVCC timestamp of the event, e.g., `transaction_timestamp` or `statement_timestamp`. Additionally, some <InternalLink path="functions-and-operators#date-and-time-functions">time-based functions</InternalLink>, such as `now()` are not supported. We recommend using the `transaction_timestamp()` function or the <InternalLink path="cdc-queries#crdb-internal-mvcc-timestamp">`crdb_internal_mvcc_timestamp`</InternalLink> column instead.

* The following are not permitted in CDC queries:

  * <InternalLink path="functions-and-operators#function-volatility">Volatile functions</InternalLink>.
  * Sub-select queries.
  * <InternalLink path="functions-and-operators#aggregate-functions">Aggregate</InternalLink> and <InternalLink path="window-functions">window functions</InternalLink> (i.e., functions operating over many rows).

* `delete` changefeed events will only contain the <InternalLink path="primary-key">primary key</InternalLink>. All other columns will emit as `NULL`. See <InternalLink path="cdc-queries#capture-delete-messages">Capture delete messages</InternalLink> for detail on running a CDC query that emits the deleted values.

* Creating a changefeed with <InternalLink path="cdc-queries#crdb-internal-mvcc-timestamp">CDC queries</InternalLink> on tables with more than one <InternalLink path="changefeeds-on-tables-with-column-families">column family</InternalLink> is not supported.

* When you create a changefeed on a table with more than one <InternalLink path="changefeeds-on-tables-with-column-families">column family</InternalLink> , the changefeed will emit messages per column family in separate streams. As a result, <InternalLink path="changefeed-messages">changefeed messages</InternalLink> for different column families will arrive at the <InternalLink path="changefeed-sinks">sink</InternalLink> under separate topics.

#### `ALTER CHANGEFEED` limitations

* It is necessary to <InternalLink path="pause-job">`PAUSE`</InternalLink> the changefeed before performing any <InternalLink path="alter-changefeed">`ALTER CHANGEFEED`</InternalLink> statement.

* CockroachDB does not keep track of the <InternalLink path="create-changefeed">`initial_scan`</InternalLink> option applied to tables when it is set to `yes` or `only`. For example:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  ALTER CHANGEFEED {job_ID} ADD table WITH initial_scan = 'yes';
  ```

  This will trigger an initial scan of the table and the changefeed will track `table`. The changefeed will **not** track `initial_scan` specified as an option, so it will not display in the output or after a `SHOW CHANGEFEED JOB` statement.

* <InternalLink path="alter-changefeed">`ALTER CHANGEFEED`</InternalLink> is not fully supported with changefeeds that use <InternalLink path="cdc-queries#crdb-internal-mvcc-timestamp">CDC queries</InternalLink>. You can alter the options that a changefeed uses, but you cannot alter the changefeed target tables.

### Performance optimization

#### Optimizer and locking behavior

The SQL optimizer has limitations under certain isolation levels:

* The new implementation of `SELECT FOR UPDATE` is not yet the default setting under `SERIALIZABLE` isolation. It can be used under `SERIALIZABLE` isolation by setting the `optimizer_use_lock_op_for_serializable` <InternalLink path="session-variables">session setting</InternalLink> to `true`.
* `SELECT FOR UPDATE` does not lock completely-`NULL` column families in multi-column-family tables.

#### Statistics limitations

* The <InternalLink path="cost-based-optimizer#control-statistics-refresh-rate">automatic statistics refresher</InternalLink> automatically checks whether it needs to refresh statistics for every table in the database upon startup of each node in the cluster. If statistics for a table have not been refreshed in a while, this will trigger collection of statistics for that table. If statistics have been refreshed recently, it will not force a refresh. As a result, the automatic statistics refresher does not necessarily perform a refresh of statistics after an <InternalLink path="upgrade-cockroach-version">upgrade</InternalLink>. This could cause a problem, for example, if the upgrade moves from a version without <InternalLink path="cost-based-optimizer#control-histogram-collection">histograms</InternalLink> to a version with histograms. To refresh statistics manually, use <InternalLink path="create-statistics">`CREATE STATISTICS`</InternalLink>.

* The following <InternalLink path="cluster-settings">cluster settings</InternalLink> do not immediately take effect, and instead only take effect when new statistics are collected for a table.

  * <InternalLink path="cluster-settings">`sql.stats.forecasts.max_decrease`</InternalLink>
  * <InternalLink path="cluster-settings">`sql.stats.forecasts.min_goodness_of_fit`</InternalLink>
  * <InternalLink path="cluster-settings">`sql.stats.forecasts.min_observations`</InternalLink>

  Although <InternalLink path="show-statistics#display-forecasted-statistics">`SHOW STATISTICS WITH FORECAST`</InternalLink> shows the settings taking effect immediately, they do not actually take effect until new statistics are collected (as can be verified with <InternalLink path="explain">`EXPLAIN`</InternalLink>).

  As a workaround, disable and enable forecasting at the <InternalLink path="cost-based-optimizer#enable-and-disable-automatic-statistics-collection-for-clusters">cluster</InternalLink> or <InternalLink path="cost-based-optimizer#enable-and-disable-automatic-statistics-collection-for-tables">table</InternalLink> level. This will invalidate the statistics cache and cause these settings to take effect immediately.

#### Incorrect query plans for partitions with `NULL` values

In cases where the partition definition includes a comparison with `NULL` and a query constraint, incorrect query plans are returned. However, this case uses non-standard partitioning which defines partitions which could never hold values, so it is not likely to occur in production environments.

#### Vectorized engine limitations

* The vectorized engine does not support queries containing a join filtered with an <InternalLink path="joins#supported-join-conditions">`ON` expression</InternalLink>.
* The vectorized engine does not support <InternalLink path="export-spatial-data">working with spatial data</InternalLink>. Queries with <InternalLink path="functions-and-operators#spatial-functions">geospatial functions</InternalLink> or <InternalLink path="export-spatial-data">spatial data</InternalLink> will revert to the row-oriented execution engine.

#### `transaction_rows_read_err` and `transaction_rows_written_err` do not halt query execution

The `transaction_rows_read_err` and `transaction_rows_written_err` <InternalLink path="set-vars">session settings</InternalLink> limit the number of rows read or written by a single <InternalLink path="transactions#limit-the-number-of-rows-written-or-read-in-a-transaction">transaction</InternalLink>. These session settings will fail the transaction with an error, but not until the current query finishes executing and the results have been returned to the client.

#### `sql.guardrails.max_row_size_err` misses indexed virtual computed columns

The `sql.guardrails.max_row_size_err` <InternalLink path="cluster-settings">cluster setting</InternalLink> misses large rows caused by indexed virtual computed columns. This is because the guardrail only checks the size of primary key rows, not secondary index rows.

#### Using `LIKE...ESCAPE` in `WHERE` and `HAVING` constraints

CockroachDB tries to optimize most comparisons operators in `WHERE` and `HAVING` clauses into constraints on SQL indexes by only accessing selected rows. This is done for `LIKE` clauses when a common prefix for all selected rows can be determined in the search pattern (e.g., `... LIKE 'Joe%'`). However, this optimization is not yet available if the `ESCAPE` keyword is also used.

#### Import with a high amount of disk contention

<InternalLink path="import-into">`IMPORT INTO`</InternalLink> can sometimes fail with a "context canceled" error, or can restart itself many times without ever finishing. If this is happening, it is likely due to a high amount of disk contention. This can be mitigated by setting the `kv.bulk_io_write.max_rate` <InternalLink path="cluster-settings">cluster setting</InternalLink> to a value below your max disk write speed. For example, to set it to 10MB/s, execute:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SET CLUSTER SETTING kv.bulk_io_write.max_rate = '10MB';
```

#### CockroachDB does not properly optimize some left and anti joins with GIN indexes

<InternalLink path="joins#left-outer-joins">Left joins</InternalLink> and anti joins involving <InternalLink path="jsonb">`JSONB`</InternalLink>, <InternalLink path="array">`ARRAY`</InternalLink>, or <InternalLink path="export-spatial-data">spatial-typed</InternalLink> columns with a multi-column or <InternalLink path="alter-index#partition-by">partitioned</InternalLink> <InternalLink path="inverted-indexes">GIN index</InternalLink> will not take advantage of the index if the prefix columns of the index are unconstrained, or if they are constrained to multiple, constant values.

To work around this limitation, make sure that the prefix columns of the index are either constrained to single constant values, or are part of an equality condition with an input column (e.g., `col1 = col2`, where `col1` is a prefix column and `col2` is an input column).

For example, suppose you have the following <InternalLink path="multiregion-overview">multi-region database</InternalLink> and tables:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
CREATE DATABASE multi_region_test_db PRIMARY REGION "europe-west1" REGIONS "us-west1", "us-east1" SURVIVE REGION FAILURE;
USE multi_region_test_db;

CREATE TABLE t1 (
  k INT PRIMARY KEY,
  geom GEOMETRY
);

CREATE TABLE t2 (
  k INT PRIMARY KEY,
  geom GEOMETRY,
  INVERTED INDEX geom_idx (geom)
) LOCALITY REGIONAL BY ROW;
```

And you <InternalLink path="insert">insert</InternalLink> some data into the tables:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
INSERT INTO t1 SELECT generate_series(1, 1000), 'POINT(1.0 1.0)';
INSERT INTO t2 (crdb_region, k, geom) SELECT 'us-east1', generate_series(1, 1000), 'POINT(1.0 1.0)';
INSERT INTO t2 (crdb_region, k, geom) SELECT 'us-west1', generate_series(1001, 2000), 'POINT(2.0 2.0)';
INSERT INTO t2 (crdb_region, k, geom) SELECT 'europe-west1', generate_series(2001, 3000), 'POINT(3.0 3.0)';
```

If you attempt a left join between `t1` and `t2` on only the geometry columns, CockroachDB will not be able to plan an <InternalLink path="joins#inverted-joins">inverted join</InternalLink>:

```
> EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON st_contains(t1.geom, t2.geom);
                info
------------------------------------
  distribution: full
  vectorized: true

  • cross join (right outer)
  │ pred: st_contains(geom, geom)
  │
  ├── • scan
  │     estimated row count: 3,000
  │     table: t2@primary
  │     spans: FULL SCAN
  │
  └── • scan
        estimated row count: 1,000
        table: t1@primary
        spans: FULL SCAN
(15 rows)
```

However, if you constrain the `crdb_region` column to a single value, CockroachDB can plan an inverted join:

```
> EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON st_contains(t1.geom, t2.geom) AND t2.crdb_region = 'us-east1';
                       info
--------------------------------------------------
  distribution: full
  vectorized: true

  • lookup join (left outer)
  │ table: t2@primary
  │ equality: (crdb_region, k) = (crdb_region,k)
  │ equality cols are key
  │ pred: st_contains(geom, geom)
  │
  └── • inverted join (left outer)
      │ table: t2@geom_idx
      │
      └── • render
          │
          └── • scan
                estimated row count: 1,000
                table: t1@primary
                spans: FULL SCAN
(18 rows)
```

If you do not know which region to use, you can combine queries with <InternalLink path="selection-queries#union-combine-two-queries">`UNION ALL`</InternalLink>:

```
> EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON st_contains(t1.geom, t2.geom) AND t2.crdb_region = 'us-east1'
UNION ALL SELECT * FROM t1 LEFT JOIN t2 ON st_contains(t1.geom, t2.geom) AND t2.crdb_region = 'us-west1'
UNION ALL SELECT * FROM t1 LEFT JOIN t2 ON st_contains(t1.geom, t2.geom) AND t2.crdb_region = 'europe-west1';
                           info
----------------------------------------------------------
  distribution: full
  vectorized: true

  • union all
  │
  ├── • union all
  │   │
  │   ├── • lookup join (left outer)
  │   │   │ table: t2@primary
  │   │   │ equality: (crdb_region, k) = (crdb_region,k)
  │   │   │ equality cols are key
  │   │   │ pred: st_contains(geom, geom)
  │   │   │
  │   │   └── • inverted join (left outer)
  │   │       │ table: t2@geom_idx
  │   │       │
  │   │       └── • render
  │   │           │
  │   │           └── • scan
  │   │                 estimated row count: 1,000
  │   │                 table: t1@primary
  │   │                 spans: FULL SCAN
  │   │
  │   └── • lookup join (left outer)
  │       │ table: t2@primary
  │       │ equality: (crdb_region, k) = (crdb_region,k)
  │       │ equality cols are key
  │       │ pred: st_contains(geom, geom)
  │       │
  │       └── • inverted join (left outer)
  │           │ table: t2@geom_idx
  │           │
  │           └── • render
  │               │
  │               └── • scan
  │                     estimated row count: 1,000
  │                     table: t1@primary
  │                     spans: FULL SCAN
  │
  └── • lookup join (left outer)
      │ table: t2@primary
      │ equality: (crdb_region, k) = (crdb_region,k)
      │ equality cols are key
      │ pred: st_contains(geom, geom)
      │
      └── • inverted join (left outer)
          │ table: t2@geom_idx
          │
          └── • render
              │
              └── • scan
                    estimated row count: 1,000
                    table: t1@primary
                    spans: FULL SCAN
(54 rows)
```

#### Locality optimized search limitations

* <InternalLink path="cost-based-optimizer#locality-optimized-search-in-multi-region-clusters">Locality optimized search</InternalLink> does not work for queries that use <InternalLink path="partitioning#partition-using-a-secondary-index">partitioned unique indexes</InternalLink> on <InternalLink path="computed-columns">virtual computed columns</InternalLink>. A workaround for computed columns is to make the virtual computed column a <InternalLink path="computed-columns">stored computed column</InternalLink>. Locality optimized search does not work for queries that use partitioned unique <InternalLink path="expression-indexes">expression indexes</InternalLink>.

* <InternalLink path="cost-based-optimizer#locality-optimized-search-in-multi-region-clusters">Locality optimized search</InternalLink> works only for queries selecting a limited number of records (up to 100,000 unique keys).

#### Query plans for materialized views

* The optimizer may not select the most optimal query plan when querying materialized views because CockroachDB does not <InternalLink path="cost-based-optimizer#table-statistics">collect statistics</InternalLink> on materialized views.

#### Inverted join for `tsvector` and `tsquery` types is not supported

CockroachDB cannot index-accelerate queries with `@@` predicates when both sides of the operator are variables.
