Skip to content

Commit

Permalink
sql: add a way for sequence caching to be per-node
Browse files Browse the repository at this point in the history
Previously, the sequence CACHE implementation caches IDs per-session. This can be wasteful since a single increment will allocate extra space within the sequences for each session. Depending on the use cases, a node-level cache would be more effective and minimize the number of wasted sequence values.

Epic: CRDB-20209
Fixes: #89338

Release note (sql change): Added an option for node-level sequence caching. All the sessions on the node can share the same cache, which can be concurrently accessed. The syntax for this option is [ [ PER NODE ] CACHE # ] or serial_normalization setting for sql_sequence_cached_node.
  • Loading branch information
jasminejsun committed Feb 1, 2024
1 parent b6d1474 commit 28d4471
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/generated/settings/settings-for-tenants.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ This session variable default should now be configured using ALTER ROLE... SET:
sql.defaults.results_buffer.size byte size 16 KiB "default size of the buffer that accumulates results for a statement or a batch of statements before they are sent to the client. This can be overridden on an individual connection with the 'results_buffer_size' parameter. Note that auto-retries generally only happen while no results have been delivered to the client, so reducing this size can increase the number of retriable errors a client receives. On the other hand, increasing the buffer size can increase the delay until the client receives the first result row. Updating the setting only affects new connections. Setting to 0 disables any buffering.
This cluster setting is being kept to preserve backwards-compatibility.
This session variable default should now be configured using ALTER ROLE... SET: https://www.cockroachlabs.com/docs/stable/alter-role.html" application
sql.defaults.serial_normalization enumeration rowid "default handling of SERIAL in table definitions [rowid = 0, virtual_sequence = 1, sql_sequence = 2, sql_sequence_cached = 3, unordered_rowid = 4]
sql.defaults.serial_normalization enumeration rowid "default handling of SERIAL in table definitions [rowid = 0, virtual_sequence = 1, sql_sequence = 2, sql_sequence_cached = 3, unordered_rowid = 4, sql_sequence_node_cached = 5]
This cluster setting is being kept to preserve backwards-compatibility.
This session variable default should now be configured using ALTER ROLE... SET: https://www.cockroachlabs.com/docs/stable/alter-role.html" application
sql.defaults.statement_timeout duration 0s "default value for the statement_timeout; default value for the statement_timeout session setting; controls the duration a query is permitted to run before it is canceled; if set to 0, there is no timeout
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
<tr><td><div id="setting-sql-defaults-reorder-joins-limit" class="anchored"><code>sql.defaults.reorder_joins_limit</code></div></td><td>integer</td><td><code>8</code></td><td>default number of joins to reorder<br/>This cluster setting is being kept to preserve backwards-compatibility.<br/>This session variable default should now be configured using <a href="alter-role.html"><code>ALTER ROLE... SET</code></a></td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-defaults-require-explicit-primary-keys-enabled" class="anchored"><code>sql.defaults.require_explicit_primary_keys.enabled</code></div></td><td>boolean</td><td><code>false</code></td><td>default value for requiring explicit primary keys in CREATE TABLE statements<br/>This cluster setting is being kept to preserve backwards-compatibility.<br/>This session variable default should now be configured using <a href="alter-role.html"><code>ALTER ROLE... SET</code></a></td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-defaults-results-buffer-size" class="anchored"><code>sql.defaults.results_buffer.size</code></div></td><td>byte size</td><td><code>16 KiB</code></td><td>default size of the buffer that accumulates results for a statement or a batch of statements before they are sent to the client. This can be overridden on an individual connection with the &#39;results_buffer_size&#39; parameter. Note that auto-retries generally only happen while no results have been delivered to the client, so reducing this size can increase the number of retriable errors a client receives. On the other hand, increasing the buffer size can increase the delay until the client receives the first result row. Updating the setting only affects new connections. Setting to 0 disables any buffering.<br/>This cluster setting is being kept to preserve backwards-compatibility.<br/>This session variable default should now be configured using <a href="alter-role.html"><code>ALTER ROLE... SET</code></a></td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-defaults-serial-normalization" class="anchored"><code>sql.defaults.serial_normalization</code></div></td><td>enumeration</td><td><code>rowid</code></td><td>default handling of SERIAL in table definitions [rowid = 0, virtual_sequence = 1, sql_sequence = 2, sql_sequence_cached = 3, unordered_rowid = 4]<br/>This cluster setting is being kept to preserve backwards-compatibility.<br/>This session variable default should now be configured using <a href="alter-role.html"><code>ALTER ROLE... SET</code></a></td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-defaults-serial-normalization" class="anchored"><code>sql.defaults.serial_normalization</code></div></td><td>enumeration</td><td><code>rowid</code></td><td>default handling of SERIAL in table definitions [rowid = 0, virtual_sequence = 1, sql_sequence = 2, sql_sequence_cached = 3, unordered_rowid = 4, sql_sequence_node_cached = 5]<br/>This cluster setting is being kept to preserve backwards-compatibility.<br/>This session variable default should now be configured using <a href="alter-role.html"><code>ALTER ROLE... SET</code></a></td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-defaults-statement-timeout" class="anchored"><code>sql.defaults.statement_timeout</code></div></td><td>duration</td><td><code>0s</code></td><td>default value for the statement_timeout; default value for the statement_timeout session setting; controls the duration a query is permitted to run before it is canceled; if set to 0, there is no timeout<br/>This cluster setting is being kept to preserve backwards-compatibility.<br/>This session variable default should now be configured using <a href="alter-role.html"><code>ALTER ROLE... SET</code></a></td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-defaults-stub-catalog-tables-enabled" class="anchored"><code>sql.defaults.stub_catalog_tables.enabled</code></div></td><td>boolean</td><td><code>true</code></td><td>default value for stub_catalog_tables session setting<br/>This cluster setting is being kept to preserve backwards-compatibility.<br/>This session variable default should now be configured using <a href="alter-role.html"><code>ALTER ROLE... SET</code></a></td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-defaults-super-regions-enabled" class="anchored"><code>sql.defaults.super_regions.enabled</code></div></td><td>boolean</td><td><code>false</code></td><td>default value for enable_super_regions; allows for the usage of super regions<br/>This cluster setting is being kept to preserve backwards-compatibility.<br/>This session variable default should now be configured using <a href="alter-role.html"><code>ALTER ROLE... SET</code></a></td><td>Serverless/Dedicated/Self-Hosted</td></tr>
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/sql/bnf/alter_sequence.bnf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
alter_sequence_stmt ::=
( 'ALTER' 'SEQUENCE' sequence_name 'RENAME' 'TO' sequence_name | 'ALTER' 'SEQUENCE' 'IF' 'EXISTS' sequence_name 'RENAME' 'TO' sequence_name )
| ( 'ALTER' 'SEQUENCE' sequence_name ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) )* ) | 'ALTER' 'SEQUENCE' 'IF' 'EXISTS' sequence_name ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) )* ) )
| ( 'ALTER' 'SEQUENCE' sequence_name ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) )* ) | 'ALTER' 'SEQUENCE' 'IF' 'EXISTS' sequence_name ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) )* ) )
| ( 'ALTER' 'SEQUENCE' sequence_name 'SET' 'SCHEMA' schema_name | 'ALTER' 'SEQUENCE' 'IF' 'EXISTS' sequence_name 'SET' 'SCHEMA' schema_name )
| ( 'ALTER' 'SEQUENCE' sequence_name 'OWNER' 'TO' role_spec | 'ALTER' 'SEQUENCE' 'IF' 'EXISTS' sequence_name 'OWNER' 'TO' role_spec )
4 changes: 2 additions & 2 deletions docs/generated/sql/bnf/create_sequence_stmt.bnf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
create_sequence_stmt ::=
'CREATE' opt_temp 'SEQUENCE' sequence_name ( ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) )* ) | )
| 'CREATE' opt_temp 'SEQUENCE' 'IF' 'NOT' 'EXISTS' sequence_name ( ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) )* ) | )
'CREATE' opt_temp 'SEQUENCE' sequence_name ( ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) )* ) | )
| 'CREATE' opt_temp 'SEQUENCE' 'IF' 'NOT' 'EXISTS' sequence_name ( ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) )* ) | )
5 changes: 5 additions & 0 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,7 @@ unreserved_keyword ::=
| 'NOCREATEROLE'
| 'NOCONTROLCHANGEFEED'
| 'NOCONTROLJOB'
| 'NODE'
| 'NOLOGIN'
| 'NOMODIFYCLUSTERSETTING'
| 'NONVOTERS'
Expand Down Expand Up @@ -1317,6 +1318,7 @@ unreserved_keyword ::=
| 'PASSWORD'
| 'PAUSE'
| 'PAUSED'
| 'PER'
| 'PHYSICAL'
| 'PLACEMENT'
| 'PLAN'
Expand Down Expand Up @@ -3443,6 +3445,7 @@ sequence_option_elem ::=
| 'OWNED' 'BY' 'NONE'
| 'OWNED' 'BY' column_path
| 'CACHE' signed_iconst64
| 'PER' 'NODE' 'CACHE' signed_iconst64
| 'INCREMENT' signed_iconst64
| 'INCREMENT' 'BY' signed_iconst64
| 'MINVALUE' signed_iconst64
Expand Down Expand Up @@ -3887,6 +3890,7 @@ bare_label_keywords ::=
| 'NOCREATEDB'
| 'NOCREATELOGIN'
| 'NOCREATEROLE'
| 'NODE'
| 'NOLOGIN'
| 'NOMODIFYCLUSTERSETTING'
| 'NONE'
Expand Down Expand Up @@ -3933,6 +3937,7 @@ bare_label_keywords ::=
| 'PASSWORD'
| 'PAUSE'
| 'PAUSED'
| 'PER'
| 'PHYSICAL'
| 'PLACEMENT'
| 'PLACING'
Expand Down
11 changes: 6 additions & 5 deletions pkg/sql/exec_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,12 @@ var SerialNormalizationMode = settings.RegisterEnumSetting(
"default handling of SERIAL in table definitions",
"rowid",
map[int64]string{
int64(sessiondatapb.SerialUsesRowID): "rowid",
int64(sessiondatapb.SerialUsesUnorderedRowID): "unordered_rowid",
int64(sessiondatapb.SerialUsesVirtualSequences): "virtual_sequence",
int64(sessiondatapb.SerialUsesSQLSequences): "sql_sequence",
int64(sessiondatapb.SerialUsesCachedSQLSequences): "sql_sequence_cached",
int64(sessiondatapb.SerialUsesRowID): "rowid",
int64(sessiondatapb.SerialUsesUnorderedRowID): "unordered_rowid",
int64(sessiondatapb.SerialUsesVirtualSequences): "virtual_sequence",
int64(sessiondatapb.SerialUsesSQLSequences): "sql_sequence",
int64(sessiondatapb.SerialUsesCachedSQLSequences): "sql_sequence_cached",
int64(sessiondatapb.SerialUsesCachedNodeSQLSequences): "sql_sequence_node_cached",
},
settings.WithPublic)

Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/sequences
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,9 @@ CREATE SEQUENCE cache_test CACHE 0
statement ok
CREATE SEQUENCE cache_test CACHE 10 INCREMENT 1

