


It shares almost the same restrictions as indexed view (see Create Indexed Views for details) except that a materialized view supports aggregate functions.Īlthough CREATE MATERIALIZED VIEW does not support COUNT, DISTINCT, COUNT(DISTINCT expression), or COUNT_BIG (DISTINCT expression), SELECT queries with these functions can still benefit from materialized views for faster performance as the Synapse SQL optimizer can automatically re-write those aggregations in the user query to match existing materialized views. To re-enable the materialized view, run ALTER MATERIALIZED VIEW with REBUILD.Ī materialized view in Azure data warehouse is similar to an indexed view in SQL Server. This restriction doesn't apply to INSERTs.
Materialize update#
The materialized view will be disabled when an UPDATE or DELETE occurs in the referenced base tables. GROUP BY i.i_item_sk, i.i_item_id, i.i_category_id

SELECT MAX(i.i_rec_start_date) as max_i_rec_start_date, MIN(i.i_rec_end_date) as min_i_rec_end_date, i.i_item_sk, i.i_item_id, i.i_category_id WITH (distribution = hash(i_category_id), FOR_APPEND) For example: CREATE MATERIALIZED VIEW mv_test2 When MIN/MAX aggregates are used in the SELECT list of materialized view definition, following requirements apply:įOR_APPEND is required. Supported aggregations include MAX, MIN, AVG, COUNT, COUNT_BIG, SUM, VAR, STDEV. Up to 32 columns can be used in the GROUP BY clause.Īggregate functions are required in the SELECT list of the materialized view definition.

View names must follow the rules for identifiers. Is the name of the schema to which the view belongs. This syntax is not supported by serverless SQL pool in Azure Synapse Analytics. Transact-SQL Syntax Conventions Syntax CREATE MATERIALIZED VIEW materialized_view_nameĭISTRIBUTION = HASH ( distribution_column_name ) This capability allows data engineers to implement materialized views as a mechanism for improving query response time, without having to change queries. With its execution plan automatching capability, a materialized view does not have to be referenced in the query for the optimizer to consider the view for substitution. It improves the performance of complex queries (typically queries with joins and aggregations) while offering simple maintenance operations.
Materialize code#
The article also provides code examples.Ī Materialized View persists the data returned from the view definition query and automatically gets updated as data changes in the underlying tables. This article explains the CREATE MATERIALIZED VIEW AS SELECT T-SQL statement in Azure Synapse Analytics for developing solutions.
