cockroach: github.com/cockroachdb/cockroach/pkg/internal/sqlsmith Index | Files

package sqlsmith

import "github.com/cockroachdb/cockroach/pkg/internal/sqlsmith"

Index

Package Files

alter.go bulkio.go random.go relational.go sampler.go scalar.go schema.go scope.go setup.go sqlsmith.go type.go

Variables

var AvoidConsts = simpleOption("avoid consts", func(s *Smither) {
    s.avoidConsts = true
})

AvoidConsts causes the Smither to prefer column references over generating constants.

var CompareMode = multiOption(
    "compare mode",
    DisableMutations(),
    DisableImpureFns(),
    DisableCRDBFns(),
    IgnoreFNs("^version"),
    DisableLimits(),
    OutputSort(),
)

CompareMode causes the Smither to generate statements that have deterministic output.

var DisableDDLs = simpleOption("disable DDLs", func(s *Smither) {
    s.stmtWeights = []statementWeight{
        {20, makeSelect},
        {5, makeInsert},
        {5, makeUpdate},
        {1, makeDelete},
    }
})

DisableDDLs causes the Smither to not emit statements that change table schema (CREATE, DROP, ALTER, etc.)

var DisableImpureFns = simpleOption("disable impure funcs", func(s *Smither) {
    s.disableImpureFns = true
})

DisableImpureFns causes the Smither to disable impure functions.

var DisableLimits = simpleOption("disable LIMIT", func(s *Smither) {
    s.disableLimits = true
})

DisableLimits causes the Smither to disable LIMIT clauses.

var DisableMutations = simpleOption("disable mutations", func(s *Smither) {
    s.stmtWeights = nonMutatingStatements
    s.tableExprWeights = nonMutatingTableExprs
})

DisableMutations causes the Smither to not emit statements that could mutate any on-disk data.

var DisableWindowFuncs = simpleOption("disable window funcs", func(s *Smither) {
    s.disableWindowFuncs = true
})

DisableWindowFuncs disables window functions.

var DisableWith = simpleOption("disable WITH", func(s *Smither) {
    s.disableWith = true
})

DisableWith causes the Smither to not emit WITH clauses.

var OnlyNoDropDDLs = simpleOption("only DDLs", func(s *Smither) {
    s.stmtWeights = append([]statementWeight{
        {1, makeBegin},
        {2, makeRollback},
        {6, makeCommit},
    },
        altersExistingTable...,
    )
})

OnlyNoDropDDLs causes the Smither to only emit DDLs, but won't ever drop a table.

var OutputSort = simpleOption("output sort", func(s *Smither) {
    s.outputSort = true
})

OutputSort adds a top-level ORDER BY on all columns.

var PostgresMode = multiOption(
    "postgres mode",
    CompareMode(),
    DisableWith(),
    SimpleDatums(),
    IgnoreFNs("^current_"),
    simpleOption("postgres", func(s *Smither) {
        s.postgres = true
    })(),

    IgnoreFNs("^sha"),

    IgnoreFNs("^quote"),

    IgnoreFNs("^pg_collation_for"),
)

PostgresMode causes the Smither to generate statements that work identically in Postgres and Cockroach.

var SettingVectorize = staticSetting(Parallel, Vectorizable())

SettingVectorize is the setting for vectorizable. It is not included in Settings because it has type restrictions during CREATE TABLE, but Settings is designed to be used with anything in Setups, which may violate that restriction.

var Settings = map[string]SettingFunc{
    "default":           staticSetting(Parallel),
    "no-mutations":      staticSetting(Parallel, DisableMutations()),
    "no-ddl":            staticSetting(NoParallel, DisableDDLs()),
    "default+rand":      randSetting(Parallel),
    "no-mutations+rand": randSetting(Parallel, DisableMutations()),
    "no-ddl+rand":       randSetting(NoParallel, DisableDDLs()),
    "ddl-nodrop":        randSetting(NoParallel, OnlyNoDropDDLs()),
}

Settings is a collection of useful Setting options.

var Setups = map[string]Setup{
    "empty": stringSetup(""),

    "seed": stringSetup(seedTable),

    "seed-vec":    stringSetup(vecSeedTable),
    "rand-tables": randTables,
}

Setups is a collection of useful initial table states.

var SimpleDatums = simpleOption("simple datums", func(s *Smither) {
    s.simpleDatums = true
})

SimpleDatums causes the Smither to emit simpler constant datums.

var Vectorizable = multiOption(
    "Vectorizable",
    DisableMutations(),
    DisableWith(),
    DisableWindowFuncs(),
    AvoidConsts(),

    simpleOption("vectorizable", func(s *Smither) {
        s.vectorizable = true
        s.stmtWeights = nonMutatingStatements
        s.tableExprWeights = vectorizableTableExprs
    })(),
)

Vectorizable causes the Smither to limit query generation to queries supported by vectorized execution.

func RandSetting Uses

func RandSetting(r *rand.Rand) string

RandSetting returns a random key from Settings.

func RandSetup Uses

func RandSetup(r *rand.Rand) string

RandSetup returns a random key from Setups.

type Context Uses

type Context struct {
    // contains filtered or unexported fields
}

Context holds information about what kinds of expressions are legal at a particular place in a query.

type ExecMode Uses

type ExecMode int

ExecMode definitions define how a Setting can be executed.

const (
    // NoParallel indicates that, if determinism is desired, this Setting
    // should not be executed in parallel.
    NoParallel ExecMode = iota
    // Parallel indicates that this Setting can be executed in parallel and
    // still preserve determinism.
    Parallel
)

type Setting Uses

type Setting struct {
    Options []SmitherOption
    Mode    ExecMode
}

Setting defines options and execution modes for a Smither.

type SettingFunc Uses

type SettingFunc func(*rand.Rand) Setting

SettingFunc generates a Setting.

type Setup Uses

type Setup func(*rand.Rand) string

Setup generates a SQL query that can be executed to initialize a database for smithing.

type Smither Uses

type Smither struct {
    // contains filtered or unexported fields
}

Smither is a sqlsmith generator.

func NewSmither Uses

func NewSmither(db *gosql.DB, rnd *rand.Rand, opts ...SmitherOption) (*Smither, error)

NewSmither creates a new Smither. db is used to populate existing tables for use as column references. It can be nil to skip table population.

func (*Smither) Close Uses

func (s *Smither) Close()

Close closes resources used by the Smither.

func (*Smither) Generate Uses

func (s *Smither) Generate() string

Generate returns a random SQL string.

func (*Smither) GenerateExpr Uses

func (s *Smither) GenerateExpr() tree.TypedExpr

GenerateExpr returns a random SQL expression that does not depend on any tables or columns.

func (*Smither) ReloadSchemas Uses

func (s *Smither) ReloadSchemas() error

ReloadSchemas loads tables from the database.

type SmitherOption Uses

type SmitherOption interface {
    Apply(*Smither)
    String() string
}

SmitherOption is an option for the Smither client.

func DisableCRDBFns Uses

func DisableCRDBFns() SmitherOption

DisableCRDBFns causes the Smither to disable crdb_internal functions.

func IgnoreFNs Uses

func IgnoreFNs(regex string) SmitherOption

IgnoreFNs causes the Smither to ignore functions that match the regex.

Package sqlsmith imports 23 packages (graph) and is imported by 7 packages. Updated 2020-02-19. Refresh now. Tools for package owners.