code: func (s *session) ExecRestrictedSQLWithSnapshot(sctx sessionctx.Context, sql string) ([]chunk.Row, []*ast.ResultField, error) {
  	ctx := context.TODO()
  
  	// Use special session to execute the sql.
  	tmp, err := s.sysSessionPool().Get()
  	if err != nil {
  		return nil, nil, err
  	}
  	se := tmp.(*session)
  	defer s.sysSessionPool().Put(tmp)
  	metrics.SessionRestrictedSQLCounter.Inc()
  	var snapshot uint64
  	txn, err := s.Txn(false)
  	if err != nil {
  		return nil, nil, err
  	}
  	if txn.Valid() {
  		snapshot = s.txn.StartTS()
  	}
  	if s.sessionVars.SnapshotTS != 0 {
  		snapshot = s.sessionVars.SnapshotTS
  	}
  	// Set snapshot.
  	if snapshot != 0 {
  		if err := se.sessionVars.SetSystemVar(variable.TiDBSnapshot, strconv.FormatUint(snapshot, 10)); err != nil {
  			return nil, nil, err
  		}
  		defer func() {
  			if err := se.sessionVars.SetSystemVar(variable.TiDBSnapshot, ""); err != nil {
  				logutil.Logger(context.Background()).Error("set tidbSnapshot error", zap.Error(err))
  			}
  		}()
  	}
  	return execRestrictedSQL(ctx, se, sql)
  }
docs: // ExecRestrictedSQLWithSnapshot implements RestrictedSQLExecutor interface.
  // This is used for executing some restricted sql statements with snapshot.
  // If current session sets the snapshot timestamp, then execute with this snapshot timestamp.
  // Otherwise, execute with the current transaction start timestamp if the transaction is valid.