statement ok
CREATE SEQUENCE cache_node_test PER NODE CACHE 10

query TT
SHOW CREATE SEQUENCE cache_test
----
Expand Down
10 changes: 8 additions & 2 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ func (u *sqlSymUnion) showFingerprintOptions() *tree.ShowFingerprintOptions {
%token <str> MULTIPOLYGON MULTIPOLYGONM MULTIPOLYGONZ MULTIPOLYGONZM

%token <str> NAN NAME NAMES NATURAL NEVER NEW_DB_NAME NEW_KMS NEXT NO NOCANCELQUERY NOCONTROLCHANGEFEED
%token <str> NOCONTROLJOB NOCREATEDB NOCREATELOGIN NOCREATEROLE NOLOGIN NOMODIFYCLUSTERSETTING NOREPLICATION
%token <str> NOCONTROLJOB NOCREATEDB NOCREATELOGIN NOCREATEROLE NODE NOLOGIN NOMODIFYCLUSTERSETTING NOREPLICATION
%token <str> NOSQLLOGIN NO_INDEX_JOIN NO_ZIGZAG_JOIN NO_FULL_SCAN NONE NONVOTERS NORMAL NOT
%token <str> NOTHING NOTHING_AFTER_RETURNING
%token <str> NOTNULL
Expand All @@ -981,7 +981,7 @@ func (u *sqlSymUnion) showFingerprintOptions() *tree.ShowFingerprintOptions {
%token <str> OF OFF OFFSET OID OIDS OIDVECTOR OLD_KMS ON ONLY OPT OPTION OPTIONS OR
%token <str> ORDER ORDINALITY OTHERS OUT OUTER OVER OVERLAPS OVERLAY OWNED OWNER OPERATOR

%token <str> PARALLEL PARENT PARTIAL PARTITION PARTITIONS PASSWORD PAUSE PAUSED PHYSICAL PLACEMENT PLACING
%token <str> PARALLEL PARENT PARTIAL PARTITION PARTITIONS PASSWORD PAUSE PAUSED PER PHYSICAL PLACEMENT PLACING
%token <str> PLAN PLANS POINT POINTM POINTZ POINTZM POLYGON POLYGONM POLYGONZ POLYGONZM
%token <str> POSITION PRECEDING PRECISION PREPARE PRESERVE PRIMARY PRIOR PRIORITY PRIVILEGES
%token <str> PROCEDURAL PROCEDURE PROCEDURES PUBLIC PUBLICATION
Expand Down Expand Up @@ -10717,6 +10717,8 @@ sequence_option_elem:
$$.val = tree.SequenceOption{Name: tree.SeqOptOwnedBy, ColumnItemVal: columnItem} }
| CACHE signed_iconst64 { x := $2.int64()
$$.val = tree.SequenceOption{Name: tree.SeqOptCache, IntVal: &x} }
| PER NODE CACHE signed_iconst64 { x := $4.int64()
$$.val = tree.SequenceOption{Name: tree.SeqOptCacheNode, IntVal: &x} }
| INCREMENT signed_iconst64 { x := $2.int64()
$$.val = tree.SequenceOption{Name: tree.SeqOptIncrement, IntVal: &x} }
| INCREMENT BY signed_iconst64 { x := $3.int64()
Expand Down Expand Up @@ -17152,6 +17154,7 @@ unreserved_keyword:
| NOCREATEROLE
| NOCONTROLCHANGEFEED
| NOCONTROLJOB
| NODE
| NOLOGIN
| NOMODIFYCLUSTERSETTING
| NONVOTERS
Expand Down Expand Up @@ -17185,6 +17188,7 @@ unreserved_keyword:
| PASSWORD
| PAUSE
| PAUSED
| PER
| PHYSICAL
| PLACEMENT
| PLAN
Expand Down Expand Up @@ -17690,6 +17694,7 @@ bare_label_keywords:
| NOCREATEDB
| NOCREATELOGIN
| NOCREATEROLE
| NODE
| NOLOGIN
| NOMODIFYCLUSTERSETTING
| NONE
Expand Down Expand Up @@ -17736,6 +17741,7 @@ bare_label_keywords:
| PASSWORD
| PAUSE
| PAUSED
| PER
| PHYSICAL
| PLACEMENT
| PLACING
Expand Down
24 changes: 24 additions & 0 deletions pkg/sql/parser/testdata/create_sequence
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,30 @@ CREATE SEQUENCE a CACHE 2 -- fully parenthesized
CREATE SEQUENCE a CACHE 0 -- literals removed
CREATE SEQUENCE _ CACHE 2 -- identifiers removed

parse
CREATE SEQUENCE a PER NODE CACHE 0
----
CREATE SEQUENCE a PER NODE CACHE 0
CREATE SEQUENCE a PER NODE CACHE 0 -- fully parenthesized
CREATE SEQUENCE a PER NODE CACHE 0 -- literals removed
CREATE SEQUENCE _ PER NODE CACHE 0 -- identifiers removed

parse
CREATE SEQUENCE a PER NODE CACHE 1
----
CREATE SEQUENCE a PER NODE CACHE 1
CREATE SEQUENCE a PER NODE CACHE 1 -- fully parenthesized
CREATE SEQUENCE a PER NODE CACHE 0 -- literals removed
CREATE SEQUENCE _ PER NODE CACHE 1 -- identifiers removed

parse
CREATE SEQUENCE a PER NODE CACHE 2
----
CREATE SEQUENCE a PER NODE CACHE 2
CREATE SEQUENCE a PER NODE CACHE 2 -- fully parenthesized
CREATE SEQUENCE a PER NODE CACHE 0 -- literals removed
CREATE SEQUENCE _ PER NODE CACHE 2 -- identifiers removed

parse
CREATE SEQUENCE a INCREMENT 5
----
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/sem/tree/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -1701,7 +1701,7 @@ func (node *SequenceOptions) Format(ctx *FmtCtx) {
ctx.WriteString(option.AsIntegerType.SQLString())
case SeqOptCycle, SeqOptNoCycle:
ctx.WriteString(option.Name)
case SeqOptCache:
case SeqOptCache, SeqOptCacheNode:
ctx.WriteString(option.Name)
ctx.WriteByte(' ')
// TODO(knz): replace all this with ctx.FormatNode if/when
Expand Down Expand Up @@ -1803,6 +1803,7 @@ const (
SeqOptNoCycle = "NO CYCLE"
SeqOptOwnedBy = "OWNED BY"
SeqOptCache = "CACHE"
SeqOptCacheNode = "PER NODE CACHE"
SeqOptIncrement = "INCREMENT"
SeqOptMinValue = "MINVALUE"
SeqOptMaxValue = "MAXVALUE"
Expand Down

0 comments on commit 28d4471

Please sign in to comment.