preview
We're still working on this feature, but we'd love for you to try it out!
This feature is currently provided as part of a preview program pursuant to our pre-release policies.
For larger, computationally expensive queries, you can store the results as materialized views in Lens. A materialized view stores the precomputed results of a query, allowing you to query the stored data instead of running the complex query each time.
Benefits of materialized views
Materialized views help you:
- Reduce query costs: Avoid repeatedly fetching the same data from external data sources, which can incur costs based on data scanned or transferred.
- Improve performance: Query precomputed results instead of running complex joins across multiple databases each time.
- Simplify dashboards: Store results from multi-database queries and reference them simply in dashboard widgets.
Prerequisites
Before you start:
- Verify you have the necessary permissions to create and manage materialized views.
- If you need to query external data sources, ensure the connectors are set up.
Create a materialized view
To create a materialized view:
- Go to one.newrelic.com > Administration > Materialized views.
- Click Create materialized view.
- Enter a unique name for the materialized view.
- To query NRDB data, select an account from the account selector. You can join NRDB data from this account with external data sources.
- Write your SQL query using the table reference format:
connection_name.schema.table - Click Create.
The materialized view appears in the list. Storing results may take some time depending on the complexity of your query.
Refresh a materialized view
Materialized views contain a snapshot of data from when they were created or last refreshed. To get fresh data:
- Go to one.newrelic.com > Administration > Materialized views.
- Find the materialized view you want to refresh.
- Click the menu.
- Select Refresh.
The view runs the original query again and updates the stored results with the latest data.
Importante
Consider your data freshness requirements when deciding how often to refresh materialized views. Frequently refreshing views with complex queries may increase costs.
Query a materialized view
You can query a materialized view like any other table in Lens:
Go to one.newrelic.com > Query your data.
Enable the toggle beside Notebooks and click + SQL to add a SQL block.
Reference your materialized view using the
mv.prefix followed by the view name:SELECT * FROM mv.your_materialized_view_nameRun your query.
You can apply additional filters, joins, or aggregations on the materialized view:
SELECT store_id, transaction_countFROM mv.top_stores_mvWHERE transaction_count > 1000ORDER BY transaction_count DESCThe materialized view acts as a table containing the precomputed results, allowing you to perform further analysis without running the original complex query again.
Delete a materialized view
To delete a materialized view you no longer need:
- Go to one.newrelic.com > Administration > Materialized views.
- Find the materialized view you want to delete.
- Click the menu.
- Select Delete.
- Confirm the deletion.
Advertencia
Deleting a materialized view is permanent. Any queries or dashboards referencing the deleted view will fail.
For query examples including cross-database joins, refer to Query materialized views.