You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/t-sql/statements/create-materialized-view-as-select-transact-sql.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -108,7 +108,7 @@ When MIN/MAX aggregates are used in the SELECT list of materialized view definit
108
108
A materialized view in Azure data warehouse is similar to an indexed view in SQL Server. It shares almost the same restrictions as indexed view (see [Create Indexed Views](/sql/relational-databases/views/create-indexed-views) for details) except that a materialized view supports aggregate functions.
109
109
110
110
>[!Note]
111
-
>Although CREATE MATERIALIZED VIEW does not support COUNT(), DISTINCT(), COUNT(DISTINCT()), COUNT_BIG(DISTINCT()), or APPROX_COUNT_DISTINCT, 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. For details, check this article's example section.
111
+
>Although 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. For details, check this article's example section.
112
112
113
113
Only CLUSTERED COLUMNSTORE INDEX is supported by materialized view.
114
114
@@ -145,7 +145,7 @@ To find out if a SQL statement can benefit from a new materialized view, run the
145
145
Requires 1) REFERENCES and CREATE VIEW permission OR 2) CONTROL permission on the schema in which the view is being created.
146
146
147
147
## Example
148
-
A. This example shows how Synapse SQL optimizer automatically uses materialized views to execute a query for better performance even when the query uses functions un-supported in CREATE MATERIALIZED VIEW, such as COUNT(DISTINCT()). The query execution time got reduced from 176 seconds to <1 second without any change in the user query.
148
+
A. This example shows how Synapse SQL optimizer automatically uses materialized views to execute a query for better performance even when the query uses functions un-supported in CREATE MATERIALIZED VIEW, such as COUNT(DISTINCT expression). The query execution time got reduced from multiple seconds to sub-second without any change in the user query.
149
149
150
150
```sql
151
151
@@ -161,21 +161,21 @@ while (@P < 30)
161
161
select @p +=1;
162
162
end
163
163
164
-
-- A SELECT query with count_big(distinct()) took ~176 seconds and it reads data directly from the base table a.
164
+
-- A SELECT query with COUNT_BIG (DISTINCT expression) took multiple seconds to complete and it reads data directly from the base table a.
165
165
select a, count_big(distinct b) from t group by a;
166
166
167
-
-- Create two materialized views, not using COUNT_BIG(DISTINCT()).
167
+
-- Create two materialized views, not using COUNT_BIG(DISTINCT expression).
168
168
create materialized view V1 with(distribution=hash(a)) asselect a, b fromdbo.tgroup by a, b;
169
169
170
170
-- Clear all cache.
171
171
172
172
DBCC DROPCLEANBUFFERS;
173
173
DBCC freeproccache;
174
174
175
-
-- Check the estimated execution plan in SSMS. It shows the SELECT query is first step (GET operator) is to read data from the materialized view V1, not from base table a.
175
+
-- Check the estimated execution plan in SQL Server Management Studio. It shows the SELECT query is first step (GET operator) is to read data from the materialized view V1, not from base table a.
176
176
select a, count_big(distinct b) from t group by a;
177
177
178
-
-- Now run this SELECT query. This time it took <1 second to complete because Synapse SQL engine automatically matches the query with materialized view V1 and uses it for faster query execution. There was change in no user query.
178
+
-- Now execute this SELECT query. This time it took sub-second to complete because Synapse SQL engine automatically matches the query with materialized view V1 and uses it for faster query execution. There was no change in the user query.
0 commit comments