Skip to content

Commit 6e622ea

Browse files
committed
sql: no-op SHOW SYNTAX in replication mode
Currently on the CLI, the command must parse on the server for it to run. For replication related commands, we have not implemented `SHOW SYNTAX` yet. This is a bit of effort and seems outside the scope of what we want for now. For now, handle replication commands by no-oping them. Release note: None
1 parent 7196bc3 commit 6e622ea

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#! /usr/bin/env expect -f
2+
3+
source [file join [file dirname $argv0] common.tcl]
4+
5+
start_server $argv
6+
7+
start_test "Ensure that replication mode works as expected in the sql shell"
8+
9+
# Spawn a sql shell.
10+
spawn /bin/bash
11+
12+
send "$argv sql --url `cat server_url`'\&replication=database' -e 'IDENTIFY_SYSTEM'\r"
13+
eexpect "(1 row)"
14+
15+
send_eof
16+
eexpect eof
17+
18+
end_test
19+
20+
stop_server $argv

pkg/sql/delegate/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ go_library(
5353
"//pkg/sql/oidext",
5454
"//pkg/sql/opt/cat",
5555
"//pkg/sql/parser",
56+
"//pkg/sql/pgrepl/pgreplparser",
5657
"//pkg/sql/pgwire/pgcode",
5758
"//pkg/sql/pgwire/pgerror",
5859
"//pkg/sql/privilege",
5960
"//pkg/sql/roleoption",
6061
"//pkg/sql/sem/catconstants",
6162
"//pkg/sql/sem/eval",
6263
"//pkg/sql/sem/tree",
64+
"//pkg/sql/sessiondatapb",
6365
"//pkg/sql/sqlerrors",
6466
"//pkg/sql/sqltelemetry",
6567
"//pkg/sql/syntheticprivilege",

pkg/sql/delegate/show_syntax.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import (
1818
"github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo"
1919
"github.com/cockroachdb/cockroach/pkg/sql/lexbase"
2020
"github.com/cockroachdb/cockroach/pkg/sql/parser"
21+
"github.com/cockroachdb/cockroach/pkg/sql/pgrepl/pgreplparser"
2122
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
23+
"github.com/cockroachdb/cockroach/pkg/sql/sessiondatapb"
2224
)
2325

2426
// delegateShowSyntax implements SHOW SYNTAX. This statement is usually handled
@@ -41,6 +43,16 @@ func (d *delegator) delegateShowSyntax(n *tree.ShowSyntax) (tree.Statement, erro
4143
colinfo.ShowSyntaxColumns[0].Name, colinfo.ShowSyntaxColumns[1].Name,
4244
)
4345

46+
// For replication based statements, return nothing for now.
47+
if d.evalCtx.SessionData().ReplicationMode != sessiondatapb.ReplicationMode_REPLICATION_MODE_DISABLED &&
48+
pgreplparser.IsReplicationProtocolCommand(n.Statement) {
49+
return d.parse(fmt.Sprintf(
50+
`SELECT '' AS %s, '' AS %s FROM generate_series(0, -1) x`,
51+
colinfo.ShowSyntaxColumns[0].Name,
52+
colinfo.ShowSyntaxColumns[1].Name,
53+
))
54+
}
55+
4456
comma := ""
4557
// TODO(knz): in the call below, reportErr is nil although we might
4658
// want to be able to capture (and report) these errors as well.

0 commit comments

Comments
 (0)