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
@@ -258,7 +258,7 @@ ORDER BY t_s_secyear.customer_id
258
258
OPTION ( LABEL ='Query04-af359846-253-3');
259
259
```
260
260
261
-
Check the estimated execution plan for this query. There are 18 shuffles and 17 joins operations that take more time to execution. Now create one materialized view for each sub-SELECT statement.
261
+
Check the query's estimated execution plan. There are 18 shuffles and 17 joins operations which take more time to execute. Now let's create one materialized view for each of the three sub-SELECT statements.
262
262
263
263
```sql
264
264
CREATE materialized view nbViewSS WITH (DISTRIBUTION=HASH(customer_id)) AS
@@ -285,7 +285,7 @@ GROUP BY c_customer_id
285
285
,c_login
286
286
,c_email_address
287
287
,d_year
288
-
288
+
GO
289
289
CREATE materialized view nbViewCS WITH (DISTRIBUTION=HASH(customer_id)) AS
290
290
SELECT c_customer_id customer_id
291
291
,c_first_name customer_first_name
@@ -311,7 +311,7 @@ GROUP BY c_customer_id
311
311
,c_email_address
312
312
,d_year
313
313
314
-
314
+
GO
315
315
CREATE materialized view nbViewWS WITH (DISTRIBUTION=HASH(customer_id)) AS
316
316
SELECT c_customer_id customer_id
317
317
,c_first_name customer_first_name
@@ -338,5 +338,9 @@ GROUP BY c_customer_id
338
338
,d_year
339
339
340
340
```
341
-
Check the original query's estimated execution plan again. The number of shuffles changes from 18 to # and the number of joins changes from 17 to #. Hover over the join operator icons in the plan, the Output List shows the data is produced from the materialized views instead of base tables. By getting data from materialized views, the query execution has fewer expensive operations and finishes much faster with no code change.
341
+
Check the execution plan of the original query again. Now the number of joins changes from 17 to 5 and there's no shuffle anymore. Click the Filter operation icon in the plan, its Output List shows the data is read from the materialized views instead of base tables.
0 commit comments