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

# SHOW RANGE FOR ROW

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

export const version = "v26.1";

The `SHOW RANGE... FOR ROW` <InternalLink path="sql-statements">statement</InternalLink> shows information about a <InternalLink path="architecture/overview">range</InternalLink> for a single row in a table or index. This information is useful for verifying how SQL data maps to underlying ranges, and where the replicas for a range are located.

<Note>
  **This feature is in <InternalLink path="cockroachdb-feature-availability">preview</InternalLink>** and subject to change. To share feedback and/or issues, contact [Support](https://support.cockroachlabs.com).
</Note>

<Note>
  To show information about the ranges for all data in a table, index, or database, use the <InternalLink path="show-ranges">`SHOW RANGES`</InternalLink> statement.
</Note>

## Syntax

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SHOW RANGE FROM TABLE

FOR ROW (value1, value2, ...)
SHOW RANGE FROM INDEX [  @ ]  FOR ROW (value1, value2, ...)
```

## Required privileges

The user must have the `SELECT` <InternalLink path="security-reference/authorization#managing-privileges">privilege</InternalLink> on the target table.

## Parameters

| Parameter               | Description                                                                                                                                                                       |
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `tablename`             | The name of the table that contains the row that you want range information about.                                                                                                |
| `indexname`             | The name of the index that contains the row that you want range information about.                                                                                                |
| `(value1, value2, ...)` | The values of the indexed columns of the row that you want range information about, as a tuple. In previous releases, this statement required the values of all columns of a row. |

## Response

The following fields are returned:

| Field                     | Description                                                                                               |
| ------------------------- | --------------------------------------------------------------------------------------------------------- |
| `start\_key`              | The start key for the range.                                                                              |
| `end\_key`                | The end key for the range.                                                                                |
| `range\_id`               | The range ID.                                                                                             |
| `lease\_holder`           | The node that contains the range's <InternalLink path="architecture/overview">leaseholder</InternalLink>. |
| `lease\_holder\_locality` | The <InternalLink path="cockroach-start#locality">locality</InternalLink> of the leaseholder.             |
| `replicas`                | The nodes that contain the range <InternalLink path="architecture/overview">replicas</InternalLink>.      |
| `replica\_localities`     | The <InternalLink path="cockroach-start#locality">locality</InternalLink> of the range.                   |

## Examples

#### Setup

To follow along, run <InternalLink path="cockroach-demo">`cockroach demo`</InternalLink> to start a temporary, in-memory cluster with the <InternalLink path="movr">`movr`</InternalLink> sample dataset preloaded:

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

### Show range information for a row in a table

To show information about a row in a table, you must know the values of the columns in the row's primary key:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SHOW INDEX FROM vehicles;
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  table_name |              index_name               | non_unique | seq_in_index | column_name | direction | storing | implicit
-------------+---------------------------------------+------------+--------------+-------------+-----------+---------+-----------
  vehicles   | vehicles_pkey                         |   false    |            1 | city             | ASC       |  false  |  false
  vehicles   | vehicles_pkey                         |   false    |            2 | id               | ASC       |  false  |  false
  vehicles   | vehicles_pkey                         |   false    |            3 | type             | N/A       |  true   |  false
  vehicles   | vehicles_pkey                         |   false    |            4 | owner_id         | N/A       |  true   |  false
  vehicles   | vehicles_pkey                         |   false    |            5 | creation_time    | N/A       |  true   |  false
  vehicles   | vehicles_pkey                         |   false    |            6 | status           | N/A       |  true   |  false
  vehicles   | vehicles_pkey                         |   false    |            7 | current_location | N/A       |  true   |  false
  vehicles   | vehicles_pkey                         |   false    |            8 | ext              | N/A       |  true   |  false
  vehicles   | vehicles_auto_index_fk_city_ref_users |    true    |            1 | city             | ASC       |  false  |  false
  vehicles   | vehicles_auto_index_fk_city_ref_users |    true    |            2 | owner_id         | ASC       |  false  |  false
  vehicles   | vehicles_auto_index_fk_city_ref_users |    true    |            3 | id               | ASC       |  false  |   true
(11 rows)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SELECT city, id FROM vehicles LIMIT 5;
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
     city     |                  id
--------------+---------------------------------------
  amsterdam   | bbbbbbbb-bbbb-4800-8000-00000000000b
  amsterdam   | aaaaaaaa-aaaa-4800-8000-00000000000a
  boston      | 22222222-2222-4200-8000-000000000002
  boston      | 33333333-3333-4400-8000-000000000003
  los angeles | 99999999-9999-4800-8000-000000000009
(5 rows)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SHOW RANGE FROM TABLE vehicles FOR ROW (
    'boston',
    '22222222-2222-4200-8000-000000000002'
  );
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
                            start_key                           |                         end_key                         | range_id | lease_holder | lease_holder_locality | replicas |    replica_localities
----------------------------------------------------------------+---------------------------------------------------------+----------+--------------+-----------------------+----------+---------------------------
  /"boston"/"\"\"\"\"\"\"B\x00\x80\x00\x00\x00\x00\x00\x00\x02" | /"boston"/"333333D\x00\x80\x00\x00\x00\x00\x00\x00\x03" |       57 |            1 | region=us-east1,az=b  | {1}      | {"region=us-east1,az=b"}
(1 row)
```

### Show range information for a row by a secondary index

To show information about a row in a secondary index, you must know the values of the indexed columns:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SHOW INDEX FROM vehicles;
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  table_name |              index_name               | non_unique | seq_in_index | column_name | direction | storing | implicit
-------------+---------------------------------------+------------+--------------+-------------+-----------+---------+-----------
  vehicles   | vehicles_pkey                         |   false    |            1 | city             | ASC       |  false  |  false
  vehicles   | vehicles_pkey                         |   false    |            2 | id               | ASC       |  false  |  false
  vehicles   | vehicles_pkey                         |   false    |            3 | type             | N/A       |  true   |  false
  vehicles   | vehicles_pkey                         |   false    |            4 | owner_id         | N/A       |  true   |  false
  vehicles   | vehicles_pkey                         |   false    |            5 | creation_time    | N/A       |  true   |  false
  vehicles   | vehicles_pkey                         |   false    |            6 | status           | N/A       |  true   |  false
  vehicles   | vehicles_pkey                         |   false    |            7 | current_location | N/A       |  true   |  false
  vehicles   | vehicles_pkey                         |   false    |            8 | ext              | N/A       |  true   |  false
  vehicles   | vehicles_auto_index_fk_city_ref_users |    true    |            1 | city             | ASC       |  false  |  false
  vehicles   | vehicles_auto_index_fk_city_ref_users |    true    |            2 | owner_id         | ASC       |  false  |  false
  vehicles   | vehicles_auto_index_fk_city_ref_users |    true    |            3 | id               | ASC       |  false  |   true
(11 rows)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SELECT city, owner_id, id FROM vehicles@vehicles_auto_index_fk_city_ref_users LIMIT 5;
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
     city     |               owner_id               |                  id
--------------+--------------------------------------+---------------------------------------
  amsterdam   | bd70a3d7-0a3d-4000-8000-000000000025 | bbbbbbbb-bbbb-4800-8000-00000000000b
  amsterdam   | c28f5c28-f5c2-4000-8000-000000000026 | aaaaaaaa-aaaa-4800-8000-00000000000a
  boston      | 2e147ae1-47ae-4400-8000-000000000009 | 22222222-2222-4200-8000-000000000002
  boston      | 33333333-3333-4400-8000-00000000000a | 33333333-3333-4400-8000-000000000003
  los angeles | 9eb851eb-851e-4800-8000-00000000001f | 99999999-9999-4800-8000-000000000009
(5 rows)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SHOW RANGE FROM INDEX vehicles@vehicles_auto_index_fk_city_ref_users FOR ROW (
    'boston',
    '2e147ae1-47ae-4400-8000-000000000009',
    '22222222-2222-4200-8000-000000000002'
  );
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  start_key | end_key | range_id | lease_holder | lease_holder_locality | replicas |    replica_localities
------------+---------+----------+--------------+-----------------------+----------+---------------------------
  NULL      | NULL    |       53 |            1 | region=us-east1,az=b  | {1}      | {"region=us-east1,az=b"}
```

## See also

* <InternalLink path="show-ranges">`SHOW RANGES`</InternalLink>
* <InternalLink path="alter-table#split-at">`ALTER TABLE... SPLIT AT`</InternalLink>
* <InternalLink path="alter-index#split-at">`ALTER INDEX... SPLIT AT`</InternalLink>
* <InternalLink path="create-table">`CREATE TABLE`</InternalLink>
* <InternalLink path="create-index">`CREATE INDEX`</InternalLink>
* <InternalLink path="indexes">Indexes</InternalLink>
* <InternalLink path="partitioning">Partitioning tables</InternalLink>
* <InternalLink path="architecture/overview">Architecture Overview</InternalLink>
