Skip to content

Commit 99ca83a

Browse files
committed
add distinct function example 3
1 parent 600bba4 commit 99ca83a

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

docs/t-sql/statements/create-materialized-view-as-select-transact-sql.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ When MIN/MAX aggregates are used in the SELECT list of materialized view definit
108108
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.  
109109

110110
>[!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.
112112
113113
Only CLUSTERED COLUMNSTORE INDEX is supported by materialized view.
114114

@@ -145,7 +145,7 @@ To find out if a SQL statement can benefit from a new materialized view, run the
145145
Requires 1) REFERENCES and CREATE VIEW permission OR 2) CONTROL permission on the schema in which the view is being created.
146146

147147
## 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.
149149

150150
``` sql
151151

@@ -161,21 +161,21 @@ while (@P < 30)
161161
select @p +=1;
162162
end
163163

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.
165165
select a, count_big(distinct b) from t group by a;
166166

167-
-- Create two materialized views, not using COUNT_BIG(DISTINCT()).
167+
-- Create two materialized views, not using COUNT_BIG(DISTINCT expression).
168168
create materialized view V1 with(distribution=hash(a)) as select a, b from dbo.t group by a, b;
169169

170170
-- Clear all cache.
171171

172172
DBCC DROPCLEANBUFFERS;
173173
DBCC freeproccache;
174174

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.
176176
select a, count_big(distinct b) from t group by a;
177177

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.
179179

180180
DECLARE @timerstart datetime2, @timerend datetime2;
181181
SET @timerstart = sysdatetime();

0 commit comments

Comments
 (0)