Skip to content

Commit 8502150

Browse files
committed
Add docs for ALTER TABLE ... SCATTER
(also `ALTER INDEX ... SCATTER`) Fixes DOC-286
1 parent c5383da commit 8502150

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

src/current/v25.2/alter-index.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Subcommand | Description |
3838
[`CONFIGURE ZONE`](#configure-zone) | [Replication Controls]({% link {{ page.version.version }}/configure-replication-zones.md %}) for an index. |
3939
[`PARTITION BY`](#partition-by) | Partition, re-partition, or un-partition an index.
4040
[`RENAME TO`](#rename-to) | Change the name of an index.
41+
[`SCATTER`](#scatter) | Redistribute leaseholders for the ranges of a table or index. |
4142
[`SPLIT AT`](#split-at) | Force a [range split]({% link {{ page.version.version }}/architecture/distribution-layer.md %}#range-splits) at the specified row in the index.
4243
[`UNSPLIT AT`](#unsplit-at) | Remove a range split enforcement in the index.
4344
[`VISIBILITY`](#visibility) | Set the visibility of an index between a range of `0.0` and `1.0`.
@@ -119,6 +120,30 @@ The user must have the `CREATE` [privilege]({% link {{ page.version.version }}/s
119120

120121
For usage, see [Synopsis](#synopsis).
121122

123+
### `SCATTER`
124+
125+
`ALTER INDEX ... SCATTER` runs a specified set of ranges for a table or index through the [replication layer]({% link {{ page.version.version }}/architecture/replication-layer.md %}) queue. If many ranges have been created recently, the replication queue may transfer some leases to other replicas to balance load across the cluster. Some leaseholders may not update as a result of this command.
126+
127+
{{site.data.alerts.callout_info}}
128+
`SCATTER` has the potential to result in data movement proportional to the size of the table or index being scattered, thus taking additional time and resources to complete.
129+
{{site.data.alerts.end}}
130+
131+
For examples, see [Scatter indexes](#scatter-indexes).
132+
133+
#### Required privileges
134+
135+
The user must have the `INSERT` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the table or index.
136+
137+
#### Parameters
138+
139+
Parameter | Description
140+
----------|-------------
141+
`table_name` | The name of the table that you want to scatter.
142+
`table_index_name` | The name of the index that you want to scatter.
143+
`expr_list` | A list of [scalar expressions]({% link {{ page.version.version }}/scalar-expressions.md %}) in the form of the primary key of the table or the specified index.
144+
145+
For usage, see [Synopsis](#synopsis).
146+
122147
### `SPLIT AT`
123148

124149
`ALTER INDEX ... SPLIT AT` forces a [range split]({% link {{ page.version.version }}/architecture/distribution-layer.md %}#range-splits) at a specified row in the index.
@@ -343,6 +368,39 @@ SHOW INDEXES FROM users;
343368
(8 rows)
344369
~~~
345370

371+
### Scatter indexes
372+
373+
Before scattering, you can view the current leaseholder distribution for an index:
374+
375+
{% include_cached copy-clipboard.html %}
376+
~~~ sql
377+
WITH range_details AS (SHOW RANGES FROM DATABASE movr WITH DETAILS) SELECT range_id, lease_holder, replicas from range_details;
378+
~~~
379+
380+
~~~
381+
range_id | lease_holder | replicas
382+
-----------+--------------+-----------
383+
94 | 1 | {1}
384+
~~~
385+
386+
{% include_cached copy-clipboard.html %}
387+
~~~ sql
388+
> ALTER INDEX rides@revenue_idx SCATTER;
389+
~~~
390+
391+
After scattering, recheck the leaseholder distribution:
392+
393+
{% include_cached copy-clipboard.html %}
394+
~~~ sql
395+
WITH range_details AS (SHOW RANGES FROM DATABASE movr WITH DETAILS) SELECT range_id, lease_holder, replicas from range_details;
396+
~~~
397+
398+
~~~
399+
range_id | lease_holder | replicas
400+
-----------+--------------+-----------
401+
94 | 1 | {1}
402+
~~~
403+
346404
### Split and unsplit indexes
347405

348406
{% include {{ page.version.version }}/sql/movr-statements-geo-partitioned-replicas.md %}

src/current/v25.2/alter-table.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Subcommand | Description | Can combine with other subcommands?
6565
[`SET {storage parameter}`](#set-storage-parameter) | Set a storage parameter on a table. | Yes
6666
[`SET LOCALITY`](#set-locality) | Set the table locality for a table in a [multi-region database]({% link {{ page.version.version }}/multiregion-overview.md %}). | No
6767
[`SET SCHEMA`](#set-schema) | Change the [schema]({% link {{ page.version.version }}/sql-name-resolution.md %}) of a table. | No
68+
[`SCATTER`](#scatter) | Redistribute leaseholders for the ranges of a table or index. | No
6869
[`SPLIT AT`](#split-at) | Force a [range split]({% link {{ page.version.version }}/architecture/distribution-layer.md %}#range-splits) at the specified row in the table. | No
6970
[`UNSPLIT AT`](#unsplit-at) | Remove a range split enforcement in the table. | No
7071
[`VALIDATE CONSTRAINT`](#validate-constraint) | Check whether values in a column match a [constraint]({% link {{ page.version.version }}/constraints.md %}) on the column. | Yes
@@ -602,6 +603,30 @@ Parameter | Description |
602603

603604
For usage, see [Synopsis](#synopsis).
604605

606+
### `SCATTER`
607+
608+
`ALTER TABLE ... SCATTER` runs a specified set of ranges for a table or index through the [replication layer]({% link {{ page.version.version }}/architecture/replication-layer.md %}) queue. If many ranges have been created recently, the replication queue may transfer some leases to other replicas to balance load across the cluster. Some leaseholders may not update as a result of this command.
609+
610+
{{site.data.alerts.callout_info}}
611+
`SCATTER` has the potential to result in data movement proportional to the size of the table or index being scattered, thus taking additional time and resources to complete.
612+
{{site.data.alerts.end}}
613+
614+
For examples, see [Scatter tables](#scatter-tables).
615+
616+
#### Required privileges
617+
618+
The user must have the `INSERT` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the table or index.
619+
620+
#### Parameters
621+
622+
Parameter | Description
623+
----------|-------------
624+
`table_name` | The name of the table that you want to scatter.
625+
`table_index_name` | The name of the index that you want to scatter.
626+
`expr_list` | A list of [scalar expressions]({% link {{ page.version.version }}/scalar-expressions.md %}) in the form of the primary key of the table or the specified index.
627+
628+
For usage, see [Synopsis](#synopsis).
629+
605630
### `SPLIT AT`
606631

607632
`ALTER TABLE ... SPLIT AT` forces a [range split]({% link {{ page.version.version }}/architecture/distribution-layer.md %}#range-splits) at a specified row in the table.
@@ -2827,6 +2852,57 @@ Then, change the table's schema:
28272852
(6 rows)
28282853
~~~
28292854
2855+
### Scatter tables
2856+
2857+
Before scattering, you can view the current leaseholder distribution for a table:
2858+
2859+
{% include_cached copy-clipboard.html %}
2860+
~~~ sql
2861+
WITH range_details AS (SHOW RANGES FROM TABLE movr.users WITH DETAILS) SELECT range_id, lease_holder, replicas from range_details;
2862+
~~~
2863+
2864+
~~~
2865+
range_id | lease_holder | replicas
2866+
-----------+--------------+-----------
2867+
99 | 1 | {1}
2868+
82 | 1 | {1}
2869+
81 | 1 | {1}
2870+
77 | 1 | {1}
2871+
80 | 1 | {1}
2872+
75 | 1 | {1}
2873+
79 | 1 | {1}
2874+
76 | 1 | {1}
2875+
78 | 1 | {1}
2876+
(9 rows)
2877+
~~~
2878+
2879+
{% include_cached copy-clipboard.html %}
2880+
~~~ sql
2881+
ALTER TABLE movr.users SCATTER;
2882+
~~~
2883+
2884+
After scattering, recheck the leaseholder distribution:
2885+
2886+
{% include_cached copy-clipboard.html %}
2887+
~~~ sql
2888+
WITH range_details AS (SHOW RANGES FROM TABLE movr.users WITH DETAILS) SELECT range_id, lease_holder, replicas from range_details;
2889+
~~~
2890+
2891+
~~~
2892+
range_id | lease_holder | replicas
2893+
-----------+--------------+-----------
2894+
99 | 1 | {1}
2895+
82 | 1 | {1}
2896+
81 | 1 | {1}
2897+
77 | 1 | {1}
2898+
80 | 1 | {1}
2899+
75 | 1 | {1}
2900+
79 | 1 | {1}
2901+
76 | 1 | {1}
2902+
78 | 1 | {1}
2903+
(9 rows)
2904+
~~~
2905+
28302906
### Split and unsplit tables
28312907
28322908
{% include {{page.version.version}}/sql/movr-statements-geo-partitioned-replicas.md %}

0 commit comments

Comments
 (0)