Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
53322: roachtest: skip jobs/mixed-version r=dt a=pbardea

Re-enabling this roachtest is high priority at this point, but due to
the many failures we're seeing, let's skip it for now to reduce noise
until we know that this test is stable.

Release note: None

53367: tpcc/roachtest: adjust tpcc workload to optionally include deprecated FKs r=rohany a=rohany

Fixes #53136.
Fixes #53122.

Updates the TPCC workload to create no longer needed FK indexes based on
a flag, and use that flag when running tpcc on versions below 20.2.

Release note: None

53374: backupccl: support SHOW BACKUP options on tenant backups r=dt a=pbardea

This commit ensures that SHOW BACKUP can be used with all of the options
it supports on tenant backups.

Release note: None

53386: cli: add the postgres \dT alias for listing enums r=rohany a=rohany

Teach the cli to translate \dT into a call to `SHOW ENUMS`.

Release note (cli change): Recognize the \dT alias for listing user
defined types.

Release note (sql change): Add the `SHOW TYPES` command to list all user
defined types.

Co-authored-by: Paul Bardea <[email protected]>
Co-authored-by: Rohan Yadav <[email protected]>
  • Loading branch information
3 people committed Aug 25, 2020
5 parents 7b55c9e + 7a74659 + b52aefc + dbee26e + 180b3a4 commit 32525b0
Show file tree
Hide file tree
Showing 20 changed files with 203 additions and 24 deletions.
1 change: 1 addition & 0 deletions docs/generated/sql/bnf/show_var.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ show_stmt ::=
| show_csettings_stmt
| show_databases_stmt
| show_enums_stmt
| show_types_stmt
| show_grants_stmt
| show_indexes_stmt
| show_partitions_stmt
Expand Down
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 @@ -197,6 +197,7 @@ show_stmt ::=
| show_csettings_stmt
| show_databases_stmt
| show_enums_stmt
| show_types_stmt
| show_grants_stmt
| show_indexes_stmt
| show_partitions_stmt
Expand Down Expand Up @@ -583,6 +584,9 @@ show_databases_stmt ::=
show_enums_stmt ::=
'SHOW' 'ENUMS'

show_types_stmt ::=
'SHOW' 'TYPES'

show_grants_stmt ::=
'SHOW' 'GRANTS' opt_on_targets_roles for_grantee_clause

