> ## Documentation Index
> Fetch the complete documentation index at: https://docs.startree.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Using a Star-Tree Index

In this recipe we'll learn how to use the Star-tree index.

To understand how this recipe processes data, examine the commands executed in the Makefile.

| Pinot Version | 1.0.0                                                                                                                       |
| ------------- | --------------------------------------------------------------------------------------------------------------------------- |
| Code          | [startreedata/pinot-recipes/startree-index](https://github.com/startreedata/pinot-recipes/tree/main/recipes/startree-index) |

## Makefile

Run this recipe using make.

```bash theme={null}
make recipe
```

This will build up the infrastructure: Pinot and Kafka, create the tables, and produce streaming data.

Three tables will be generated:

* webtraffic - a real-time table with any Pinot indexes.
* webstraffic\_inverted - a real-time table with an `inverted index` on the columns: country, browserType, and deviceBrand.

```json theme={null}
"invertedIndexColumns": [
  "country",
  "browserType",
  "deviceBrand"
],
```

* webtraffic\_startree - a real-time table with a `startree index`.

```json theme={null}
"starTreeIndexConfigs": [
  {
    "dimensionsSplitOrder": [
      "country",
      "browserType",
      "deviceBrand"
    ],
    "skipStarNodeCreationForDimensions": [],
    "functionColumnPairs": [
      "COUNT__*",
      "SUM__timeSpent",
      "AVG__timeSpent"
    ],
    "maxLeafRecords": 10000
  }
],
```

Open your browser to the [Pinot console](http://localhost:9000) and execute the SQL statements below.

```sql theme={null}
select browserType, count(*)
from webtraffic 
WHERE country = 'Uruguay'
GROUP BY browserType
limit 10
```

```sql theme={null}
select country, sum(timeSpent) AS totalTime
from webtraffic
group by country
order by totalTime DESC
limit 10
```

```sql theme={null}
select count(*), sum(timeSpent) AS totalTime
from webtraffic
where country = 'United Kingdom'
order by totalTime DESC
limit 10
```

```sql theme={null}
select browserType, count(*)
from webtraffic
WHERE country IN ('Germany', 'United Kingdom', 'Spain')
GROUP BY browserType
limit 10
```

Try changing `FROM webtraffic` to `FROM webtraffic_inverted` or `FROM webtraffic_stree`

## Clean up

```bash theme={null}
make clean
```

## Troubleshooting

To clean up old Docker installations that may be interfering with your testing of this recipe, run the following command:

```bash theme={null}
docker system prune
```
