Skip to content

Commit

Permalink
Add SHOW VSCHEMA KEYSPACES query (#14505)
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 authored Nov 13, 2023
1 parent a0ee6c1 commit 0fd0b36
Show file tree
Hide file tree
Showing 11 changed files with 7,482 additions and 7,328 deletions.
22 changes: 22 additions & 0 deletions changelog/19.0/19.0.0/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- **[Deprecations and Deletions](#deprecations-and-deletions)**
- **[Docker](#docker)**
- [New MySQL Image](#mysql-image)
- **[Query Compatibility](#query-compatibility)**
- [`SHOW VSCHEMA KEYSPACES` Query](#show-vschema-keyspaces)

## <a id="major-changes"/>Major Changes

Expand All @@ -21,3 +23,23 @@ In `v19.0` the Vitess team is shipping a new image: `vitess/mysql`.
This lightweight image is a replacement of `vitess/lite` to only run `mysqld`.

Several tags are available to let you choose what version of MySQL you want to use: `vitess/mysql:8.0.30`, `vitess/mysql:8.0.34`.

### <a id="query-compatibility"/>Query Compatibility

#### <a id="show-vschema-keyspaces"/>`SHOW VSCHEMA KEYSPACES` Query

A SQL query, `SHOW VSCHEMA KEYSPACES` is now supported in Vitess. This query prints the vschema information
for all the keyspaces. It is useful for seeing the foreign key mode, whether the keyspace is sharded, and if there is an
error in the VSchema for the keyspace.

An example output of the query looks like -
```sql
mysql> show vschema keyspaces;
+---------------+---------+------------------+-------+
| Keyspace Name | Sharded | Foreign Key Mode | Error |
+---------------+---------+------------------+-------+
| uks | false | managed | |
| ks | true | managed | |
+---------------+---------+------------------+-------+
2 rows in set (0.00 sec)
```
13 changes: 13 additions & 0 deletions go/test/endtoend/vtgate/foreignkey/fk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package foreignkey

import (
"context"
"fmt"
"io"
"testing"
"time"
Expand Down Expand Up @@ -907,6 +908,18 @@ func TestFkQueries(t *testing.T) {
}
}

// TestShowVschemaKeyspaces verifies the show vschema keyspaces query output for the keyspaces where the foreign keys are
func TestShowVschemaKeyspaces(t *testing.T) {
mcmp, closer := start(t)
conn := mcmp.VtConn
defer closer()

res := utils.Exec(t, conn, "SHOW VSCHEMA KEYSPACES")
resStr := fmt.Sprintf("%v", res.Rows)
require.Contains(t, resStr, `[VARCHAR("uks") VARCHAR("false") VARCHAR("managed") VARCHAR("")]`)
require.Contains(t, resStr, `[VARCHAR("ks") VARCHAR("true") VARCHAR("managed") VARCHAR("")]`)
}

// TestFkOneCase is for testing a specific set of queries. On the CI this test won't run since we'll keep the queries empty.
func TestFkOneCase(t *testing.T) {
queries := []string{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ func TestVSchemaTrackerInit(t *testing.T) {
100*time.Millisecond,
60*time.Second,
"initial table list not complete")

utils.AssertMatches(t, conn, "SHOW VSCHEMA KEYSPACES", `[[VARCHAR("ks") VARCHAR("false") VARCHAR("unmanaged") VARCHAR("")]]`)
}

// TestVSchemaTrackerKeyspaceReInit tests that the vschema tracker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ func TestInitAndUpdate(t *testing.T) {
30*time.Second,
"initial table list not complete")

if vtgateVersion >= 19 {
utils.AssertMatches(t, conn,
"SHOW VSCHEMA KEYSPACES",
`[[VARCHAR("ks") VARCHAR("true") VARCHAR("unmanaged") VARCHAR("")]]`)
}

// Init
_ = utils.Exec(t, conn, "create table test_sc (id bigint primary key)")
expected = `[[VARCHAR("dual")] [VARCHAR("t2")] [VARCHAR("t2_id4_idx")] [VARCHAR("t8")] [VARCHAR("test_sc")]]`
Expand Down
2 changes: 2 additions & 0 deletions go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,8 @@ func (ty ShowCommandType) ToString() string {
return VitessVariablesStr
case VschemaTables:
return VschemaTablesStr
case VschemaKeyspaces:
return VschemaKeyspacesStr
case VschemaVindexes:
return VschemaVindexesStr
case Warnings:
Expand Down
2 changes: 2 additions & 0 deletions go/vt/sqlparser/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ const (
VitessTargetStr = " vitess_target"
VitessVariablesStr = " vitess_metadata variables"
VschemaTablesStr = " vschema tables"
VschemaKeyspacesStr = " vschema keyspaces"
VschemaVindexesStr = " vschema vindexes"
WarningsStr = " warnings"

Expand Down Expand Up @@ -881,6 +882,7 @@ const (
VitessTarget
VitessVariables
VschemaTables
VschemaKeyspaces
VschemaVindexes
Warnings
Keyspace
Expand Down
2 changes: 2 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2369,6 +2369,8 @@ var (
input: "show vitess_targets",
}, {
input: "show vschema tables",
}, {
input: "show vschema keyspaces",
}, {
input: "show vschema vindexes",
}, {
Expand Down
Loading

0 comments on commit 0fd0b36

Please sign in to comment.