Expand Down Expand Up @@ -993,6 +997,7 @@ unreserved_keyword ::=
| 'TRUNCATE'
| 'TRUSTED'
| 'TYPE'
| 'TYPES'
| 'THROTTLING'
| 'UNBOUNDED'
| 'UNCOMMITTED'
Expand Down
11 changes: 9 additions & 2 deletions pkg/ccl/backupccl/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,22 @@ func backupShowerDefault(
}
}
for _, t := range manifest.Tenants {
rows = append(rows, tree.Datums{
row := tree.Datums{
tree.NewDString("TENANT"),
tree.NewDString(roachpb.MakeTenantID(t.ID).String()),
start,
end,
tree.DNull,
tree.DNull,
tree.DNull,
})
}
if showSchemas {
row = append(row, tree.DNull)
}
if _, shouldShowPrivileges := opts[backupOptWithPrivileges]; shouldShowPrivileges {
row = append(row, tree.DNull)
}
rows = append(rows, row)
}
}
return rows, nil
Expand Down
51 changes: 51 additions & 0 deletions pkg/ccl/backupccl/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ import (
"strings"
"testing"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/security"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkv"
"github.com/cockroachdb/cockroach/pkg/sql/rowenc"
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -322,3 +326,50 @@ func TestShowBackups(t *testing.T) {
b2 := sqlDBRestore.QueryStr(t, `SHOW BACKUP $1 IN $2`, rows[1][0], full)
require.Equal(t, 3, len(b2))
}

func TestShowBackupTenants(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

const numAccounts = 1
_, tc, systemDB, _, cleanupFn := BackupRestoreTestSetup(t, singleNode, numAccounts, InitNone)
defer cleanupFn()
srv := tc.Server(0)

// NB: tenant certs for 10, 11, 20 are embedded. See:
_ = security.EmbeddedTenantIDs()

// Setup a few tenants, each with a different table.
conn10 := serverutils.StartTenant(t, srv, base.TestTenantArgs{TenantID: roachpb.MakeTenantID(10), TenantInfo: []byte("ten")})
defer conn10.Close()
tenant10 := sqlutils.MakeSQLRunner(conn10)
tenant10.Exec(t, `CREATE DATABASE foo; CREATE TABLE foo.bar(i int primary key); INSERT INTO foo.bar VALUES (110), (210)`)
beforeTS := systemDB.QueryStr(t, `SELECT now()::timestamp::string`)[0][0]

systemDB.Exec(t, fmt.Sprintf(`BACKUP TENANT 10 TO 'nodelocal://1/t10' AS OF SYSTEM TIME '%s'`, beforeTS))

res := systemDB.QueryStr(t, `SELECT table_name, start_time::string, end_time::string, rows FROM [SHOW BACKUP 'nodelocal://1/t10']`)
require.Equal(t, [][]string{
{"10", "NULL", beforeTS, "NULL"},
}, res)

res = systemDB.QueryStr(t, `SELECT table_name, privileges FROM [SHOW BACKUP 'nodelocal://1/t10' WITH privileges]`)
require.Equal(t, [][]string{
{"10", "NULL"},
}, res)

res = systemDB.QueryStr(t, `SELECT table_name, create_statement FROM [SHOW BACKUP SCHEMAS 'nodelocal://1/t10']`)
require.Equal(t, [][]string{
{"10", "NULL"},
}, res)

res = systemDB.QueryStr(t, `SELECT start_pretty, end_pretty FROM [SHOW BACKUP RANGES 'nodelocal://1/t10']`)
require.Equal(t, [][]string{
{"/Tenant/10", "/Tenant/11"},
}, res)

res = systemDB.QueryStr(t, `SELECT start_pretty, end_pretty FROM [SHOW BACKUP FILES 'nodelocal://1/t10']`)
require.Equal(t, [][]string{
{"/Tenant/10", "/Tenant/11"},
}, res)
}
5 changes: 5 additions & 0 deletions pkg/cli/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Type:
\hf [NAME] help on SQL built-in functions.
\l list all databases in the CockroachDB cluster.
\dt show the tables of the current schema in the current database.
\dT show the user defined types of the current database.
\du list the users for all databases.
\d [TABLE] show details about columns in the specified table, or alias for '\dt' if no table is specified.
%s
Expand Down Expand Up @@ -1042,6 +1043,10 @@ func (c *cliState) doHandleCliCmd(loopState, nextState cliStateEnum) cliStateEnu
c.concatLines = `SHOW TABLES`
return cliRunStatement

case `\dT`:
c.concatLines = `SHOW TYPES`
return cliRunStatement

case `\du`:
c.concatLines = `SHOW USERS`
return cliRunStatement
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func TestHandleCliCmdSqlAlias(t *testing.T) {
}{
{`\l`, `SHOW DATABASES`},
{`\dt`, `SHOW TABLES`},
{`\dT`, `SHOW TYPES`},
{`\du`, `SHOW USERS`},
{`\d mytable`, `SHOW COLUMNS FROM mytable`},
{`\d`, `SHOW TABLES`},
Expand Down
10 changes: 7 additions & 3 deletions pkg/cmd/roachtest/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/util/retry"
"github.com/cockroachdb/cockroach/pkg/util/version"
"github.com/cockroachdb/errors"
)

Expand All @@ -35,12 +36,15 @@ func registerImportTPCC(r *testRegistry) {
hc := NewHealthChecker(c, c.All())
m.Go(hc.Runner)

workloadStr := `./workload fixtures import tpcc --warehouses=%d --csv-server='http://localhost:8081'`
if !t.buildVersion.AtLeast(version.MustParse("v20.2.0")) {
workloadStr += " --deprecated-fk-indexes"
}

m.Go(func(ctx context.Context) error {
defer dul.Done()
defer hc.Done()
cmd := fmt.Sprintf(
`./workload fixtures import tpcc --warehouses=%d --csv-server='http://localhost:8081'`,
warehouses)
cmd := fmt.Sprintf(workloadStr, warehouses)
c.Run(ctx, c.Node(1), cmd)
return nil
})
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/roachtest/mixed_version_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ func registerJobsMixedVersions(r *testRegistry) {
// is to to test the state transitions of jobs from paused to resumed and
// vice versa in order to detect regressions in the work done for 20.1.
MinVersion: "v20.1.0",
Skip: "https://github.com/cockroachdb/cockroach/issues/51699",
Cluster: makeClusterSpec(4),
Run: func(ctx context.Context, t *test, c *cluster) {
predV, err := PredecessorVersion(r.buildVersion)
Expand Down
14 changes: 10 additions & 4 deletions pkg/cmd/roachtest/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/util/binfetcher"
"github.com/cockroachdb/cockroach/pkg/util/version"
"github.com/cockroachdb/errors"
_ "github.com/lib/pq"
)

// TODO(tbg): remove this test. Use the harness in versionupgrade.go
// to make a much better one, much more easily.
func registerVersion(r *testRegistry) {
runVersion := func(ctx context.Context, t *test, c *cluster, version string) {
runVersion := func(ctx context.Context, t *test, c *cluster, binaryVersion string) {
nodes := c.spec.NodeCount - 1
goos := ifLocal(runtime.GOOS, "linux")

b, err := binfetcher.Download(ctx, binfetcher.Options{
Binary: "cockroach",
Version: "v" + version,
Version: "v" + binaryVersion,
GOOS: goos,
GOARCH: "amd64",
})
Expand All @@ -56,8 +57,13 @@ func registerVersion(r *testRegistry) {

loadDuration := " --duration=" + (time.Duration(3*nodes+2)*stageDuration + buffer).String()

var deprecatedWorkloadsStr string
if !t.buildVersion.AtLeast(version.MustParse("v20.2.0")) {
deprecatedWorkloadsStr += " --deprecated-fk-indexes"
}

workloads := []string{
"./workload run tpcc --tolerate-errors --wait=false --drop --init --warehouses=1 " + loadDuration + " {pgurl:1-%d}",
"./workload run tpcc --tolerate-errors --wait=false --drop --init --warehouses=1 " + deprecatedWorkloadsStr + loadDuration + " {pgurl:1-%d}",
"./workload run kv --tolerate-errors --init" + loadDuration + " {pgurl:1-%d}",
}

Expand Down Expand Up @@ -101,7 +107,7 @@ func registerVersion(r *testRegistry) {
// checks had been broken for a long time. See:
//
// https://github.com/cockroachdb/cockroach/issues/37737#issuecomment-496026918
if !strings.HasPrefix(version, "2.") {
if !strings.HasPrefix(binaryVersion, "2.") {
if err := c.CheckReplicaDivergenceOnDB(ctx, db); err != nil {
return errors.Wrapf(err, "node %d", i)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/delegate/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func TryDelegate(
case *tree.ShowEnums:
return d.delegateShowEnums()

case *tree.ShowTypes:
return d.delegateShowTypes()

case *tree.ShowCreate:
return d.delegateShowCreate(t)

Expand Down
25 changes: 25 additions & 0 deletions pkg/sql/delegate/show_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2020 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 delegate

import "github.com/cockroachdb/cockroach/pkg/sql/sem/tree"

func (d *delegator) delegateShowTypes() (tree.Statement, error) {
// TODO (SQL Features, SQL Exec): Once more user defined types are added
// they should be added here.
return parse(`
SELECT
schema, name, value AS description
FROM
[SHOW ENUMS]
ORDER BY
(schema, name)`)
}
11 changes: 11 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/enums
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,17 @@ public greeting2 hello
public int Z|S of int
public notbad dup|DUP

query TTT
SHOW TYPES
----
public as_bytes bytes
public dbs postgres|mysql|spanner|cockroach
public farewell bye|seeya
public greeting hello|howdy|hi
public greeting2 hello
public int Z|S of int
public notbad dup|DUP

statement ok
SET experimental_enable_user_defined_schemas = true;
CREATE SCHEMA uds;
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/parser/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ func TestContextualHelp(t *testing.T) {
{`SHOW DATABASES ??`, `SHOW DATABASES`},

{`SHOW ENUMS ??`, `SHOW ENUMS`},
{`SHOW TYPES ??`, `SHOW TYPES`},

{`SHOW GRANTS ON ??`, `SHOW GRANTS`},
{`SHOW GRANTS ON foo FOR ??`, `SHOW GRANTS`},
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ func TestParse(t *testing.T) {
{`EXPLAIN SHOW DATABASES`},
{`SHOW ENUMS`},
{`EXPLAIN SHOW ENUMS`},
{`SHOW TYPES`},
{`EXPLAIN SHOW TYPES`},
{`SHOW SCHEMAS`},
{`EXPLAIN SHOW SCHEMAS`},
{`SHOW SCHEMAS FROM a`},
Expand Down
21 changes: 17 additions & 4 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ func (u *sqlSymUnion) refreshDataOption() tree.RefreshDataOption {

%token <str> TABLE TABLES TEMP TEMPLATE TEMPORARY TENANT TESTING_RELOCATE EXPERIMENTAL_RELOCATE TEXT THEN
%token <str> TIES TIME TIMETZ TIMESTAMP TIMESTAMPTZ TO THROTTLING TRAILING TRACE TRANSACTION TREAT TRIGGER TRIM TRUE
%token <str> TRUNCATE TRUSTED TYPE
%token <str> TRUNCATE TRUSTED TYPE TYPES
%token <str> TRACING

%token <str> UNBOUNDED UNCOMMITTED UNION UNIQUE UNKNOWN UNLOGGED UNSPLIT
Expand Down Expand Up @@ -860,6 +860,7 @@ func (u *sqlSymUnion) refreshDataOption() tree.RefreshDataOption {
%type <tree.Statement> show_tables_stmt
%type <tree.Statement> show_trace_stmt
%type <tree.Statement> show_transaction_stmt
%type <tree.Statement> show_types_stmt
%type <tree.Statement> show_users_stmt
%type <tree.Statement> show_zone_stmt
%type <tree.Statement> show_schedules_stmt
Expand Down Expand Up @@ -4172,8 +4173,8 @@ zone_value:
// SHOW CREATE, SHOW DATABASES, SHOW ENUMS, SHOW HISTOGRAM, SHOW INDEXES, SHOW
// PARTITIONS, SHOW JOBS, SHOW QUERIES, SHOW RANGE, SHOW RANGES,
// SHOW ROLES, SHOW SCHEMAS, SHOW SEQUENCES, SHOW SESSION, SHOW SESSIONS,
// SHOW STATISTICS, SHOW SYNTAX, SHOW TABLES, SHOW TRACE SHOW TRANSACTION, SHOW USERS,
// SHOW LAST QUERY STATISTICS, SHOW SCHEDULES
// SHOW STATISTICS, SHOW SYNTAX, SHOW TABLES, SHOW TRACE, SHOW TRANSACTION, SHOW TYPES,
// SHOW USERS, SHOW LAST QUERY STATISTICS, SHOW SCHEDULES
show_stmt:
show_backup_stmt // EXTEND WITH HELP: SHOW BACKUP
| show_columns_stmt // EXTEND WITH HELP: SHOW COLUMNS
Expand All @@ -4182,6 +4183,7 @@ show_stmt:
| show_csettings_stmt // EXTEND WITH HELP: SHOW CLUSTER SETTING
| show_databases_stmt // EXTEND WITH HELP: SHOW DATABASES
| show_enums_stmt // EXTEND WITH HELP: SHOW ENUMS
| show_types_stmt // EXTEND WITH HELP: SHOW TYPES
| show_fingerprints_stmt
| show_grants_stmt // EXTEND WITH HELP: SHOW GRANTS
| show_histogram_stmt // EXTEND WITH HELP: SHOW HISTOGRAM
Expand Down Expand Up @@ -4437,7 +4439,7 @@ show_databases_stmt:
}
| SHOW DATABASES error // SHOW HELP: SHOW DATABASES

// %Help: SHOW ENUMS - list defined enums
// %Help: SHOW ENUMS - list enums
// %Category: Misc
// %Text: SHOW ENUMS
show_enums_stmt:
Expand All @@ -4447,6 +4449,16 @@ show_enums_stmt:
}
| SHOW ENUMS error // SHOW HELP: SHOW ENUMS

// %Help: SHOW TYPES - list user defined types
// %Category: Misc
// %Text: SHOW TYPES
show_types_stmt:
SHOW TYPES
{
$$.val = &tree.ShowTypes{}
}
| SHOW TYPES error // SHOW HELP: SHOW TYPES

// %Help: SHOW GRANTS - list grants
// %Category: Priv
// %Text:
Expand Down Expand Up @@ -11530,6 +11542,7 @@ unreserved_keyword:
| TRUNCATE
| TRUSTED
| TYPE
| TYPES
| THROTTLING
| UNBOUNDED
| UNCOMMITTED
Expand Down
8 changes: 8 additions & 0 deletions pkg/sql/sem/tree/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ func (node *ShowEnums) Format(ctx *FmtCtx) {
ctx.WriteString("SHOW ENUMS")
}

// ShowTypes represents a SHOW TYPES statement.
type ShowTypes struct{}

// Format implements the NodeFormatter interface.
func (node *ShowTypes) Format(ctx *FmtCtx) {
ctx.WriteString("SHOW TYPES")
}

// ShowTraceType is an enum of SHOW TRACE variants.
type ShowTraceType string

Expand Down
Loading

0 comments on commit 32525b0

Please sign in to comment.