Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: fix multiregion sqlsmith failure #84650

Merged
merged 1 commit into from
Jul 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions pkg/internal/sqlsmith/alter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree/treebin"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/errors"
)

var (
Expand Down Expand Up @@ -375,13 +376,13 @@ func makeCreateType(s *Smither) (tree.Statement, bool) {
return randgen.RandCreateType(s.rnd, string(name), letters), true
}

func rowsToRegionList(rows *gosql.Rows) []string {
func rowsToRegionList(rows *gosql.Rows) ([]string, error) {
// Don't add duplicate regions to the slice.
regionsSet := make(map[string]struct{})
var region, zone string
for rows.Next() {
if err := rows.Scan(&region, &zone); err != nil {
panic(err)
return nil, err
}
regionsSet[region] = struct{}{}
}
Expand All @@ -390,23 +391,31 @@ func rowsToRegionList(rows *gosql.Rows) []string {
for region := range regionsSet {
regions = append(regions, region)
}
return regions
return regions, nil
}

func getClusterRegions(s *Smither) []string {
rows, err := s.db.Query("SHOW REGIONS FROM CLUSTER")
if err != nil {
panic(err)
}
return rowsToRegionList(rows)
regions, err := rowsToRegionList(rows)
if err != nil {
panic(errors.Wrap(err, "Failed to scan SHOW REGIONS FROM CLUSTER into values"))
}
return regions
}

func getDatabaseRegions(s *Smither) []string {
rows, err := s.db.Query("SHOW REGIONS FROM DATABASE defaultdb")
rows, err := s.db.Query("SELECT region, zones FROM [SHOW REGIONS FROM DATABASE defaultdb]")
if err != nil {
panic(err)
}
return rowsToRegionList(rows)
regions, err := rowsToRegionList(rows)
if err != nil {
panic(errors.Wrap(err, "Failed to scan SHOW REGIONS FROM DATABASE defaultdb into values"))
}
return regions
}

func makeAlterLocality(s *Smither) (tree.Statement, bool) {
Expand Down