code: func (s *SessionVars) AddPreparedStmt(stmtID uint32, stmt *ast.Prepared) error {
  	if _, exists := s.PreparedStmts[stmtID]; !exists {
  		valStr, _ := s.GetSystemVar(MaxPreparedStmtCount)
  		maxPreparedStmtCount, err := strconv.ParseInt(valStr, 10, 64)
  		if err != nil {
  			maxPreparedStmtCount = DefMaxPreparedStmtCount
  		}
  		newPreparedStmtCount := atomic.AddInt64(&preparedStmtCount, 1)
  		if maxPreparedStmtCount >= 0 && newPreparedStmtCount > maxPreparedStmtCount {
  			atomic.AddInt64(&preparedStmtCount, -1)
  			return ErrMaxPreparedStmtCountReached.GenWithStackByArgs(maxPreparedStmtCount)
  		}
  		metrics.PreparedStmtGauge.Set(float64(newPreparedStmtCount))
  	}
  	s.PreparedStmts[stmtID] = stmt
  	return nil
  }
docs: // AddPreparedStmt adds prepareStmt to current session and count in global.