liveBook · Manning

Materialized view

As explained in Snowflake Data Engineering

A materialized view is a database object that stores the results of a query and maintains them for subsequent access.

A materialized view is a database object that stores the result of a query for later access. Because the result is persisted, querying it can be faster than rerunning the defining query, especially against external tables. section 3.4.2 section 3.5

In Snowflake, an external table can expose files in cloud storage, but querying it is generally slower than querying regular Snowflake tables. A materialized view stores the external-table data in Snowflake while preserving the queryable result. section 3.4.1 section 3.4.2

Use the pattern with these operational considerations:

  • Define the view over an external table, then query the materialized view instead of repeatedly querying the external data. section 3.4.2
  • Rely on Snowflake to maintain the view after the external table refreshes, whether that refresh occurs automatically through cloud notifications or manually. section 3.4.1 section 3.4.2
  • Account for storage and compute costs, and verify that the Snowflake edition supports materialized views; they require Enterprise Edition or higher. section 3.4.2

Materializing external orders

Create ORDERS_BISTRO_MV from ORDERS_BISTRO_EXT with the selected order columns, then run SELECT * FROM ORDERS_BISTRO_MV to retrieve the same data through the faster persisted result. section 3.4.2

Listing 3.4 Creating an external table from an external stage
create external table ORDERS_BISTRO_EXT (
  customer varchar as (VALUE:c1::varchar),
  order_date date as (VALUE:c2::date),
  delivery_date date as (VALUE:c3::date),
  baked_good_type varchar as (VALUE:c4::varchar),
  quantity number as (VALUE:c5::number),
  source_file_name varchar as metadata$filename
)
location = @BISTRO_STAGE
auto_refresh = FALSE
file_format = ORDERS_CSV_FORMAT;

Use the external-table definition to see the stage location, metadata filename, typed columns, file format, and refresh configuration that precede materialization. section 3.4.1

How Snowflake Data Engineering covers it

How deep it goes
Explains persistence, automatic maintenance, refresh dependencies, and cost trade-offs, but does not detail internal maintenance algorithms.
Examples
Uses the ORDERS_BISTRO_EXT external table and ORDERS_BISTRO_MV materialized view with executable creation and SELECT statements.
What it assumes
Assumes familiarity with Snowflake SQL and external tables while explaining the materialized-view purpose and refresh relationship.
What you can do after
Operate/configure a Snowflake materialized view over an external table and assess refresh behavior, performance benefits, edition requirements, and costs.
How it connects
Connects external tables, cloud storage, data refresh, query performance, storage costs, compute resources, and dynamic tables.

Also explained in

Compare how 5 books explain materialized view →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Snowflake Data Engineering. The section links point to the parts of the book it draws on.