Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
1. Run 01.query_1.sql
View the SQL Monitor Report.
Note any problems with the SQL execution.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
SQL> SELECT /*+ monitor */
2 SUM(lo_quantity) lo_quantity,
3 SUM(lo_revenue) lo_revenue,
4 SUM(lo_supplycost) lo_supplycost
5 FROM lineorder
6 WHERE lo_promotion_id=192000
7 AND lo_orderpriority = '1-URGENT'
8 AND lo_shipmode = 'MAIL'
9 /
LO_QUANTITY LO_REVENUE LO_SUPPLYCOST
---------------- ------------------ ----------------
16044.00 2310218805.00 57579017.00
Elapsed: 00:00:02.49
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise 2 seconds
Full Table Scan
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
2. Run 02.desc_lineorder.sql
Note any issues between the table columns and how the SQL statement is written.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
SQL> desc lineorder
Name Null? Type
--------------------------------- -------- ----------
LO_ORDERKEY NUMBER
LO_LINENUMBER NUMBER
LO_CUSTKEY NUMBER
LO_PARTKEY NUMBER
LO_SUPPKEY NUMBER
LO_ORDERDATE DATE
LO_ORDERPRIORITY VARCHAR2(15)
LO_SHIPPRIORITY VARCHAR2(1)
LO_QUANTITY NUMBER
LO_EXTENDEDPRICE NUMBER
LO_ORDTOTALPRICE NUMBER
LO_DISCOUNT NUMBER
LO_REVENUE NUMBER
LO_SUPPLYCOST NUMBER
LO_TAX NUMBER
LO_COMMITDATE DATE
LO_SHIPMODE VARCHAR2(10)
LO_PROMOTION_ID VARCHAR2(6)
LO_PROMOTION_ID is a VARCHAR2
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
3. Run 03.query_1.sql
View the SQL Monitor Report.
Why is the SQL statement executing faster now?
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
SQL> @03.query_1.sql
SQL>
SQL> SELECT /*+ monitor */
2 SUM(lo_quantity) lo_quantity,
3 SUM(lo_revenue) lo_revenue,
4 SUM(lo_supplycost) lo_supplycost
5 FROM lineorder
6 WHERE lo_promotion_id='192000'
7 AND lo_orderpriority = '1-URGENT'
8 AND lo_shipmode = 'MAIL'
9 /
LO_QUANTITY LO_REVENUE LO_SUPPLYCOST
---------------- ------------------ ----------------
16044.00 2310218805.00 57579017.00
Elapsed: 00:00:00.76
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
1 second
Index Scan
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
4. Run 04.query_2.sql
View the SQL Monitor Report.
Note any problems with the SQL execution.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
SQL> @04.query_2.sql
SQL>
SQL> SELECT /*+ monitor */
2 SUM(lo_quantity) lo_quantity,
3 SUM(lo_revenue) lo_revenue,
4 SUM(lo_supplycost) lo_supplycost
5 FROM lineorder
6 WHERE lo_promotion_id='100000'
7 AND lo_orderpriority = '1-URGENT'
8 AND lo_shipmode = 'MAIL'
9 /
LO_QUANTITY LO_REVENUE LO_SUPPLYCOST
---------------- ------------------ ----------------
833238.00 118720566967.00 2945197263.00
Elapsed: 00:01:41.47
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
101 seconds
Index Scan Poor Cardinality Estimate
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
5. Run 05.check_lineorder_stats.sql
Note any issues with the table stats relative to the two queries.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
TABLE_NAME COLUMN_NAME HISTOGRAM
------------------------------ ------------------------------ ---------------
LINEORDER LO_COMMITDATE NONE
LINEORDER LO_CUSTKEY NONE
LINEORDER LO_DISCOUNT NONE
LINEORDER LO_EXTENDEDPRICE NONE
LINEORDER LO_LINENUMBER NONE
LINEORDER LO_ORDERDATE NONE
LINEORDER LO_ORDERKEY NONE
LINEORDER LO_ORDERPRIORITY NONE
LINEORDER LO_ORDTOTALPRICE NONE
LINEORDER LO_PARTKEY NONE
LINEORDER LO_PROMOTION_ID NONE
LINEORDER LO_QUANTITY NONE
LINEORDER LO_REVENUE NONE
LINEORDER LO_SHIPMODE NONE
LINEORDER LO_SHIPPRIORITY NONE
LINEORDER LO_SUPPKEY NONE
LINEORDER LO_SUPPLYCOST NONE
LINEORDER LO_TAX NONE
No Histograms
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
6. Run 06.gather_stats_lineorder.sql
Regather stats on the lineorder table.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
SQL> @06.gather_stats_lineorder.sql
SQL>
SQL> exec dbms_stats.gather_table_stats(user, 'LINEORDER', degree=>4);
PL/SQL procedure successfully completed.
Elapsed: 00:01:29.43
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
7. Run 07.check_lineorder_stats.sql
What changed with the stats on the lineorder table?
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
TABLE_NAME COLUMN_NAME HISTOGRAM
------------------------------ ------------------------------ ---------------
LINEORDER LO_COMMITDATE NONE
LINEORDER LO_CUSTKEY NONE
LINEORDER LO_DISCOUNT NONE
LINEORDER LO_EXTENDEDPRICE NONE
LINEORDER LO_LINENUMBER NONE
LINEORDER LO_ORDERDATE NONE
LINEORDER LO_ORDERKEY NONE
LINEORDER LO_ORDERPRIORITY FREQUENCY
LINEORDER LO_ORDTOTALPRICE NONE
LINEORDER LO_PARTKEY NONE
LINEORDER LO_PROMOTION_ID HYBRID
LINEORDER LO_QUANTITY NONE
LINEORDER LO_REVENUE NONE
LINEORDER LO_SHIPMODE FREQUENCY
LINEORDER LO_SHIPPRIORITY NONE
LINEORDER LO_SUPPKEY NONE
LINEORDER LO_SUPPLYCOST NONE
LINEORDER LO_TAX NONE
Histogram on LO_PROMOTION_ID
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
8. Run 08.query_1.sql
Has the execution plan or time for query 1 changed?
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
SQL> @08.query_1.sql
SQL>
SQL> SELECT /*+ monitor */
2 SUM(lo_quantity) lo_quantity,
3 SUM(lo_revenue) lo_revenue,
4 SUM(lo_supplycost) lo_supplycost
5 FROM lineorder
6 WHERE lo_promotion_id='192000'
7 AND lo_orderpriority = '1-URGENT'
8 AND lo_shipmode = 'MAIL'
9 /
LO_QUANTITY LO_REVENUE LO_SUPPLYCOST
---------------- ------------------ ----------------
16044.00 2310218805.00 57579017.00
Elapsed: 00:00:01.06
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
1 second
Index Scan
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
9. Run 09.query_2.sql
Has the execution plan or time for query 2 changed?
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
SQL> @09.query_2.sql
SQL>
SQL> SELECT /*+ monitor */
2 SUM(lo_quantity) lo_quantity,
3 SUM(lo_revenue) lo_revenue,
4 SUM(lo_supplycost) lo_supplycost
5 FROM lineorder
6 WHERE lo_promotion_id='100000'
7 AND lo_orderpriority = '1-URGENT'
8 AND lo_shipmode = 'MAIL'
9 /
LO_QUANTITY LO_REVENUE LO_SUPPLYCOST
---------------- ------------------ ----------------
833238.00 118720566967.00 2945197263.00
Elapsed: 00:00:02.11
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
2 seconds
Full Table Scan Better Cardinality Estimate
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
10. Run 10.query_3.sql
View the SQL Monitor Report.
Note any problems with the SQL execution of query 3.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
SQL> @10.query_3.sql
SQL>
SQL> SELECT /*+ monitor */
2 SUM(lo_quantity) lo_quantity,
3 SUM(lo_revenue) lo_revenue,
4 SUM(lo_supplycost) lo_supplycost
5 FROM lineorder
6 JOIN supplier ON lo_suppkey = s_suppkey
7 WHERE s_nation in ('UNITED KINGDOM')
8 /
LO_QUANTITY LO_REVENUE LO_SUPPLYCOST
---------------- ------------------ ----------------
54160034.00 7714635359678.00 191116713490.00
Elapsed: 00:01:13.58
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
73 seconds
Poor Cardinality Estimates
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
11. Run 11.query_4.sql
View the SQL Monitor Report.
Note any problems with the SQL execution of query 4.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
SQL> SELECT /*+ monitor */
2 d_month, d_year, s_nation,
3 SUM(lo_quantity) lo_quantity,
4 SUM(lo_revenue) lo_revenue,
5 SUM(lo_supplycost) lo_supplycost
6 FROM lineorder
7 JOIN date_dim ON lo_orderdate = d_datekey
8 JOIN part ON lo_partkey = p_partkey
9 JOIN supplier ON lo_suppkey = s_suppkey
10 WHERE d_year = 1994
11 AND s_region in ('ASIA')
12 AND s_nation in ('CHINA')
13 AND s_city in ('CHINA 1',
14 'CHINA 2',
15 'CHINA 3',
16 'CHINA 4',
17 'CHINA 5',
18 'CHINA 6',
19 'CHINA 7',
20 'CHINA 8',
21 'CHINA 9')
22 AND p_mfgr in ('MFGR#1','MFGR#3')
23 GROUP BY d_month, d_year, s_nation
24 ORDER BY d_month, d_year, s_nation
25 /
Elapsed: 00:01:34.13
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise94 seconds
Index ScanPoor Cardinality Estimates
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
12. Run 12.set_parallel.sql
Set the degree of parallel on the tables and indexes.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
alter table CUSTOMER parallel 4;
alter table DATE_DIM parallel 4;
alter table LINEORDER parallel 4;
alter table PART parallel 4;
alter table PROMOTION parallel 4;
alter table SUPPLIER parallel 4;
alter index LO_ORDERDATE parallel 4;
alter index LO_SUPPLIER parallel 4;
alter index LO_CUSTOMER parallel 4;
alter index LO_PART parallel 4;
alter index LO_PROMOTION parallel 4;
alter index SUPPLIER_PK parallel 4;
alter index PART_PK parallel 4;
alter index DATE_DIM_PK parallel 4;
alter index CUSTOMER_PK parallel 4;
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
13. Run 13.query_3.sql
View the SQL Monitor Report.
Note any changes in the execution plan or run time with parallel execution.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
SQL> @13.query_3.sql
SQL>
SQL> SELECT /*+ monitor */
2 SUM(lo_quantity) lo_quantity,
3 SUM(lo_revenue) lo_revenue,
4 SUM(lo_supplycost) lo_supplycost
5 FROM lineorder
6 JOIN supplier ON lo_suppkey = s_suppkey
7 WHERE s_nation in ('UNITED KINGDOM')
8 /
LO_QUANTITY LO_REVENUE LO_SUPPLYCOST
---------------- ------------------ ----------------
54160034.00 7714635359678.00 191116713490.00
Elapsed: 00:00:36.83
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
Faster
Still Index Scan Still Poor Cardinality Estimates
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
14. Run 14.query_4.sql
View the SQL Monitor Report.
Note any changes in the execution plan or run time with parallel execution.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
SQL> SELECT /*+ monitor */
2 d_month, d_year, s_nation,
3 SUM(lo_quantity) lo_quantity,
4 SUM(lo_revenue) lo_revenue,
5 SUM(lo_supplycost) lo_supplycost
6 FROM lineorder
7 JOIN date_dim ON lo_orderdate = d_datekey
8 JOIN part ON lo_partkey = p_partkey
9 JOIN supplier ON lo_suppkey = s_suppkey
10 WHERE d_year = 1994
11 AND s_region in ('ASIA')
12 AND s_nation in ('CHINA')
13 AND s_city in ('CHINA 1',
14 'CHINA 2',
15 'CHINA 3',
16 'CHINA 4',
17 'CHINA 5',
18 'CHINA 6',
19 'CHINA 7',
20 'CHINA 8',
21 'CHINA 9')
22 AND p_mfgr in ('MFGR#1','MFGR#3')
23 GROUP BY d_month, d_year, s_nation
24 ORDER BY d_month, d_year, s_nation
Elapsed: 00:00:19.17
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise18 seconds
Index Scans Poor Cardinality Estimates
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
15. Run 15.check_table_stats.sql
Check the table stats.
Are there any issues with the table stats?
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
TABLE_NAME NUM_ROWS BLOCKS LAST_ANAL
------------------------------ ---------- ---------- ---------
CUSTOMER 270000 3711 10-OCT-14
DATE_DIM 2556 67 10-OCT-14
LINEORDER 53986608 709240 04-MAY-15
PART 800000 9975 26-MAR-15
PROMOTION 946 7 26-MAR-15
SUPPLIER 10 5 26-MAR-15
Supplier only has 10 rows?
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
16. Run 16.check_supplier_column_stats.sql
Check the column stats on the supplier table.
Are there any issues with the column stats?
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
TABLE_NAME COLUMN_NAME NUM_DISTINCT HISTOGRAM
------------------------------ ------------------------------ ------------ ---------------
SUPPLIER S_ADDRESS 10 NONE
SUPPLIER S_CITY 10 NONE
SUPPLIER S_NAME 10 NONE
SUPPLIER S_NATION 9 NONE
SUPPLIER S_PHONE 10 NONE
SUPPLIER S_REGION 4 NONE
SUPPLIER S_SUPPKEY 10 NONE
No histograms on supplier
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
17. Run 17.gather_stats_supplier.sql
Regather stats on the supplier table.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
SQL> exec dbms_stats.gather_table_stats(user, 'SUPPLIER', degree=>4);
PL/SQL procedure successfully completed.
Elapsed: 00:00:02.70
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
18. Run 18.check_table_stats.sql
Check the new stats on the supplier table.
Are there any changes?
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
TABLE_NAME NUM_ROWS BLOCKS LAST_ANAL
------------------------------ ---------- ---------- ---------
CUSTOMER 270000 3711 10-OCT-14
DATE_DIM 2556 67 10-OCT-14
LINEORDER 53986608 709240 04-MAY-15
PART 800000 9975 26-MAR-15
PROMOTION 946 7 26-MAR-15
SUPPLIER 18000 237 04-MAY-15
Accurate row count
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
19. Run 19.check_supplier_column_stats.sql
Check the new column stats on the supplier table.
Are there any changes?
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
TABLE_NAME COLUMN_NAME NUM_DISTINCT HISTOGRAM
------------------------------ ------------------------------ ------------ ---------------
SUPPLIER S_ADDRESS 17886 NONE
SUPPLIER S_CITY 250 FREQUENCY
SUPPLIER S_NAME 17764 NONE
SUPPLIER S_NATION 25 FREQUENCY
SUPPLIER S_PHONE 17912 NONE
SUPPLIER S_REGION 5 FREQUENCY
SUPPLIER S_SUPPKEY 18000 NONE
Histograms
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
20. Run 20.query_3.sql
Run query 3 and note any differences in the execution plan and time.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
SQL> @20.query_3.sql
SQL>
SQL> SELECT /*+ monitor */
2 SUM(lo_quantity) lo_quantity,
3 SUM(lo_revenue) lo_revenue,
4 SUM(lo_supplycost) lo_supplycost
5 FROM lineorder
6 JOIN supplier ON lo_suppkey = s_suppkey
7 WHERE s_nation in ('UNITED KINGDOM')
8 /
LO_QUANTITY LO_REVENUE LO_SUPPLYCOST
---------------- ------------------ ----------------
54160034.00 7714635359678.00 191116713490.00
Elapsed: 00:00:05.89
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On ExerciseFaster
Full table scans Better Cardinality Estimates
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
21. Run 21.query_4.sql
Run query 4 and note any differences in the execution plan and time.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
SQL> SELECT /*+ monitor */
2 d_month, d_year, s_nation,
3 SUM(lo_quantity) lo_quantity,
4 SUM(lo_revenue) lo_revenue,
5 SUM(lo_supplycost) lo_supplycost
6 FROM lineorder
7 JOIN date_dim ON lo_orderdate = d_datekey
8 JOIN part ON lo_partkey = p_partkey
9 JOIN supplier ON lo_suppkey = s_suppkey
10 WHERE d_year = 1994
11 AND s_region in ('ASIA')
12 AND s_nation in ('CHINA')
13 AND s_city in ('CHINA 1',
14 'CHINA 2',
15 'CHINA 3',
16 'CHINA 4',
17 'CHINA 5',
18 'CHINA 6',
19 'CHINA 7',
20 'CHINA 8',
21 'CHINA 9')
22 AND p_mfgr in ('MFGR#1','MFGR#3')
23 GROUP BY d_month, d_year, s_nation
24 ORDER BY d_month, d_year, s_nation
25 /
Elapsed: 00:00:19.90
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise20 seconds
Still Index Scan Still Poor Cardinality Estimates
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
22. Run 22.column_group_supplier.sql
Create a column group on the supplier table and regather stats.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
SQL> select dbms_stats.create_extended_stats
(user, 'SUPPLIER', '(S_REGION,S_NATION,S_CITY)') col_group from dual;
COL_GROUP
------------------------------
SYS_STU1_R3P$YT6XRQT9PK4LXF74J
SQL> exec dbms_stats.gather_table_stats(user, 'SUPPLIER', degree=>4);
PL/SQL procedure successfully completed.
Elapsed: 00:00:01.86
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
23. Run 23.query_4.sql
Run query 4.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
SQL> SELECT /*+ monitor */
2 d_month, d_year, s_nation,
3 SUM(lo_quantity) lo_quantity,
4 SUM(lo_revenue) lo_revenue,
5 SUM(lo_supplycost) lo_supplycost
6 FROM lineorder
7 JOIN date_dim ON lo_orderdate = d_datekey
8 JOIN part ON lo_partkey = p_partkey
9 JOIN supplier ON lo_suppkey = s_suppkey
10 WHERE d_year = 1994
11 AND s_region in ('ASIA')
12 AND s_nation in ('CHINA')
13 AND s_city in ('CHINA 1',
14 'CHINA 2',
15 'CHINA 3',
16 'CHINA 4',
17 'CHINA 5',
18 'CHINA 6',
19 'CHINA 7',
20 'CHINA 8',
21 'CHINA 9')
22 AND p_mfgr in ('MFGR#1','MFGR#3')
23 GROUP BY d_month, d_year, s_nation
24 ORDER BY d_month, d_year, s_nation
25 /
Elapsed: 00:00:21.11
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise21 seconds
Still Index ScanStill Poor Cardinality Estimates
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
24. Run 24.check_supplier_column_stats.sql
Check the column stats on the supplier table.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
TABLE_NAME COLUMN_NAME NUM_DISTINCT HISTOGRAM
------------------------------ ------------------------------ ------------ ---------------
SUPPLIER SYS_STU1_R3P$YT6XRQT9PK4LXF74J 250 NONE
SUPPLIER S_ADDRESS 17886 NONE
SUPPLIER S_CITY 250 FREQUENCY
SUPPLIER S_NAME 17764 NONE
SUPPLIER S_NATION 25 FREQUENCY
SUPPLIER S_PHONE 17912 NONE
SUPPLIER S_REGION 5 FREQUENCY
SUPPLIER S_SUPPKEY 18000 NONE
No Histogram
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
25. Run 25.gather_stats_supplier.sql
Regather stats on the supplier table.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
SQL> @25.gather_stats_supplier.sql
SQL>
SQL> exec dbms_stats.gather_table_stats(user, 'SUPPLIER', degree=>4);
PL/SQL procedure successfully completed.
Elapsed: 00:00:02.57
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
26. Run 26.check_supplier_column_stats.sql
Check the column stats on the supplier table.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
TABLE_NAME COLUMN_NAME NUM_DISTINCT HISTOGRAM
------------------------------ ------------------------------ ------------ ---------------
SUPPLIER SYS_STU1_R3P$YT6XRQT9PK4LXF74J 250 FREQUENCY
SUPPLIER S_ADDRESS 17886 NONE
SUPPLIER S_CITY 250 FREQUENCY
SUPPLIER S_NAME 17764 NONE
SUPPLIER S_NATION 25 FREQUENCY
SUPPLIER S_PHONE 17912 NONE
SUPPLIER S_REGION 5 FREQUENCY
SUPPLIER S_SUPPKEY 18000 NONE
Histogram
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
27. Run 27.query_4.sql
Run query 4.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise
SQL> SELECT /*+ monitor */
2 d_month, d_year, s_nation,
3 SUM(lo_quantity) lo_quantity,
4 SUM(lo_revenue) lo_revenue,
5 SUM(lo_supplycost) lo_supplycost
6 FROM lineorder
7 JOIN date_dim ON lo_orderdate = d_datekey
8 JOIN part ON lo_partkey = p_partkey
9 JOIN supplier ON lo_suppkey = s_suppkey
10 WHERE d_year = 1994
11 AND s_region in ('ASIA')
12 AND s_nation in ('CHINA')
13 AND s_city in ('CHINA 1',
14 'CHINA 2',
15 'CHINA 3',
16 'CHINA 4',
17 'CHINA 5',
18 'CHINA 6',
19 'CHINA 7',
20 'CHINA 8',
21 'CHINA 9')
22 AND p_mfgr in ('MFGR#1','MFGR#3')
23 GROUP BY d_month, d_year, s_nation
24 ORDER BY d_month, d_year, s_nation
25 /
Elapsed: 00:00:01.28
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
RWP Training SQL Hands-On Exercise1 second
Full table scan Better Cardinality Estimates