Skip to content

Commit

Permalink
sql: add sqlsmith support to test partial visibility of indexes
Browse files Browse the repository at this point in the history
Sometimes generate a partially invisible index instead of a fully
invisible index.

Informs cockroachdb#82363

Release note: None
  • Loading branch information
rytaft committed Apr 20, 2023
1 parent 568c68a commit ae4aeea
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pkg/internal/sqlsmith/alter.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,9 @@ func makeCreateIndex(s *Smither) (tree.Statement, bool) {
visibility := 1.0
if notvisible := s.d6() == 1; notvisible {
visibility = 0.0
// TODO(rytaft): sometimes generate a float between (0.0,1.0).
if s.coin() {
visibility = rand.Float64() // [0.0, 1.0)
}
}

return &tree.CreateIndex{
Expand Down
4 changes: 3 additions & 1 deletion pkg/sql/randgen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ func RandCreateTableWithColumnIndexNumberGeneratorAndName(
indexDef.Invisibility = 0.0
if notvisible := rng.Intn(6) == 0; notvisible {
indexDef.Invisibility = 1.0
// TODO(rytaft): sometimes generate a float between (0.0,1.0).
if rng.Intn(2) == 0 {
indexDef.Invisibility = 1 - rng.Float64()
}
}

defs = append(defs, &indexDef)
Expand Down
4 changes: 3 additions & 1 deletion pkg/workload/schemachange/operation_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,9 @@ func (og *operationGenerator) createIndex(ctx context.Context, tx pgx.Tx) (*opSt
visibility := 1.0
if notvisible := og.randIntn(20) == 0; notvisible {
visibility = 0.0
// TODO(rytaft): sometimes generate a float between (0.0,1.0).
if og.randIntn(2) == 0 {
visibility = rand.Float64()
}
}

def := &tree.CreateIndex{
Expand Down

0 comments on commit ae4aeea

Please sign in to comment.