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

# Metabase best practices

> Best practices for optimizing Metabase queries and improving performance on large datasets and distributed engines.

<Warning>NexusOne replaced Metabase with [Apache Superset](/platform-components/apache-superset/superset-in-nx1)</Warning>

Metabase queries can become expensive, especially on large datasets or distributed engines
like [Trino](/platform-components/trino). The following best practices help reduce execution
time, lower load on the engine, and improve dashboard responsiveness.

## Avoid full table scans

Large unfiltered queries are costly. Always filter or limit data early when
possible. Filtering drastically reduces the data scanned and speeds up execution.

* **Bad example**: Full table scan

  ```sql theme={null}
  SELECT *
  FROM events;
  ```

* **Good example**: Filter early

  ```sql theme={null}
  SELECT user_id, event_type
  FROM events
  WHERE event_type = 'purchase';
  ```

## Use date filters

Filtering by a recent time window reduces the amount of data scanned.

For example

```sql theme={null}
WHERE event_date >= current_date - interval '30' day
```

## Prefer aggregated queries

Aggregations reduce the amount of data processed and returned.

* **Bad example**: Returning raw rows

  ```sql theme={null}
  SELECT user_id, amount
  FROM transactions
  WHERE transaction_date >= current_date - interval '7' day;
  ```

* **Good example**: Summary metric

  ```sql theme={null}
  SELECT
      date(transaction_date) AS day,
      sum(amount) AS total_revenue
  FROM transactions
  WHERE transaction_date >= current_date - interval '7' day
  GROUP BY 1
  ORDER BY 1;
  ```

## Use partitions

If you partition Iceberg tables, filtering on partitions, such as date or region,
significantly improves performance.

* **Bad example**: Filtering on a non-partition column.

  ```sql theme={null}
  SELECT *
  FROM events
  WHERE user_id = 123;
  ```

* **Good example**: Filter using the partition column.

  ```sql theme={null}
  SELECT * FROM events
  WHERE event_date = current_date
  AND user_id = 123;
  ```

## Limit returned data

Visualization queries should return summaries or KPIs, not raw tables with large row counts.

* **Bad example**: Returning millions of rows.

  ```sql theme={null}
  SELECT *
  FROM page_views
  WHERE view_date >= current_date - interval '90' day;
  ```

* **Good example**: Return only needed fields, or aggregated data.

  ```sql theme={null}
  SELECT user_id, page_url, view_time
  FROM page_views
  WHERE view_time >= current_date - interval '7' day
  LIMIT 5000;
  ```

## Additional resources

* To get an overview of Metabase, refer to the [Metabase in NexusOne](./metabase-in-nx1) page.
* To learn practical ways to use Metabase in the NexusOne environment, refer to the
  [Metabase hands-on examples](./metabase-hands-on-examples) page.
* For more details about Metabase, refer to the [Metabase](https://www.metabase.com/docs/latest/)
  official documentation.
* If you are using the NexusOne portal to visualize your dataset, refer to the
  [Discover](/documentation/catalog-and-models/tasks/launch-superset) page.
