diff --git a/pkg/sql/rowexec/project_set.go b/pkg/sql/rowexec/project_set.go index 5f7a70273fd0..ca37d0ebd5cd 100644 --- a/pkg/sql/rowexec/project_set.go +++ b/pkg/sql/rowexec/project_set.go @@ -144,6 +144,13 @@ func (ps *projectSetProcessor) nextInputRow() ( if fn := ps.funcs[i]; fn != nil { // A set-generating function. Prepare its ValueGenerator. + // First, make sure to close its ValueGenerator from the previous + // input row (if it exists). + if ps.gens[i] != nil { + ps.gens[i].Close(ps.Ctx) + ps.gens[i] = nil + } + // Set ExprHelper.row so that we can use it as an IndexedVarContainer. ps.exprHelpers[i].Row = row