You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/current/v25.4/alter-sequence.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,9 @@ The `ALTER SEQUENCE` [statement]({% link {{ page.version.version }}/sql-statemen
29
29
`RENAME TO sequence_name` | Rename the sequence to `sequence_name`, which must be unique to its database and follow these [identifier rules]({% link {{ page.version.version }}/keywords-and-identifiers.md %}#identifiers). Name changes do not propagate to the table(s) using the sequence.<br><br>Note that `RENAME TO` can be used to move a sequence from one database to another, but it cannot be used to move a sequence from one schema to another. To change a sequence's schema, use `ALTER SEQUENCE ...SET SCHEMA` instead.
30
30
`CYCLE`/`NO CYCLE` | The sequence will wrap around when the sequence value reaches the maximum or minimum value. `CYCLE` is not implemented. If `NO CYCLE` is set, the sequence will not wrap.
31
31
`OWNED BY column_name` | Associates the sequence to a particular column. If that column or its parent table is dropped, the sequence will also be dropped.<br><br>Specifying an owner column with `OWNED BY` replaces any existing owner column on the sequence. To remove existing column ownership on the sequence and make the column free-standing, specify `OWNED BY NONE`.<br><br>**Default:**`NONE`
32
-
`CACHE` | The number of sequence values to cache in memory for reuse in the session. A cache size of `1` means that there is no cache, and cache sizes of less than `1` are not valid.<br><br>**Default:**`1` (sequences are not cached by default)
32
+
`CACHE` <aname="cache"></a> | The number of sequence values to cache in memory at the [node]({% link {{ page.version.version }}/architecture/overview.md %}#node) level. All sessions on the node share the same cache, which can be concurrently accessed, and which reduces the chance of creating large gaps between generated IDs. A cache size of `1` means that there is no cache, and cache sizes of less than `1` are not valid.<br><br>**Default:**`1` (sequences are not cached by default). By default, this caches sequences per node. To cache sequence values per session, use [`PER SESSION CACHE`](#per-session-cache) explicitly.
33
+
`PER NODE CACHE` <aname="per-node-cache"></a> | The number of sequence values to cache in memory at the node level. All sessions on the node share the same cache, which can be concurrently accessed, and which reduces the chance of creating large gaps between generated IDs. A cache size of `1` means that there is no cache, and cache sizes of less than `1` are not valid. This is the default caching strategy, and is equivalent to specifying `CACHE`.
34
+
`PER SESSION CACHE` <aname="per-session-cache"></a> | The number of sequence values to cache in memory for reuse within a single [session]({% link {{ page.version.version }}/show-sessions.md %}). A cache size of `1` means that there is no cache, and cache sizes of less than `1` are not valid.
33
35
`MINVALUE` | The new minimum value of the sequence. <br><br>**Default:**`1`
34
36
`MAXVALUE` | The new maximum value of the sequence. <br><br>**Default:**`9223372036854775807`
35
37
`INCREMENT` | The new value by which the sequence is incremented. A negative number creates a descending sequence. A positive number creates an ascending sequence.
Copy file name to clipboardExpand all lines: src/current/v25.4/create-sequence.md
+32-10Lines changed: 32 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,8 +37,9 @@ The user must have the `CREATE` [privilege]({% link {{ page.version.version }}/s
37
37
`START [WITH]` | The first value of the sequence. <br><br>**Default for ascending:**`1` <br><br>**Default for descending:**`-1`
38
38
`RESTART [WITH]` | Sets `nextval` to the specified number, or back to the original `START` value.
39
39
`NO CYCLE` | All sequences are set to `NO CYCLE` and the sequence will not wrap.
40
-
`CACHE` | The number of sequence values to cache in memory for reuse in the session. A cache size of `1` means that there is no cache, and cache sizes of less than `1` are not valid.<br><br>**Default:**`1` (sequences are not cached by default)
41
-
`PER NODE CACHE` <aname="per-node-cache"></a> | The number of sequence values to cache in memory at the node level. All sessions on the node share the same cache, which can be concurrently accessed, and which reduces the chance of creating large gaps between generated IDs. A cache size of `1` means that there is no cache, and cache sizes of less than `1` are not valid.<br><br>**Default:**`256` (controlled by the [cluster setting]({% link {{ page.version.version }}/cluster-settings.md %}) `sql.defaults.serial_sequences_cache_size` when the [session variable]({% link {{ page.version.version }}/set-vars.md %}) `serial_normalization` is set to `sql_sequence_cached_node`)
40
+
`CACHE` <aname="cache"></a> | The number of sequence values to cache in memory at the [node]({% link {{ page.version.version }}/architecture/overview.md %}#node) level. All sessions on the node share the same cache, which can be concurrently accessed, and which reduces the chance of creating large gaps between generated IDs. A cache size of `1` means that there is no cache, and cache sizes of less than `1` are not valid.<br><br>**Default:**`1` (sequences are not cached by default). By default, this caches sequences per node. To cache sequence values per session, use [`PER SESSION CACHE`](#per-session-cache) explicitly.
41
+
`PER NODE CACHE` <aname="per-node-cache"></a> | The number of sequence values to cache in memory at the node level. All sessions on the node share the same cache, which can be concurrently accessed, and which reduces the chance of creating large gaps between generated IDs. A cache size of `1` means that there is no cache, and cache sizes of less than `1` are not valid. This is the default caching strategy, and is equivalent to specifying `CACHE`.
42
+
`PER SESSION CACHE` <aname="per-session-cache"></a> | The number of sequence values to cache in memory for reuse within a single [session]({% link {{ page.version.version }}/show-sessions.md %}). A cache size of `1` means that there is no cache, and cache sizes of less than `1` are not valid.
42
43
`OWNED BY column_name` <aname="owned-by"></a> | Associates the sequence to a particular column. If that column or its parent table is dropped, the sequence will also be dropped.<br>Specifying an owner column with `OWNED BY` replaces any existing owner column on the sequence. To remove existing column ownership on the sequence and make the column free-standing, specify `OWNED BY NONE`.<br><br>**Default:**`NONE`
43
44
`opt_temp` | Defines the sequence as a session-scoped temporary sequence. For more information, see [Temporary sequences](#temporary-sequences).
44
45
@@ -274,20 +275,20 @@ In this example, we create a sequence that starts at -1 and descends in incremen
274
275
(3 rows)
275
276
~~~
276
277
277
-
### Cache sequence values in memory
278
+
### Cache sequence values in memory (per node)
278
279
279
-
For improved performance, use the `CACHE` keyword to cache sequence values in memory.
280
+
For improved performance, use the [`CACHE`](#cache) keyword to cache sequence values in memory at the node level. By default, all sessions on a node share the same cache. If you want sequence values to be cached per session, see [Cache sequence values per session](#cache-sequence-values-per-session).
280
281
281
-
For example, to cache 10 sequence values in memory:
282
+
For example, to cache 10 sequence values in memory per node:
282
283
283
284
{% include_cached copy-clipboard.html %}
284
285
~~~sql
285
-
>CREATE SEQUENCE customer_seq_cached CACHE 10;
286
+
CREATESEQUENCEcustomer_seq_cached CACHE 10;
286
287
~~~
287
288
288
289
{% include_cached copy-clipboard.html %}
289
290
~~~sql
290
-
>SHOW CREATE customer_seq_cached;
291
+
SHOW CREATE customer_seq_cached;
291
292
~~~
292
293
293
294
~~~
@@ -297,9 +298,7 @@ For example, to cache 10 sequence values in memory:
297
298
(1 row)
298
299
~~~
299
300
300
-
### Cache sequence values per node
301
-
302
-
For improved performance, use the `PER NODE CACHE` clause to cache sequence values in memory at the node level.
301
+
You can also use the [`PER NODE CACHE` clause](#per-node-cache) to explicitly cache sequence values in memory at the node level. Since this is the default strategy, it is equivalent to using [`CACHE`](#cache).
303
302
304
303
For example, to cache 10 sequence values per node:
305
304
@@ -320,6 +319,29 @@ SHOW CREATE customer_seq_node_cached;
320
319
(1 row)
321
320
~~~
322
321
322
+
### Cache sequence values per session
323
+
324
+
To cache sequence values within a single session, use the [`PER SESSION CACHE` clause](#per-session-cache).
325
+
326
+
For example, to cache 10 sequence values per session:
327
+
328
+
{% include_cached copy-clipboard.html %}
329
+
~~~sql
330
+
CREATESEQUENCEcustomer_seq_session_cached PER SESSION CACHE 10;
0 commit comments