From 7c32d9787006e05d8267f20cdf199bb5187f3966 Mon Sep 17 00:00:00 2001 From: Rebecca Taft Date: Wed, 19 Apr 2023 13:50:43 -0500 Subject: [PATCH] sql: add sqlsmith support to test partial visibility of indexes Sometimes generate a partially invisible index instead of a fully invisible index. Informs #82363 Release note: None --- pkg/internal/sqlsmith/alter.go | 4 +++- pkg/sql/randgen/schema.go | 4 +++- pkg/workload/schemachange/operation_generator.go | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/internal/sqlsmith/alter.go b/pkg/internal/sqlsmith/alter.go index 30f150def84c..67865b971ef8 100644 --- a/pkg/internal/sqlsmith/alter.go +++ b/pkg/internal/sqlsmith/alter.go @@ -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 = s.rnd.Float64() // [0.0, 1.0) + } } return &tree.CreateIndex{ diff --git a/pkg/sql/randgen/schema.go b/pkg/sql/randgen/schema.go index 818e7c7d500a..872a408d0553 100644 --- a/pkg/sql/randgen/schema.go +++ b/pkg/sql/randgen/schema.go @@ -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) diff --git a/pkg/workload/schemachange/operation_generator.go b/pkg/workload/schemachange/operation_generator.go index 5d027f137041..0d9f8d1d2593 100644 --- a/pkg/workload/schemachange/operation_generator.go +++ b/pkg/workload/schemachange/operation_generator.go @@ -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 = og.params.rng.Float64() + } } def := &tree.CreateIndex{