Create Materialized Views

In this section, you will find information about Oracle Materialized Views and their Snowflake equivalent.

Definition

A materialized view is a pre-computed data set derived from a query specification (the SELECT in the view definition) and stored for later use.

CREATE

The following is an Oracle's Materialized View create a basic example and its Snowflake counter part

Oracle

CREATE MATERIALIZED VIEW mv1
AS 
    SELECT 
        * 
    FROM 
        hr.employees
    ;
/

Snowflake

CREATE OR REPLACE MATERIALIZED VIEW PUBLIC.mv1
AS
SELECT
    *
FROM
    hr.employees;

ALTER

Altering the structure of a Materialized View in Snowflake is not supported, for these changes a CREATE OR REPLACE is recommended. There are only a handful of supported actions, as follows:

  • RENAME TO <NEW_NAME>, to rename the Materialized View

  • CLUSTER BY ( [, ... ] ), to cluster the Materialized View

  • DROP CLUSTERING KEY, to drop the cluster in the Materialized View

  • SUSPEND RECLUSTER, to suspend the clustering in the Materialized View

  • RESUME RECLUSTER, to resume in the Materialized View

  • SUSPEND, to suspend the maintenance of the Materialized View

  • RESUME, to resume the maintenance of the Materialized View

  • SET {SECURE | TAG = ' [ , <TAG_NAME = '' ... ] | COMMENT = '<COMMENT>' }

  • UNSET { SECURE | TAG = ' [ , <TAG_NAME = '' ... ] | COMMENT = '<COMMENT>' }

DROP

The following is an Oracle's Materialized View drop basic example and its Snowflake counterpart.

Oracle

Snowflake

Limitations

Oracle supports a large set of configurations for Materialized Views that Snowflake does not. The following list includes but is not limited to:

  • BUILD

  • CACHE / NOCACHE

  • CLUSTER

  • COMPRESS

  • DISTRIBUTE

  • EVALUATE

  • FOR UPDATE

  • INMEMORY | NO INMEMORY

  • LOB

  • LOGGING | NOLOGGING | FILESYSTEM_LIKE_LOGGING

  • MEMCOMPRESS

  • NESTED TABLE | STORE AS

  • ON PREBUILT TABLE

  • ORGANIZATION

  • PARALLEL | NOPARALLEL

  • PRIORITY REFRESH | NEVER REFRESH

  • SEGMENT CREATION

  • STORE AS [SECUREFILE | BASICFILE] LOB

  • USING INDEX | USING NO INDEX

  • VARRAY

  • WITH | WITHOUT

For more information about Snowflake's Materialized Views limitations, please use the following link Materialized Views Limitations

Transformation

Here we'll address the transformation process from Oracle to Snowflake. Following the limitations and considerations, when parsing and transforming an Oracle Materialized View is better to target a Snowflake's regular view, to keep consistency and prevent migration issues.

Simple Transformation

A simple transformation refers to a source code matching Snowflake's definition of Materialized View.

Oracle

Snowflake

Complex Transformation

Complex transformation refers to a source code not matching Snowflake's definition of Materialized View. Any Oracle source code including any of the keywords in the Limitations section of this page or its SELECT contains any of the unsupported clauses present in the Snowflake documentation must be considered complex.

Oracle

Note that the SELECT is performing multiple joins and accessing multiple tables. These are limitations of the Snowflake Materialized Views, so it will be transformed into a Snowflake regular view.

Snowflake

Known issues

1. Materialized Views with subqueries are converted to regular Views.

Snowflake Materialized Views support subqueries if they meet certain specifications. This scenario is currently not recognized, every Materialized View that has a subquery is converted to a regular view. For more information regarding this case, check this documentation.

  1. MSCEWI1092: Materialized View was converted to regular View.

Last updated

Was this helpful?