Skip to content

Commit

Permalink
sql: add parsing for LISTEN and NOTIFY statements.
Browse files Browse the repository at this point in the history
Part of: cockroachdb#41522

Release note: None
  • Loading branch information
asg0451 committed Jul 29, 2024
1 parent c70b187 commit 23279c3
Show file tree
Hide file tree
Showing 21 changed files with 238 additions and 21 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 @@ -371,7 +371,7 @@ sql.ttl.job.enabled boolean true whether the TTL job is enabled application
sql.txn.read_committed_isolation.enabled boolean true set to true to allow transactions to use the READ COMMITTED isolation level if specified by BEGIN/SET commands application
sql.txn_fingerprint_id_cache.capacity integer 100 the maximum number of txn fingerprint IDs stored application
storage.max_sync_duration duration 20s maximum duration for disk operations; any operations that take longer than this setting trigger a warning log entry or process crash system-visible
storage.max_sync_duration.fatal.enabled boolean true if true, fatal the process when a disk operation exceeds storage.max_sync_duration application
storage.max_sync_duration.fatal.enabled boolean false if true, fatal the process when a disk operation exceeds storage.max_sync_duration application
storage.sstable.compression_algorithm enumeration snappy determines the compression algorithm to use when compressing sstable data blocks for use in a Pebble store; [snappy = 1, zstd = 2, none = 3] system-visible
storage.sstable.compression_algorithm_backup_storage enumeration snappy determines the compression algorithm to use when compressing sstable data blocks for backup row data storage; [snappy = 1, zstd = 2, none = 3] system-visible
storage.sstable.compression_algorithm_backup_transport enumeration snappy determines the compression algorithm to use when compressing sstable data blocks for backup transport; [snappy = 1, zstd = 2, none = 3] system-visible
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 @@ -324,7 +324,7 @@
<tr><td><div id="setting-storage-experimental-eventually-file-only-snapshots-enabled" class="anchored"><code>storage.experimental.eventually_file_only_snapshots.enabled</code></div></td><td>boolean</td><td><code>true</code></td><td>set to false to disable eventually-file-only-snapshots (kv.snapshot_receiver.excise.enabled must also be false)</td><td>Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-storage-ingest-split-enabled" class="anchored"><code>storage.ingest_split.enabled</code></div></td><td>boolean</td><td><code>true</code></td><td>set to false to disable ingest-time splitting that lowers write-amplification</td><td>Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-storage-max-sync-duration" class="anchored"><code>storage.max_sync_duration</code></div></td><td>duration</td><td><code>20s</code></td><td>maximum duration for disk operations; any operations that take longer than this setting trigger a warning log entry or process crash</td><td>Dedicated/Self-hosted (read-write); Serverless (read-only)</td></tr>
<tr><td><div id="setting-storage-max-sync-duration-fatal-enabled" class="anchored"><code>storage.max_sync_duration.fatal.enabled</code></div></td><td>boolean</td><td><code>true</code></td><td>if true, fatal the process when a disk operation exceeds storage.max_sync_duration</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-storage-max-sync-duration-fatal-enabled" class="anchored"><code>storage.max_sync_duration.fatal.enabled</code></div></td><td>boolean</td><td><code>false</code></td><td>if true, fatal the process when a disk operation exceeds storage.max_sync_duration</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-storage-sstable-compression-algorithm" class="anchored"><code>storage.sstable.compression_algorithm</code></div></td><td>enumeration</td><td><code>snappy</code></td><td>determines the compression algorithm to use when compressing sstable data blocks for use in a Pebble store; [snappy = 1, zstd = 2, none = 3]</td><td>Dedicated/Self-hosted (read-write); Serverless (read-only)</td></tr>
<tr><td><div id="setting-storage-sstable-compression-algorithm-backup-storage" class="anchored"><code>storage.sstable.compression_algorithm_backup_storage</code></div></td><td>enumeration</td><td><code>snappy</code></td><td>determines the compression algorithm to use when compressing sstable data blocks for backup row data storage; [snappy = 1, zstd = 2, none = 3]</td><td>Dedicated/Self-hosted (read-write); Serverless (read-only)</td></tr>
<tr><td><div id="setting-storage-sstable-compression-algorithm-backup-transport" class="anchored"><code>storage.sstable.compression_algorithm_backup_transport</code></div></td><td>enumeration</td><td><code>snappy</code></td><td>determines the compression algorithm to use when compressing sstable data blocks for backup transport; [snappy = 1, zstd = 2, none = 3]</td><td>Dedicated/Self-hosted (read-write); Serverless (read-only)</td></tr>
Expand Down
2 changes: 2 additions & 0 deletions docs/generated/sql/bnf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ FILES = [
"legacy_transaction_stmt",
"like_table_option_list",
"limit_clause",
"listen_stmt",
"move_cursor_stmt",
"not_null_column_level",
"notify_stmt",
"offset_clause",
"on_conflict",
"opt_frame_clause",
Expand Down
2 changes: 2 additions & 0 deletions docs/generated/sql/bnf/listen_stmt.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
listen_stmt ::=
'LISTEN' type_name
3 changes: 3 additions & 0 deletions docs/generated/sql/bnf/notify_stmt.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
notify_stmt ::=
'NOTIFY' type_name string_or_placeholder
| 'NOTIFY' type_name
41 changes: 27 additions & 14 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ stmt_without_legacy_transaction ::=
| fetch_cursor_stmt
| move_cursor_stmt
| unlisten_stmt
| listen_stmt
| notify_stmt
| show_commit_timestamp_stmt

legacy_transaction_stmt ::=
Expand Down Expand Up @@ -171,6 +173,13 @@ unlisten_stmt ::=
'UNLISTEN' type_name
| 'UNLISTEN' '*'

listen_stmt ::=
'LISTEN' type_name

notify_stmt ::=
'NOTIFY' type_name string_or_placeholder
| 'NOTIFY' type_name

show_commit_timestamp_stmt ::=
'SHOW' 'COMMIT' 'TIMESTAMP'

Expand Down Expand Up @@ -506,6 +515,10 @@ cursor_movement_specifier ::=
| 'FIRST' opt_from_or_in cursor_name
| 'LAST' opt_from_or_in cursor_name

string_or_placeholder ::=
non_reserved_word_or_sconst
| 'PLACEHOLDER'

opt_transaction ::=
'TRANSACTION'
|
Expand Down Expand Up @@ -684,10 +697,6 @@ explain_option_list ::=
import_format ::=
name

string_or_placeholder ::=
non_reserved_word_or_sconst
| 'PLACEHOLDER'

opt_with_options ::=
'WITH' kv_option_list
| 'WITH' 'OPTIONS' '(' kv_option_list ')'
Expand Down Expand Up @@ -1244,6 +1253,7 @@ unreserved_keyword ::=
| 'LINESTRINGZ'
| 'LINESTRINGZM'
| 'LIST'
| 'LISTEN'
| 'LOCAL'
| 'LOCKED'
| 'LOGICAL'
Expand Down Expand Up @@ -1285,6 +1295,7 @@ unreserved_keyword ::=
| 'NO'
| 'NORMAL'
| 'NOTHING'
| 'NOTIFY'
| 'NO_INDEX_JOIN'
| 'NO_ZIGZAG_JOIN'
| 'NO_FULL_SCAN'
Expand Down Expand Up @@ -1643,6 +1654,10 @@ opt_forward_backward ::=
signed_iconst64 ::=
signed_iconst

non_reserved_word_or_sconst ::=
non_reserved_word
| 'SCONST'

alter_table_stmt ::=
alter_onetable_stmt
| alter_split_stmt
Expand Down Expand Up @@ -1926,10 +1941,6 @@ drop_trigger_stmt ::=
explain_option_name ::=
non_reserved_word

non_reserved_word_or_sconst ::=
non_reserved_word
| 'SCONST'

kv_option_list ::=
( kv_option ) ( ( ',' kv_option ) )*

Expand Down Expand Up @@ -2166,6 +2177,12 @@ signed_iconst ::=
'ICONST'
| only_signed_iconst

non_reserved_word ::=
'identifier'
| unreserved_keyword
| col_name_keyword
| type_func_name_keyword

alter_onetable_stmt ::=
'ALTER' 'TABLE' relation_expr alter_table_cmds
| 'ALTER' 'TABLE' 'IF' 'EXISTS' relation_expr alter_table_cmds
Expand Down Expand Up @@ -2731,12 +2748,6 @@ view_name_list ::=
sequence_name_list ::=
db_object_name_list

non_reserved_word ::=
'identifier'
| unreserved_keyword
| col_name_keyword
| type_func_name_keyword

kv_option ::=
name '=' string_or_placeholder
| name
Expand Down Expand Up @@ -3939,6 +3950,7 @@ bare_label_keywords ::=
| 'LINESTRINGZ'
| 'LINESTRINGZM'
| 'LIST'
| 'LISTEN'
| 'LOCAL'
| 'LOCALITY'
| 'LOCALTIME'
Expand Down Expand Up @@ -3996,6 +4008,7 @@ bare_label_keywords ::=
| 'NOT'
| 'NOTHING'
| 'NOTHING'
| 'NOTIFY'
| 'NOVIEWACTIVITY'
| 'NOVIEWACTIVITYREDACTED'
| 'NOVIEWCLUSTERSETTING'
Expand Down
2 changes: 2 additions & 0 deletions docs/generated/sql/bnf/stmt_without_legacy_transaction.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ stmt_without_legacy_transaction ::=
| fetch_cursor_stmt
| move_cursor_stmt
| unlisten_stmt
| listen_stmt
| notify_stmt
| show_commit_timestamp_stmt
2 changes: 2 additions & 0 deletions pkg/gen/bnf.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ BNF_SRCS = [
"//docs/generated/sql/bnf:legacy_transaction_stmt.bnf",
"//docs/generated/sql/bnf:like_table_option_list.bnf",
"//docs/generated/sql/bnf:limit_clause.bnf",
"//docs/generated/sql/bnf:listen_stmt.bnf",
"//docs/generated/sql/bnf:move_cursor_stmt.bnf",
"//docs/generated/sql/bnf:not_null_column_level.bnf",
"//docs/generated/sql/bnf:notify_stmt.bnf",
"//docs/generated/sql/bnf:offset_clause.bnf",
"//docs/generated/sql/bnf:on_conflict.bnf",
"//docs/generated/sql/bnf:opt_frame_clause.bnf",
Expand Down
2 changes: 2 additions & 0 deletions pkg/gen/diagrams.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ DIAGRAMS_SRCS = [
"//docs/generated/sql/bnf:legacy_transaction.html",
"//docs/generated/sql/bnf:like_table_option_list.html",
"//docs/generated/sql/bnf:limit_clause.html",
"//docs/generated/sql/bnf:listen.html",
"//docs/generated/sql/bnf:move_cursor.html",
"//docs/generated/sql/bnf:not_null_column_level.html",
"//docs/generated/sql/bnf:notify.html",
"//docs/generated/sql/bnf:offset_clause.html",
"//docs/generated/sql/bnf:on_conflict.html",
"//docs/generated/sql/bnf:opt_frame_clause.html",
Expand Down
2 changes: 2 additions & 0 deletions pkg/gen/docs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ DOCS_SRCS = [
"//docs/generated/sql/bnf:legacy_transaction_stmt.bnf",
"//docs/generated/sql/bnf:like_table_option_list.bnf",
"//docs/generated/sql/bnf:limit_clause.bnf",
"//docs/generated/sql/bnf:listen_stmt.bnf",
"//docs/generated/sql/bnf:move_cursor_stmt.bnf",
"//docs/generated/sql/bnf:not_null_column_level.bnf",
"//docs/generated/sql/bnf:notify_stmt.bnf",
"//docs/generated/sql/bnf:offset_clause.bnf",
"//docs/generated/sql/bnf:on_conflict.bnf",
"//docs/generated/sql/bnf:opt_frame_clause.bnf",
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,15 @@ go_library(
"join.go",
"join_predicate.go",
"limit.go",
"listen.go",
"lookup_join.go",
"max_one_row.go",
"mem_metrics.go",
"mvcc_backfiller.go",
"mvcc_statistics_update_job.go",
"name_util.go",
"notice.go",
"notify.go",
"opaque.go",
"opt_catalog.go",
"opt_exec_factory.go",
Expand Down
29 changes: 29 additions & 0 deletions pkg/sql/listen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2024 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package sql

import (
"context"

"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented"
)

func (p *planner) Listen(ctx context.Context, n *tree.Listen) (planNode, error) {
p.BufferClientNotice(ctx,
pgerror.WithSeverity(
unimplemented.NewWithIssuef(41522, "CRDB does not support LISTEN"),
"ERROR",
),
)
return newZeroNode(nil /* columns */), nil
}
29 changes: 29 additions & 0 deletions pkg/sql/notify.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2024 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package sql

import (
"context"

"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented"
)

func (p *planner) Notify(ctx context.Context, n *tree.Notify) (planNode, error) {
p.BufferClientNotice(ctx,
pgerror.WithSeverity(
unimplemented.NewWithIssuef(41522, "CRDB does not support LISTEN"),
"ERROR",
),
)
return newZeroNode(nil /* columns */), nil
}
6 changes: 6 additions & 0 deletions pkg/sql/opaque.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ func planOpaque(ctx context.Context, p *planner, stmt tree.Statement) (planNode,
return p.Grant(ctx, n)
case *tree.GrantRole:
return p.GrantRole(ctx, n)
case *tree.Listen:
return p.Listen(ctx, n)
case *tree.Notify:
return p.Notify(ctx, n)
case *tree.MoveCursor:
return p.FetchCursor(ctx, &n.CursorStmt)
case *tree.ReassignOwnedBy:
Expand Down Expand Up @@ -375,6 +379,8 @@ func init() {
&tree.FetchCursor{},
&tree.Grant{},
&tree.GrantRole{},
&tree.Listen{},
&tree.Notify{},
&tree.MoveCursor{},
&tree.ReassignOwnedBy{},
&tree.RefreshMaterializedView{},
Expand Down
4 changes: 4 additions & 0 deletions pkg/sql/opt/optbuilder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package optbuilder
import (
"context"
"strconv"
"strings"

"github.com/cockroachdb/cockroach/pkg/clusterversion"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
Expand Down Expand Up @@ -323,6 +324,9 @@ func (b *Builder) buildStmtAtRootWithScope(
func (b *Builder) buildStmt(
stmt tree.Statement, desiredTypes []*types.T, inScope *scope,
) (outScope *scope) {
if strings.HasPrefix(stmt.String(), "LISTEN") || strings.HasPrefix(stmt.String(), "UNLISTEN") {
log.Infof(b.ctx, "Building statement: %s", stmt)
}
if b.insideViewDef {
// A blocklist of statements that can't be used from inside a view.
switch stmt := stmt.(type) {
Expand Down
Loading

0 comments on commit 23279c3

Please sign in to comment.