Skip to content

Commit

Permalink
Merge #40303
Browse files Browse the repository at this point in the history
40303: sqlsmith: add option to disable window funcs r=mjibson a=mjibson

Release note: None

Co-authored-by: Matt Jibson <matt.jibson@gmail.com>
  • Loading branch information
craig[bot] and maddyblue committed Aug 28, 2019
2 parents 4db8153 + 096ba75 commit 8e07f50
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pkg/internal/sqlsmith/scalar.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,15 +444,15 @@ func makeFunc(s *scope, ctx Context, typ *types.T, refs colRefs) (tree.TypedExpr
args = append(args, castType(arg, argTyp))
}

if fn.def.Class == tree.WindowClass && s.schema.vectorizable {
if fn.def.Class == tree.WindowClass && s.schema.disableWindowFuncs {
return nil, false
}

var window *tree.WindowDef
// Use a window function if:
// - we chose an aggregate function, then 1/6 chance, but not if we're in a HAVING (noWindow == true)
// - we explicitly chose a window function
if fn.def.Class == tree.WindowClass || (!s.schema.vectorizable && !ctx.noWindow && s.d6() == 1 && fn.def.Class == tree.AggregateClass) {
if fn.def.Class == tree.WindowClass || (!s.schema.disableWindowFuncs && !ctx.noWindow && s.d6() == 1 && fn.def.Class == tree.AggregateClass) {
var parts tree.Exprs
s.schema.sample(len(refs), 2, func(i int) {
parts = append(parts, refs[i].item)
Expand Down
27 changes: 20 additions & 7 deletions pkg/internal/sqlsmith/sqlsmith.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ type Smither struct {
statements statementWeights
tableExprs tableExprWeights

disableWith bool
disableImpureFns bool
disableLimits bool
simpleDatums bool
avoidConsts bool
vectorizable bool
ignoreFNs []*regexp.Regexp
disableWith bool
disableImpureFns bool
disableLimits bool
disableWindowFuncs bool
simpleDatums bool
avoidConsts bool
vectorizable bool
ignoreFNs []*regexp.Regexp
}

// NewSmither creates a new Smither. db is used to populate existing tables
Expand Down Expand Up @@ -232,12 +233,24 @@ func (d avoidConsts) Apply(s *Smither) {
s.avoidConsts = true
}

// DisableWindowFuncs disables window functions.
func DisableWindowFuncs() SmitherOption {
return disableWindowFuncs{}
}

type disableWindowFuncs struct{}

func (d disableWindowFuncs) Apply(s *Smither) {
s.disableWindowFuncs = true
}

// Vectorizable causes the Smither to limit query generation to queries
// supported by vectorized execution.
func Vectorizable() SmitherOption {
return multiOption{
DisableMutations(),
DisableWith(),
DisableWindowFuncs(),
AvoidConsts(),
// This must be last so it can make the final changes to table
// exprs and statements.
Expand Down

0 comments on commit 8e07f50

Please sign in to comment.