code: func (q *Query) CountEstimate(threshold int) (int, error) {
  	if q.stickyErr != nil {
  		return 0, q.stickyErr
  	}
  
  	query, err := q.countSelectQuery(placeholder).AppendQuery(q.db, nil)
  	if err != nil {
  		return 0, err
  	}
  
  	for i := 0; i < 3; i++ {
  		var count int
  		_, err = q.db.QueryOneContext(
  			q.ctx,
  			Scan(&count),
  			"SELECT _go_pg_count_estimate_v2(?, ?)",
  			string(query), threshold,
  		)
  		if err != nil {
  			if pgerr, ok := err.(internal.PGError); ok && pgerr.Field('C') == "42883" {
  				// undefined_function
  				err = q.createCountEstimateFunc()
  				if err != nil {
  					pgerr, ok := err.(internal.PGError)
  					if !ok || !pgerr.IntegrityViolation() {
  						return 0, err
  					}
  				}
  				continue
  			}
  		}
  		return count, err
  	}
  
  	return 0, err
  }
docs: // CountEstimate uses EXPLAIN to get estimated number of rows returned the query.
  // If that number is bigger than the threshold it returns the estimation.
  // Otherwise it executes another query using count aggregate function and
  // returns the result.
  //
  // Based on https://wiki.postgresql.org/wiki/Count_estimate