code: func (e *Execute) OptimizePreparedPlan(ctx sessionctx.Context, is infoschema.InfoSchema) error {
  	vars := ctx.GetSessionVars()
  	if e.Name != "" {
  		e.ExecID = vars.PreparedStmtNameToID[e.Name]
  	}
  	prepared, ok := vars.PreparedStmts[e.ExecID]
  	if !ok {
  		return errors.Trace(ErrStmtNotFound)
  	}
  
  	if len(prepared.Params) != len(e.UsingVars) {
  		return errors.Trace(ErrWrongParamCount)
  	}
  
  	for i, usingVar := range e.UsingVars {
  		val, err := usingVar.Eval(chunk.Row{})
  		if err != nil {
  			return err
  		}
  		param := prepared.Params[i].(*driver.ParamMarkerExpr)
  		param.Datum = val
  		param.InExecute = true
  		vars.PreparedParams = append(vars.PreparedParams, val)
  	}
  	if prepared.SchemaVersion != is.SchemaMetaVersion() {
  		// If the schema version has changed we need to preprocess it again,
  		// if this time it failed, the real reason for the error is schema changed.
  		err := Preprocess(ctx, prepared.Stmt, is, InPrepare)
  		if err != nil {
  			return ErrSchemaChanged.GenWithStack("Schema change caused error: %s", err.Error())
  		}
  		prepared.SchemaVersion = is.SchemaMetaVersion()
  	}
  	p, err := e.getPhysicalPlan(ctx, is, prepared)
  	if err != nil {
  		return err
  	}
  	e.Stmt = prepared.Stmt
  	e.Plan = p
  	return nil
  }
docs: // OptimizePreparedPlan optimizes the prepared statement.