SQL Tuning Guide - pt7
SQL Tuning Guide - pt7
LEGEND:
.......
####################################################################
####
1. COUNTRY_ID : EQ
2. CUST_CITY : EQ
3. CUST_STATE_PROVINCE : EQ
4. (CUST_CITY, CUST_STATE_PROVINCE,
COUNTRY_ID) : FILTER
5. (CUST_STATE_PROVINCE, COUNTRY_ID) : GROUP_BY
####################################################################
####
In the preceding report, the first three columns were used in equality predicates in
the first monitored query:
...
WHERE cust_city = 'Los Angeles'
AND cust_state_province = 'CA'
AND country_id = 52790;
All three columns appeared in the same WHERE clause, so the report shows them
as a group filter. In the second query, two columns appeared in the GROUP BY
clause, so the report labels them as GROUP_BY. The sets of columns in the FILTER
and GROUP_BY report are candidates for column groups.
14-8
Chapter 14
Managing Column Group Statistics
See Also:
Assumptions
This tutorial assumes that you have performed the steps in "Detecting Useful Column Groups
for a Specific Workload".
########################################################################
EXTENSIONS FOR SH.CUSTOMERS_TEST
................................
1. (CUST_CITY, CUST_STATE_PROVINCE,
COUNTRY_ID) :SYS_STUMZ$C3AIHLPBROI#SKA58H_N
created
2. (CUST_STATE_PROVINCE, COUNTRY_ID):SYS_STU#S#WF25Z#QAHIHE#MOFFMM_
created
########################################################################
The database created two column groups for customers_test: one column group for the
filter predicate and one group for the GROUP BY operation.
2. Regather table statistics.
Run GATHER_TABLE_STATS to regather the statistics for customers_test:
EXEC DBMS_STATS.GATHER_TABLE_STATS(user,'customers_test');
3. As user sh, run explain plans for two queries in the workload.
14-9
Chapter 14
Managing Column Group Statistics
This example shows the two column group names returned from the
DBMS_STATS.CREATE_EXTENDED_STATS function. The column group created on
CUST_CITY, CUST_STATE_PROVINCE, and COUNTRY_ID has a height-balanced
histogram.
4. Explain the plans again.
The following examples show the explain plans for two queries on the
customers_test table:
SELECT PLAN_TABLE_OUTPUT
FROM TABLE(DBMS_XPLAN.DISPLAY('plan_table', null,'basic rows'));
SELECT PLAN_TABLE_OUTPUT
FROM TABLE(DBMS_XPLAN.DISPLAY('plan_table', null,'basic rows'));
----------------------------------------------------
| Id | Operation | Name | Rows |
----------------------------------------------------
| 0 | SELECT STATEMENT | | 1093 |
| 1 | TABLE ACCESS FULL| CUSTOMERS_TEST | 1093 |
----------------------------------------------------
8 rows selected.
14-10
Chapter 14
Managing Column Group Statistics
-----------------------------------------------------
| Id | Operation | Name | Rows |
-----------------------------------------------------
| 0 | SELECT STATEMENT | | 145 |
| 1 | HASH GROUP BY | | 145 |
| 2 | TABLE ACCESS FULL| CUSTOMERS_TEST | 55500 |
-----------------------------------------------------
9 rows selected.
See Also:
Oracle Database PL/SQL Packages and Types Reference to learn about the
DBMS_STATS package
Assumptions
This tutorial assumes the following:
• You want to create a column group for the cust_state_province and country_id
columns in the customers table in sh schema.
• You want to gather statistics (including histograms) on the entire table and the new
column group.
BEGIN
DBMS_STATS.GATHER_TABLE_STATS( 'sh','customers',
METHOD_OPT => 'FOR ALL COLUMNS SIZE SKEWONLY ' ||
'FOR COLUMNS SIZE SKEWONLY (cust_state_province,country_id)' );
END;
/
14-11
Chapter 14
Managing Column Group Statistics
See Also:
Oracle Database PL/SQL Packages and Types Reference to learn about the
DBMS_STATS.GATHER_TABLE_STATS procedure
You can also use views to obtain information such as the number of distinct values,
and whether the column group has a histogram.
Assumptions
This tutorial assumes the following:
• You created a column group for the cust_state_province and country_id
columns in the customers table in sh schema.
• You want to determine the column group name, the number of distinct values, and
whether a histogram has been created for a column group.
COL_GROUP_NAME
----------------
SYS_STU#S#WF25Z#QAHIHE#MOFFMM_
EXTENSION_NAME EXTENSION
-----------------------------------------------------------------
---
14-12
Chapter 14
Managing Column Group Statistics
SYS_STU#S#WF25Z#QAHIHE#MOFFMM_ ("CUST_STATE_PROVINCE","COUNTRY_ID")
3. Query the number of distinct values and find whether a histogram has been created for a
column group.
For example, run the following query:
See Also:
Oracle Database PL/SQL Packages and Types Reference to learn about the
DBMS_STATS.SHOW_EXTENDED_STATS_NAME function
Assumptions
This tutorial assumes the following:
• You created a column group for the cust_state_province and country_id columns in
the customers table in sh schema.
• You want to drop the column group.
BEGIN
DBMS_STATS.DROP_EXTENDED_STATS( 'sh', 'customers',
'(cust_state_province, country_id)' );
END;
/
14-13