You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: subquery.go
    path of file: ./repos/cockroach/pkg/sql/opt/optbuilder
    
    the code of the file until where you have to start completion: // Copyright 2018 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package optbuilder

import (
	"context"

	"github.com/cockroachdb/cockroach/pkg/server/telemetry"
	"github.com/cockroachdb/cockroach/pkg/sql/opt"
	"github.com/cockroachdb/cockroach/pkg/sql/opt/memo"
	"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
	"gi
    
func (s *subquery) buildSubquery(desiredTypes []*types.T) {
	if s.scope.replaceSRFs {
		// We need to save and restore the previous value of the replaceSRFs field in
		// case we are recursively called within a subquery context.
		defer func() { s.scope.replaceSRFs = true }()
		s.scope.replaceSRFs = false
	}

	// Save and restore the previous value of s.builder.subquery in case we are
	// recursively called within a subquery context.
	outer := s.scope.builder.subquery
	defer func() { s.scope.builder.subquery = outer }()
	s.scope.builder.subquery = s

	// We must push() here so that the columns in s.scope are correctly identified
	// as outer columns.
	outScope := s.scope.builder.buildStmt(s.Subquery.Select, desiredTypes, s.scope.push())

	ord := outScope.ordering

	// Treat the subquery result as an anonymous data source (i.e. column names
	// are not qualified). Remove hidden columns, as they are not accessible
	// outside the subquery.
	outScope.setTableAlias("")
	outScope.removeHiddenCols()

	if s.desiredNumColumns > 0 {
		if len(outScope.cols) != s.desiredNumColumns {
			n := len(outScope.cols)
			switch s.desiredNumColumns {
			case 1:
				panic(pgerror.Newf(pgcode.Syntax,
					"subquery must return only one column, found %d", n))
			default:
				panic(pgerror.Newf(pgcode.Syntax,
					"subquery must return %d columns, found %d", s.desiredNumColumns, n))
			}
		}
	} else {
		desireAnyType := len(desiredTypes) == 0 ||
			(len(desiredTypes) == 1 && desiredTypes[0].Family() == types.AnyFamily)
		// If the SELECT list expressions are not allowed to be any number of items
		// (as detected from the desiredTypes slice), count the number of items
		// "desired" and the actual number of selected items, and error out if they
		// don't match.
		numSubqueryCols := len(outScope.cols)
		if !desireAnyType && len(desiredTypes) != numSubqueryCols {
			if s.wrapInTuple && numSubqueryCols == 1 {
				colTyp := outScope.cols[0].typ
				if colTyp.Family() == types.TupleFamily {
					numSubqueryCols = len(colTyp.TupleContents())
				}
			}
			if len(desiredTypes) != numSubqueryCols {
				qualifier := "few"
				if numSubqueryCols > len(desiredTypes) {
					qualifier = "many"
				}
				panic(pgerror.Newf(pgcode.Syntax,
					"subquery has too %s columns", qualifier))
			}
		}
	}

	if len(outScope.extraCols) > 0 && !s.extraColsAllowed {
		// We need to add a projection to remove the extra columns.
		projScope := outScope.push()
		projScope.appendColumnsFromScope(outScope)
		projScope.expr = s.scope.builder.constructProject(outScope.expr, projScope.cols)
		outScope = projScope
	}

	s.cols = outScope.cols
	s.node = outScope.expr
	s.ordering = ord
}