Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/cmd/smith/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ var (
"DisableCrossJoins": sqlsmith.DisableCrossJoins(),
"DisableDDLs": sqlsmith.DisableDDLs(),
"DisableDecimals": sqlsmith.DisableDecimals(),
"DisableDoBlocks": sqlsmith.DisableDoBlocks(),
"DisableEverything": sqlsmith.DisableEverything(),
"DisableIndexHints": sqlsmith.DisableIndexHints(),
"DisableInsertSelect": sqlsmith.DisableInsertSelect(),
Expand Down
18 changes: 18 additions & 0 deletions pkg/internal/sqlsmith/plpgsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ var (
{2, makePLpgSQLReturn},
{2, makePLpgSQLIf},
{2, makePLpgSQLWhile},
{2, makeDoBlockWithinScope},
{2, makePLpgSQLForLoop},
{5, makePLpgSQLNull},
{10, makePLpgSQLAssign},
Expand Down Expand Up @@ -395,3 +396,20 @@ func (s *plpgsqlBlockScope) addVariable(name string, typ *types.T, constant bool
s.constants[name] = struct{}{}
}
}

func (s *Smither) makeDoBlockTreeStmt() (*tree.DoBlock, bool) {
scope := makeBlockScope(0, types.Unknown, tree.RoutineVolatile)
doBlock, ok := makeDoBlockWithinScope(s, scope)
if !ok {
return nil, false
}
return &tree.DoBlock{Code: doBlock.(*ast.DoBlock)}, true
}

func makeDoBlockWithinScope(s *Smither, scope plpgsqlBlockScope) (ast.Statement, bool) {
if s.disableDoBlock {
return nil, false
}
block := s.makePLpgSQLBlock(scope)
return &ast.DoBlock{Block: block}, true
}
6 changes: 6 additions & 0 deletions pkg/internal/sqlsmith/relational.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ var (
{1, makeImport},
{1, makeCreateStats},
{1, makeSetSessionCharacteristics},
{1, makeDoBlock},
}
nonMutatingStatements = []statementWeight{
{10, makeSelect},
{1, makeDoBlock},
}
allStatements = append(mutatingStatements, nonMutatingStatements...)

Expand Down Expand Up @@ -917,6 +919,10 @@ func makeCreateFunc(s *Smither) (tree.Statement, bool) {
return s.makeCreateFunc()
}

func makeDoBlock(s *Smither) (tree.Statement, bool) {
return s.makeDoBlockTreeStmt()
}

func makeDropFunc(s *Smither) (tree.Statement, bool) {
if s.disableUDFCreation {
return nil, false
Expand Down
11 changes: 10 additions & 1 deletion pkg/internal/sqlsmith/sqlsmith.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ type Smither struct {
// disableUDFCreation indicates whether we're not allowed to create UDFs.
// It follows that if we haven't created any UDFs, we have no UDFs to invoke
// too.
disableUDFCreation bool
disableUDFCreation bool
// disableDoBlock indicates whether we're not allowed to create DO blocks,
// both as top level statements and inside plpgsql function body
// definition.
disableDoBlock bool
disableIsolationChange bool

bulkSrv *httptest.Server
Expand Down Expand Up @@ -612,6 +616,11 @@ var DisableUDFs = simpleOption("disable udfs", func(s *Smither) {
s.disableUDFCreation = true
})

// DisableDoBlocks causes the Smither to disable DO blocks.
var DisableDoBlocks = simpleOption("disable do block", func(s *Smither) {
s.disableDoBlock = true
})

// DisableIsolationChange causes the Smither to disable stmts that modify the
// txn isolation level.
var DisableIsolationChange = simpleOption("disable isolation change", func(s *Smither) {
Expand Down
Loading