> For the complete documentation index, see [llms.txt](https://docs.pinot.apache.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pinot.apache.org/functions/sketch/distinctcounthllplus.md).

# DISTINCTCOUNTHLLPLUS

This section contains reference documentation for the DISTINCTCOUNTHLLPLUS function.

Returns an approximate distinct count using *HyperLogLogPlusPlus*. It also takes an optional second and third arguments to configure the *p*, *sp* for the *HyperLogLogPlus*.\
The optional parameter *p* defines the normal set precision and the parameter *sp* defines the sparse set precision.\
For accurate distinct counting, see [DISTINCTCOUNT](/functions/aggregation/distinctcount.md).

## Signature

> DISTINCTCOUNTHLLPlus(colName) DISTINCTCOUNTHLLPlus(colName, p) DISTINCTCOUNTHLLPlus(colName, p, sp)

## Usage Examples

These examples are based on the [Batch Quick Start](/start-here/quick-start.md#batch-processing).

```sql
select DISTINCTCOUNTHLLPLUS(teamID) AS value
from baseballStats 
```

| value |
| ----- |
| 158   |

```sql
select DISTINCTCOUNTHLLPLUS(teamID, 12) AS value
from baseballStats 
```

| value |
| ----- |
| 149   |

## DISTINCTCOUNTSMARTHLLPLUS

`DISTINCTCOUNTSMARTHLLPLUS` starts with exact distinct counting in a set and switches to HyperLogLog++ when the number of distinct values exceeds a threshold. This is useful when some groups stay small enough for exact counting while larger groups still need bounded memory usage.

### Signature

> DISTINCTCOUNTSMARTHLLPLUS(colName) DISTINCTCOUNTSMARTHLLPLUS(colName, 'threshold=;p=
>
> ;sp=')

### Parameters

* `colName` (required): Column to aggregate.
* `threshold` (optional): Number of distinct values Pinot keeps exactly before converting to HLL++. Default: `100000`. A non-positive value disables the conversion.
* `p` (optional): HyperLogLog++ normal precision after conversion. Default: `14`.
* `sp` (optional): HyperLogLog++ sparse precision after conversion. Default: `0`.

### Usage Examples

```sql
SELECT DISTINCTCOUNTSMARTHLLPLUS(teamID) AS value
FROM baseballStats
```

```sql
SELECT DISTINCTCOUNTSMARTHLLPLUS(teamID, 'threshold=10000;p=12') AS value
FROM baseballStats
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.pinot.apache.org/functions/sketch/distinctcounthllplus.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
