Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
84650: sql: fix multiregion sqlsmith failure r=RichardJCai a=RichardJCai

Release note: None

Fixes cockroachdb#78138

Co-authored-by: richardjcai <[email protected]>
  • Loading branch information
craig[bot] and RichardJCai committed Jul 20, 2022
2 parents 791015c + b560ec3 commit b77d49e
Showing 1 changed file with 15 additions and 6 deletions.
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

0 comments on commit b77d49e

Please sign in to comment.