SlideShare a Scribd company logo
1 of 33
Download to read offline
By Louis liu www.vmcd.org
DBMS_STATS Advanced Tips
This article is major to introduce advanced usage of dbms_stats for CG(column group ) of extened statistics.
We start this test on oracle 11.2.0.3 oel5.8 64bit :
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> show user
USER is "TEST"
SQL> CREATE TABLE sampletable( id NUMBER,
By Louis liu www.vmcd.org
2 hotelname VARCHAR2(50),
city VARCHAR2(50),
country VARCHAR2(20));
INSERT INTO sampletable VALUES( 1, 'Pullman','Barcelona','Spain' );
INSERT INTO sampletable VALUES( 2, 'Gran Melia Fenix','Madrid','Spain' );
INSERT INTO sampletable VALUES( 3, 'Melia Castilla','Madrid','Spain' );
INSERT INTO sampletable VALUES( 4, 'Trump International','New York','US' );
INSERT INTO sampletable VALUES( 5, 'Four Seasons','New York','US' );
INSERT INTO sampletable VALUES( 6, 'Ambasciatori Palace','Rome','Italy' );
COMMIT; 3 4
Table created.
By Louis liu www.vmcd.org
SQL> SQL>
1 row created.
SQL>
1 row created.
SQL>
1 row created.
SQL>
1 row created.
SQL>
By Louis liu www.vmcd.org
1 row created.
SQL>
1 row created.
SQL>
Commit complete.
Now gather table statistics
By Louis liu www.vmcd.org
SQL> EXEC SYS.DBMS_STATS.GATHER_TABLE_STATS (OwnName => 'TEST', TabName => 'sampletable', Method_Opt => 'FOR
ALL COLUMNS size 254', Cascade => TRUE );
PL/SQL procedure successfully completed.
SQL> SELECT COLUMN_NAME, NUM_DISTINCT FROM DBA_TAB_COL_STATISTICS WHERE TABLE_NAME = 'SAMPLETABLE';
COLUMN_NAME NUM_DISTINCT
------------------------------ ------------
COUNTRY 3
CITY 4
By Louis liu www.vmcd.org
HOTELNAME 6
ID 6
SQL> conn test/test
Connected.
SQL> EXPLAIN PLAN FOR SELECT * FROM sampletable WHERE city = 'Madrid';
Explained.
SQL> SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY( format => 'ALLSTATS' ));
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------
By Louis liu www.vmcd.org
------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 2813936524
--------------------------------------------------
| Id | Operation | Name | E-Rows |
--------------------------------------------------
| 0 | SELECT STATEMENT | | 2 |
|* 1 | TABLE ACCESS FULL| SAMPLETABLE | 2 |
--------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
By Louis liu www.vmcd.org
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
1 - filter("CITY"='Madrid')
Note
-----
- Warning: basic plan statistics not available. These are only collected when:
* hint 'gather_plan_statistics' is used for the statement or
* parameter 'statistics_level' is set to 'ALL', at session or system level
19 rows selected.
By Louis liu www.vmcd.org
SQL> EXPLAIN PLAN FOR SELECT * FROM sampletable WHERE country = 'Spain';
Explained.
SQL> SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY( format => 'ALLSTATS' ));
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 2813936524
--------------------------------------------------
By Louis liu www.vmcd.org
| Id | Operation | Name | E-Rows |
--------------------------------------------------
| 0 | SELECT STATEMENT | | 3 |
|* 1 | TABLE ACCESS FULL| SAMPLETABLE | 3 |
--------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
By Louis liu www.vmcd.org
1 - filter("COUNTRY"='Spain')
Note
-----
- Warning: basic plan statistics not available. These are only collected when:
* hint 'gather_plan_statistics' is used for the statement or
* parameter 'statistics_level' is set to 'ALL', at session or system level
19 rows selected.
By Louis liu www.vmcd.org
Use dbms_stats.seed_col_usage turns on monitoring for 5 minutes or 300 seconds
SQL> begin
2 dbms_stats.seed_col_usage(null,null,300);
3 end;
4 /
PL/SQL procedure successfully completed.
SQL> EXPLAIN PLAN FOR SELECT * FROM sampletable WHERE city = 'Madrid' and country = 'Spain';
Explained.
By Louis liu www.vmcd.org
SQL> SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY( format => 'ALLSTATS' ));
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 2813936524
--------------------------------------------------
| Id | Operation | Name | E-Rows |
--------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | ------------------->incorrect
|* 1 | TABLE ACCESS FULL| SAMPLETABLE | 1 |
--------------------------------------------------
By Louis liu www.vmcd.org
Predicate Information (identified by operation id):
---------------------------------------------------
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
1 - filter("CITY"='Madrid' AND "COUNTRY"='Spain')
Note
-----
- Warning: basic plan statistics not available. These are only collected when:
By Louis liu www.vmcd.org
* hint 'gather_plan_statistics' is used for the statement or
* parameter 'statistics_level' is set to 'ALL', at session or system level
19 rows selected.
SQL> set long 90000
SQL> set lines 2000
SQL> set pages 500
SQL> select dbms_stats.report_col_usage('TEST','SAMPLETABLE') from dual;
DBMS_STATS.REPORT_COL_USAGE('TEST','SAMPLETABLE')
--------------------------------------------------------------------------------
LEGEND:
By Louis liu www.vmcd.org
.......
EQ : Used in single table EQuality predicate
RANGE : Used in single table RANGE predicate
LIKE : Used in single table LIKE predicate
NULL : Used in single table is (not) NULL predicate
EQ_JOIN : Used in EQuality JOIN predicate
NONEQ_JOIN : Used in NON EQuality JOIN predicate
FILTER : Used in single table FILTER predicate
JOIN : Used in JOIN predicate
GROUP_BY : Used in GROUP BY expression
...............................................................................
By Louis liu www.vmcd.org
###############################################################################
COLUMN USAGE REPORT FOR TEST.SAMPLETABLE
........................................
1. CITY : EQ
2. COUNTRY : EQ
3. (CITY, COUNTRY) : FILTER
###############################################################################
Add extended col statistics for columns (CITY,COUNTRY)
By Louis liu www.vmcd.org
SQL>select dbms_stats.create_extended_stats(ownname=>'TEST',tabname=>'SAMPLETABLE',extension=>'(CITY,COUNTRY)')
as sample_extended from dual;
SAMPLE_EXTENDED
------------------------------------------------------------------------------------------------------------------------------------------------------------------
SYS_STU3UJN5IT#IIA5ASKY72Q8V6Z
SQL> select column_name, data_default, virtual_column, hidden_column from dba_tab_cols where table_name =
'SAMPLETABLE';
By Louis liu www.vmcd.org
Virtual column “SYS_STU3UJN5IT#IIA5ASKY72Q8V6Z” use function “SYS_OP_COMBINED_HASH”
SQL> select column_name, ENDPOINT_NUMBER, ENDPOINT_VALUE from user_tab_histograms where table_name =
'SAMPLETABLE';
COLUMN_NAME ENDPOINT_NUMBER ENDPOINT_VALUE
By Louis liu www.vmcd.org
------------------------------------------------------------ --------------- --------------
ID 1 1
ID 2 2
ID 3 3
ID 4 4
ID 5 5
ID 6 6
HOTELNAME 1 3.3972E+35
HOTELNAME 2 3.6572E+35
HOTELNAME 3 3.7097E+35
HOTELNAME 4 4.0186E+35
HOTELNAME 5 4.1777E+35
By Louis liu www.vmcd.org
COLUMN_NAME ENDPOINT_NUMBER ENDPOINT_VALUE
------------------------------------------------------------ --------------- --------------
HOTELNAME 6 4.3847E+35
CITY 1 3.4467E+35
CITY 3 4.0178E+35
CITY 5 4.0706E+35
CITY 6 4.2803E+35
COUNTRY 1 3.8140E+35
COUNTRY 4 4.3324E+35
COUNTRY 6 4.4303E+35
19 rows selected.
By Louis liu www.vmcd.org
SQL> EXEC SYS.DBMS_STATS.GATHER_TABLE_STATS (OwnName => 'TEST', TabName => 'sampletable', Method_Opt =>
'FOR ALL COLUMNS', Cascade => TRUE );
PL/SQL procedure successfully completed.
SQL> select column_name, ENDPOINT_NUMBER, ENDPOINT_VALUE from user_tab_histograms where table_name =
'SAMPLETABLE';
COLUMN_NAME ENDPOINT_NUMBER ENDPOINT_VALUE
------------------------------------------------------------ --------------- --------------
ID 1 1
ID 2 2
ID 3 3
By Louis liu www.vmcd.org
ID 4 4
ID 5 5
ID 6 6
HOTELNAME 1 3.3972E+35
HOTELNAME 2 3.6572E+35
HOTELNAME 3 3.7097E+35
HOTELNAME 4 4.0186E+35
HOTELNAME 5 4.1777E+35
COLUMN_NAME ENDPOINT_NUMBER ENDPOINT_VALUE
------------------------------------------------------------ --------------- --------------
HOTELNAME 6 4.3847E+35
CITY 1 3.4467E+35
By Louis liu www.vmcd.org
CITY 3 4.0178E+35
CITY 5 4.0706E+35
CITY 6 4.2803E+35
COUNTRY 1 3.8140E+35
COUNTRY 4 4.3324E+35
COUNTRY 6 4.4303E+35
SYS_STU3UJN5IT#IIA5ASKY72Q8V6Z 1 511644451
SYS_STU3UJN5IT#IIA5ASKY72Q8V6Z 3 3090128096
SYS_STU3UJN5IT#IIA5ASKY72Q8V6Z 5 9086239935
COLUMN_NAME ENDPOINT_NUMBER ENDPOINT_VALUE
------------------------------------------------------------ --------------- --------------
SYS_STU3UJN5IT#IIA5ASKY72Q8V6Z 6 9933106351
By Louis liu www.vmcd.org
23 rows selected.
SQL> EXPLAIN PLAN FOR SELECT * FROM sampletable WHERE country = 'Spain' and city = 'Madrid' ;
Explained.
SQL> SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY( format => 'ALLSTATS' ));
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------
Plan hash value: 2813936524
By Louis liu www.vmcd.org
--------------------------------------------------
| Id | Operation | Name | E-Rows |
--------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | -----------------------------> correct
|* 1 | TABLE ACCESS FULL| SAMPLETABLE | 2 |
--------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------
By Louis liu www.vmcd.org
--------------------------------------
1 - filter("CITY"='Madrid' AND "COUNTRY"='Spain')
Note
-----
- Warning: basic plan statistics not available. These are only collected when:
* hint 'gather_plan_statistics' is used for the statement or
* parameter 'statistics_level' is set to 'ALL', at session or system level
19 rows selected.
By Louis liu www.vmcd.org
use 10053 event to trace correlation of these two columns.
SQL> conn /as sysdba
Connected.
SQL> oradebug setmypid
Statement processed.
SQL> oradebug unlimit
Statement processed.
SQL> oradebug event 10053 trace name context forever, level 1
Statement processed.
SQL>
SQL> EXPLAIN PLAN FOR SELECT * FROM TEST.sampletable WHERE country = 'Spain' and city = 'Madrid' ;
By Louis liu www.vmcd.org
Explained.
SQL> oradebug event 10053 trace name context off
Statement processed.
SQL>
SQL> oradebug tracefile_name
/data/app1/oracle/diag/rdbms/testdb/testdb/trace/testdb_ora_8233.trc
By Louis liu www.vmcd.org
Rounded:2 Computer: 2.00
By Louis liu www.vmcd.org
Delete histograms
SQL> EXEC SYS.DBMS_STATS.GATHER_TABLE_STATS (OwnName => 'TEST', TabName => 'sampletable', Method_Opt => 'FOR
ALL COLUMNS size 1',Cascade => TRUE );
By Louis liu www.vmcd.org
Rounded: 2 Computed : 1.50
of rows~= total # of rows * (1/NDV for CITY) * (1/NDV for COUNTRY)*corStrength(correlation strength)
= 6*(1/4)*(1/3)*2=1.5
Delete extended stats
SQL> exec dbms_stats.DROP_EXTENDED_STATS('TEST','SAMPLETABLE','(CITY,COUNTRY)');
PL/SQL procedure successfully completed.
By Louis liu www.vmcd.org
Rounded: 1 Computed : 0.50
of rows~= total # of rows * (1/NDV for CITY) * (1/NDV for COUNTRY) /*corStrength(correlation strength)*/
= 6*(1/4)*(1/3)*1=0.5

More Related Content

What's hot

Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007paulguerin
 
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should KnowOTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should KnowAlex Zaballa
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq lsInSync Conference
 
MySQL partitions tutorial
MySQL partitions tutorialMySQL partitions tutorial
MySQL partitions tutorialGiuseppe Maxia
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?Andrej Pashchenko
 
Oracle 9i notes(kamal.love@gmail.com)
Oracle 9i  notes(kamal.love@gmail.com)Oracle 9i  notes(kamal.love@gmail.com)
Oracle 9i notes(kamal.love@gmail.com)Kamal Raj
 
Oracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New FeaturesOracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New FeaturesAlex Zaballa
 
Oracle Database 12c - Data Redaction
Oracle Database 12c - Data RedactionOracle Database 12c - Data Redaction
Oracle Database 12c - Data RedactionAlex Zaballa
 
Oracle Data Redaction
Oracle Data RedactionOracle Data Redaction
Oracle Data RedactionAlex Zaballa
 
MERGE SQL Statement: Lesser Known Facets
MERGE SQL Statement: Lesser Known FacetsMERGE SQL Statement: Lesser Known Facets
MERGE SQL Statement: Lesser Known FacetsAndrej Pashchenko
 
Database Oracle Basic
Database Oracle BasicDatabase Oracle Basic
Database Oracle BasicKamlesh Singh
 
DataPump ile Single Parititon Export
DataPump ile Single Parititon ExportDataPump ile Single Parititon Export
DataPump ile Single Parititon ExportAnar Godjaev
 
Mysql Explain Explained
Mysql Explain ExplainedMysql Explain Explained
Mysql Explain ExplainedJeremy Coates
 

What's hot (20)

Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
 
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should KnowOTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
 
Les09 Manipulating Data
Les09 Manipulating DataLes09 Manipulating Data
Les09 Manipulating Data
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
 
Oracle training in hyderabad
Oracle training in hyderabadOracle training in hyderabad
Oracle training in hyderabad
 
MySQL partitions tutorial
MySQL partitions tutorialMySQL partitions tutorial
MySQL partitions tutorial
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
 
Sql queries
Sql queriesSql queries
Sql queries
 
Oracle 9i notes(kamal.love@gmail.com)
Oracle 9i  notes(kamal.love@gmail.com)Oracle 9i  notes(kamal.love@gmail.com)
Oracle 9i notes(kamal.love@gmail.com)
 
Oracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New FeaturesOracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New Features
 
Oracle Database 12c - Data Redaction
Oracle Database 12c - Data RedactionOracle Database 12c - Data Redaction
Oracle Database 12c - Data Redaction
 
Oracle Data Redaction
Oracle Data RedactionOracle Data Redaction
Oracle Data Redaction
 
Les09
Les09Les09
Les09
 
MERGE SQL Statement: Lesser Known Facets
MERGE SQL Statement: Lesser Known FacetsMERGE SQL Statement: Lesser Known Facets
MERGE SQL Statement: Lesser Known Facets
 
Database Oracle Basic
Database Oracle BasicDatabase Oracle Basic
Database Oracle Basic
 
DataPump ile Single Parititon Export
DataPump ile Single Parititon ExportDataPump ile Single Parititon Export
DataPump ile Single Parititon Export
 
Les11
Les11Les11
Les11
 
Oracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guideOracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guide
 
dbms lab manual
dbms lab manualdbms lab manual
dbms lab manual
 
Mysql Explain Explained
Mysql Explain ExplainedMysql Explain Explained
Mysql Explain Explained
 

Viewers also liked

How to study oracle by louis liu
How to study oracle by louis liu How to study oracle by louis liu
How to study oracle by louis liu Louis liu
 
Racsig rac internals
Racsig rac internalsRacsig rac internals
Racsig rac internalspv_narayanan
 
Exadata training
Exadata trainingExadata training
Exadata trainingLouis liu
 
Recent my sql_performance Test detail
Recent my sql_performance Test detailRecent my sql_performance Test detail
Recent my sql_performance Test detailLouis liu
 
Optimizer in oracle 11g by wwf from ebay COC
Optimizer in oracle 11g by wwf from ebay COCOptimizer in oracle 11g by wwf from ebay COC
Optimizer in oracle 11g by wwf from ebay COCLouis liu
 
Infiniflash benchmark
Infiniflash benchmarkInfiniflash benchmark
Infiniflash benchmarkLouis liu
 
11g r2 flashcache_Tips
11g r2 flashcache_Tips11g r2 flashcache_Tips
11g r2 flashcache_TipsLouis liu
 

Viewers also liked (7)

How to study oracle by louis liu
How to study oracle by louis liu How to study oracle by louis liu
How to study oracle by louis liu
 
Racsig rac internals
Racsig rac internalsRacsig rac internals
Racsig rac internals
 
Exadata training
Exadata trainingExadata training
Exadata training
 
Recent my sql_performance Test detail
Recent my sql_performance Test detailRecent my sql_performance Test detail
Recent my sql_performance Test detail
 
Optimizer in oracle 11g by wwf from ebay COC
Optimizer in oracle 11g by wwf from ebay COCOptimizer in oracle 11g by wwf from ebay COC
Optimizer in oracle 11g by wwf from ebay COC
 
Infiniflash benchmark
Infiniflash benchmarkInfiniflash benchmark
Infiniflash benchmark
 
11g r2 flashcache_Tips
11g r2 flashcache_Tips11g r2 flashcache_Tips
11g r2 flashcache_Tips
 

Similar to Advanced tips of dbms statas

12c SQL Plan Directives
12c SQL Plan Directives12c SQL Plan Directives
12c SQL Plan DirectivesFranck Pachot
 
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleUnderstanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleGuatemala User Group
 
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스PgDay.Seoul
 
Oracle dbms_xplan.display_cursor format
Oracle dbms_xplan.display_cursor formatOracle dbms_xplan.display_cursor format
Oracle dbms_xplan.display_cursor formatFranck Pachot
 
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Alex Zaballa
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...Alex Zaballa
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...Alex Zaballa
 
Sql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ISql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ICarlos Oliveira
 
SQL Performance Tuning and New Features in Oracle 19c
SQL Performance Tuning and New Features in Oracle 19cSQL Performance Tuning and New Features in Oracle 19c
SQL Performance Tuning and New Features in Oracle 19cRachelBarker26
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowAlex Zaballa
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowAlex Zaballa
 
MySQL InnoDB Cluster 미리보기 (remote cluster test)
MySQL InnoDB Cluster 미리보기 (remote cluster test)MySQL InnoDB Cluster 미리보기 (remote cluster test)
MySQL InnoDB Cluster 미리보기 (remote cluster test)Seungmin Yu
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsAlex Zaballa
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsAlex Zaballa
 
Oracle Database 12c Application Development
Oracle Database 12c Application DevelopmentOracle Database 12c Application Development
Oracle Database 12c Application DevelopmentSaurabh K. Gupta
 

Similar to Advanced tips of dbms statas (20)

12c SQL Plan Directives
12c SQL Plan Directives12c SQL Plan Directives
12c SQL Plan Directives
 
Do You Know The 11g Plan?
Do You Know The 11g Plan?Do You Know The 11g Plan?
Do You Know The 11g Plan?
 
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleUnderstanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
 
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
 
SQLQueries
SQLQueriesSQLQueries
SQLQueries
 
Oracle 12c SPM
Oracle 12c SPMOracle 12c SPM
Oracle 12c SPM
 
Pl sql using_xml
Pl sql using_xmlPl sql using_xml
Pl sql using_xml
 
Oracle dbms_xplan.display_cursor format
Oracle dbms_xplan.display_cursor formatOracle dbms_xplan.display_cursor format
Oracle dbms_xplan.display_cursor format
 
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
Sql
SqlSql
Sql
 
Sql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ISql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices I
 
SQL Performance Tuning and New Features in Oracle 19c
SQL Performance Tuning and New Features in Oracle 19cSQL Performance Tuning and New Features in Oracle 19c
SQL Performance Tuning and New Features in Oracle 19c
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
MySQL InnoDB Cluster 미리보기 (remote cluster test)
MySQL InnoDB Cluster 미리보기 (remote cluster test)MySQL InnoDB Cluster 미리보기 (remote cluster test)
MySQL InnoDB Cluster 미리보기 (remote cluster test)
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Oracle Database 12c Application Development
Oracle Database 12c Application DevelopmentOracle Database 12c Application Development
Oracle Database 12c Application Development
 

More from Louis liu

Tcpcopy benchmark
Tcpcopy benchmarkTcpcopy benchmark
Tcpcopy benchmarkLouis liu
 
JK Log-Center architect
JK Log-Center architectJK Log-Center architect
JK Log-Center architectLouis liu
 
JKDB BACKUP Introduction
JKDB BACKUP IntroductionJKDB BACKUP Introduction
JKDB BACKUP IntroductionLouis liu
 
MySQL Tokudb engine benchmark
MySQL Tokudb engine benchmarkMySQL Tokudb engine benchmark
MySQL Tokudb engine benchmarkLouis liu
 
Nvmfs benchmark
Nvmfs benchmarkNvmfs benchmark
Nvmfs benchmarkLouis liu
 
MySQL 5.7 milestone
MySQL 5.7 milestoneMySQL 5.7 milestone
MySQL 5.7 milestoneLouis liu
 
MySQL Oslayer performace optimization
MySQL  Oslayer performace optimizationMySQL  Oslayer performace optimization
MySQL Oslayer performace optimizationLouis liu
 
MySQL async message subscription platform
MySQL async message subscription platformMySQL async message subscription platform
MySQL async message subscription platformLouis liu
 
HBASE Performane Test
HBASE Performane TestHBASE Performane Test
HBASE Performane TestLouis liu
 
Jkcn MySQLDB 架构
Jkcn MySQLDB 架构Jkcn MySQLDB 架构
Jkcn MySQLDB 架构Louis liu
 
基于Mongodb的压力评测工具 ycsb的一些概括
基于Mongodb的压力评测工具 ycsb的一些概括基于Mongodb的压力评测工具 ycsb的一些概括
基于Mongodb的压力评测工具 ycsb的一些概括Louis liu
 
My sql fabric ha and sharding solutions
My sql fabric ha and sharding solutionsMy sql fabric ha and sharding solutions
My sql fabric ha and sharding solutionsLouis liu
 
NetApp ef540 SSD Storage Test
NetApp ef540 SSD Storage TestNetApp ef540 SSD Storage Test
NetApp ef540 SSD Storage TestLouis liu
 
Exadata best practice on E-commerce area
Exadata best practice on E-commerce area Exadata best practice on E-commerce area
Exadata best practice on E-commerce area Louis liu
 
MySQL 5.5&5.6 new features summary
MySQL 5.5&5.6 new features summaryMySQL 5.5&5.6 new features summary
MySQL 5.5&5.6 new features summaryLouis liu
 
Ssd gc review
Ssd gc reviewSsd gc review
Ssd gc reviewLouis liu
 
1号店数据库架构
1号店数据库架构1号店数据库架构
1号店数据库架构Louis liu
 
Architecture of YHD
Architecture of YHDArchitecture of YHD
Architecture of YHDLouis liu
 

More from Louis liu (20)

Tcpcopy benchmark
Tcpcopy benchmarkTcpcopy benchmark
Tcpcopy benchmark
 
JK Log-Center architect
JK Log-Center architectJK Log-Center architect
JK Log-Center architect
 
Wdt Test
Wdt TestWdt Test
Wdt Test
 
JKDB BACKUP Introduction
JKDB BACKUP IntroductionJKDB BACKUP Introduction
JKDB BACKUP Introduction
 
MySQL Tokudb engine benchmark
MySQL Tokudb engine benchmarkMySQL Tokudb engine benchmark
MySQL Tokudb engine benchmark
 
Nvmfs benchmark
Nvmfs benchmarkNvmfs benchmark
Nvmfs benchmark
 
MySQL 5.7 milestone
MySQL 5.7 milestoneMySQL 5.7 milestone
MySQL 5.7 milestone
 
MySQL Oslayer performace optimization
MySQL  Oslayer performace optimizationMySQL  Oslayer performace optimization
MySQL Oslayer performace optimization
 
MySQL async message subscription platform
MySQL async message subscription platformMySQL async message subscription platform
MySQL async message subscription platform
 
HBASE Performane Test
HBASE Performane TestHBASE Performane Test
HBASE Performane Test
 
Jkcn MySQLDB 架构
Jkcn MySQLDB 架构Jkcn MySQLDB 架构
Jkcn MySQLDB 架构
 
基于Mongodb的压力评测工具 ycsb的一些概括
基于Mongodb的压力评测工具 ycsb的一些概括基于Mongodb的压力评测工具 ycsb的一些概括
基于Mongodb的压力评测工具 ycsb的一些概括
 
My sql fabric ha and sharding solutions
My sql fabric ha and sharding solutionsMy sql fabric ha and sharding solutions
My sql fabric ha and sharding solutions
 
NetApp ef540 SSD Storage Test
NetApp ef540 SSD Storage TestNetApp ef540 SSD Storage Test
NetApp ef540 SSD Storage Test
 
Exadata best practice on E-commerce area
Exadata best practice on E-commerce area Exadata best practice on E-commerce area
Exadata best practice on E-commerce area
 
MySQL 5.5&5.6 new features summary
MySQL 5.5&5.6 new features summaryMySQL 5.5&5.6 new features summary
MySQL 5.5&5.6 new features summary
 
Ssd gc review
Ssd gc reviewSsd gc review
Ssd gc review
 
1号店数据库架构
1号店数据库架构1号店数据库架构
1号店数据库架构
 
Architecture of YHD
Architecture of YHDArchitecture of YHD
Architecture of YHD
 
Oracle dgha
Oracle dghaOracle dgha
Oracle dgha
 

Recently uploaded

Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Recently uploaded (20)

Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

Advanced tips of dbms statas

  • 1. By Louis liu www.vmcd.org DBMS_STATS Advanced Tips This article is major to introduce advanced usage of dbms_stats for CG(column group ) of extened statistics. We start this test on oracle 11.2.0.3 oel5.8 64bit : Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> show user USER is "TEST" SQL> CREATE TABLE sampletable( id NUMBER,
  • 2. By Louis liu www.vmcd.org 2 hotelname VARCHAR2(50), city VARCHAR2(50), country VARCHAR2(20)); INSERT INTO sampletable VALUES( 1, 'Pullman','Barcelona','Spain' ); INSERT INTO sampletable VALUES( 2, 'Gran Melia Fenix','Madrid','Spain' ); INSERT INTO sampletable VALUES( 3, 'Melia Castilla','Madrid','Spain' ); INSERT INTO sampletable VALUES( 4, 'Trump International','New York','US' ); INSERT INTO sampletable VALUES( 5, 'Four Seasons','New York','US' ); INSERT INTO sampletable VALUES( 6, 'Ambasciatori Palace','Rome','Italy' ); COMMIT; 3 4 Table created.
  • 3. By Louis liu www.vmcd.org SQL> SQL> 1 row created. SQL> 1 row created. SQL> 1 row created. SQL> 1 row created. SQL>
  • 4. By Louis liu www.vmcd.org 1 row created. SQL> 1 row created. SQL> Commit complete. Now gather table statistics
  • 5. By Louis liu www.vmcd.org SQL> EXEC SYS.DBMS_STATS.GATHER_TABLE_STATS (OwnName => 'TEST', TabName => 'sampletable', Method_Opt => 'FOR ALL COLUMNS size 254', Cascade => TRUE ); PL/SQL procedure successfully completed. SQL> SELECT COLUMN_NAME, NUM_DISTINCT FROM DBA_TAB_COL_STATISTICS WHERE TABLE_NAME = 'SAMPLETABLE'; COLUMN_NAME NUM_DISTINCT ------------------------------ ------------ COUNTRY 3 CITY 4
  • 6. By Louis liu www.vmcd.org HOTELNAME 6 ID 6 SQL> conn test/test Connected. SQL> EXPLAIN PLAN FOR SELECT * FROM sampletable WHERE city = 'Madrid'; Explained. SQL> SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY( format => 'ALLSTATS' )); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------
  • 7. By Louis liu www.vmcd.org ------------------------------------------------------------------------------------------------------------------------------------------ Plan hash value: 2813936524 -------------------------------------------------- | Id | Operation | Name | E-Rows | -------------------------------------------------- | 0 | SELECT STATEMENT | | 2 | |* 1 | TABLE ACCESS FULL| SAMPLETABLE | 2 | -------------------------------------------------- Predicate Information (identified by operation id): ---------------------------------------------------
  • 8. By Louis liu www.vmcd.org PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------ 1 - filter("CITY"='Madrid') Note ----- - Warning: basic plan statistics not available. These are only collected when: * hint 'gather_plan_statistics' is used for the statement or * parameter 'statistics_level' is set to 'ALL', at session or system level 19 rows selected.
  • 9. By Louis liu www.vmcd.org SQL> EXPLAIN PLAN FOR SELECT * FROM sampletable WHERE country = 'Spain'; Explained. SQL> SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY( format => 'ALLSTATS' )); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------ Plan hash value: 2813936524 --------------------------------------------------
  • 10. By Louis liu www.vmcd.org | Id | Operation | Name | E-Rows | -------------------------------------------------- | 0 | SELECT STATEMENT | | 3 | |* 1 | TABLE ACCESS FULL| SAMPLETABLE | 3 | -------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------
  • 11. By Louis liu www.vmcd.org 1 - filter("COUNTRY"='Spain') Note ----- - Warning: basic plan statistics not available. These are only collected when: * hint 'gather_plan_statistics' is used for the statement or * parameter 'statistics_level' is set to 'ALL', at session or system level 19 rows selected.
  • 12. By Louis liu www.vmcd.org Use dbms_stats.seed_col_usage turns on monitoring for 5 minutes or 300 seconds SQL> begin 2 dbms_stats.seed_col_usage(null,null,300); 3 end; 4 / PL/SQL procedure successfully completed. SQL> EXPLAIN PLAN FOR SELECT * FROM sampletable WHERE city = 'Madrid' and country = 'Spain'; Explained.
  • 13. By Louis liu www.vmcd.org SQL> SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY( format => 'ALLSTATS' )); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------ Plan hash value: 2813936524 -------------------------------------------------- | Id | Operation | Name | E-Rows | -------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | ------------------->incorrect |* 1 | TABLE ACCESS FULL| SAMPLETABLE | 1 | --------------------------------------------------
  • 14. By Louis liu www.vmcd.org Predicate Information (identified by operation id): --------------------------------------------------- PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------ 1 - filter("CITY"='Madrid' AND "COUNTRY"='Spain') Note ----- - Warning: basic plan statistics not available. These are only collected when:
  • 15. By Louis liu www.vmcd.org * hint 'gather_plan_statistics' is used for the statement or * parameter 'statistics_level' is set to 'ALL', at session or system level 19 rows selected. SQL> set long 90000 SQL> set lines 2000 SQL> set pages 500 SQL> select dbms_stats.report_col_usage('TEST','SAMPLETABLE') from dual; DBMS_STATS.REPORT_COL_USAGE('TEST','SAMPLETABLE') -------------------------------------------------------------------------------- LEGEND:
  • 16. By Louis liu www.vmcd.org ....... EQ : Used in single table EQuality predicate RANGE : Used in single table RANGE predicate LIKE : Used in single table LIKE predicate NULL : Used in single table is (not) NULL predicate EQ_JOIN : Used in EQuality JOIN predicate NONEQ_JOIN : Used in NON EQuality JOIN predicate FILTER : Used in single table FILTER predicate JOIN : Used in JOIN predicate GROUP_BY : Used in GROUP BY expression ...............................................................................
  • 17. By Louis liu www.vmcd.org ############################################################################### COLUMN USAGE REPORT FOR TEST.SAMPLETABLE ........................................ 1. CITY : EQ 2. COUNTRY : EQ 3. (CITY, COUNTRY) : FILTER ############################################################################### Add extended col statistics for columns (CITY,COUNTRY)
  • 18. By Louis liu www.vmcd.org SQL>select dbms_stats.create_extended_stats(ownname=>'TEST',tabname=>'SAMPLETABLE',extension=>'(CITY,COUNTRY)') as sample_extended from dual; SAMPLE_EXTENDED ------------------------------------------------------------------------------------------------------------------------------------------------------------------ SYS_STU3UJN5IT#IIA5ASKY72Q8V6Z SQL> select column_name, data_default, virtual_column, hidden_column from dba_tab_cols where table_name = 'SAMPLETABLE';
  • 19. By Louis liu www.vmcd.org Virtual column “SYS_STU3UJN5IT#IIA5ASKY72Q8V6Z” use function “SYS_OP_COMBINED_HASH” SQL> select column_name, ENDPOINT_NUMBER, ENDPOINT_VALUE from user_tab_histograms where table_name = 'SAMPLETABLE'; COLUMN_NAME ENDPOINT_NUMBER ENDPOINT_VALUE
  • 20. By Louis liu www.vmcd.org ------------------------------------------------------------ --------------- -------------- ID 1 1 ID 2 2 ID 3 3 ID 4 4 ID 5 5 ID 6 6 HOTELNAME 1 3.3972E+35 HOTELNAME 2 3.6572E+35 HOTELNAME 3 3.7097E+35 HOTELNAME 4 4.0186E+35 HOTELNAME 5 4.1777E+35
  • 21. By Louis liu www.vmcd.org COLUMN_NAME ENDPOINT_NUMBER ENDPOINT_VALUE ------------------------------------------------------------ --------------- -------------- HOTELNAME 6 4.3847E+35 CITY 1 3.4467E+35 CITY 3 4.0178E+35 CITY 5 4.0706E+35 CITY 6 4.2803E+35 COUNTRY 1 3.8140E+35 COUNTRY 4 4.3324E+35 COUNTRY 6 4.4303E+35 19 rows selected.
  • 22. By Louis liu www.vmcd.org SQL> EXEC SYS.DBMS_STATS.GATHER_TABLE_STATS (OwnName => 'TEST', TabName => 'sampletable', Method_Opt => 'FOR ALL COLUMNS', Cascade => TRUE ); PL/SQL procedure successfully completed. SQL> select column_name, ENDPOINT_NUMBER, ENDPOINT_VALUE from user_tab_histograms where table_name = 'SAMPLETABLE'; COLUMN_NAME ENDPOINT_NUMBER ENDPOINT_VALUE ------------------------------------------------------------ --------------- -------------- ID 1 1 ID 2 2 ID 3 3
  • 23. By Louis liu www.vmcd.org ID 4 4 ID 5 5 ID 6 6 HOTELNAME 1 3.3972E+35 HOTELNAME 2 3.6572E+35 HOTELNAME 3 3.7097E+35 HOTELNAME 4 4.0186E+35 HOTELNAME 5 4.1777E+35 COLUMN_NAME ENDPOINT_NUMBER ENDPOINT_VALUE ------------------------------------------------------------ --------------- -------------- HOTELNAME 6 4.3847E+35 CITY 1 3.4467E+35
  • 24. By Louis liu www.vmcd.org CITY 3 4.0178E+35 CITY 5 4.0706E+35 CITY 6 4.2803E+35 COUNTRY 1 3.8140E+35 COUNTRY 4 4.3324E+35 COUNTRY 6 4.4303E+35 SYS_STU3UJN5IT#IIA5ASKY72Q8V6Z 1 511644451 SYS_STU3UJN5IT#IIA5ASKY72Q8V6Z 3 3090128096 SYS_STU3UJN5IT#IIA5ASKY72Q8V6Z 5 9086239935 COLUMN_NAME ENDPOINT_NUMBER ENDPOINT_VALUE ------------------------------------------------------------ --------------- -------------- SYS_STU3UJN5IT#IIA5ASKY72Q8V6Z 6 9933106351
  • 25. By Louis liu www.vmcd.org 23 rows selected. SQL> EXPLAIN PLAN FOR SELECT * FROM sampletable WHERE country = 'Spain' and city = 'Madrid' ; Explained. SQL> SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY( format => 'ALLSTATS' )); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------ -------------------------------------- Plan hash value: 2813936524
  • 26. By Louis liu www.vmcd.org -------------------------------------------------- | Id | Operation | Name | E-Rows | -------------------------------------------------- | 0 | SELECT STATEMENT | | 2 | -----------------------------> correct |* 1 | TABLE ACCESS FULL| SAMPLETABLE | 2 | -------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------
  • 27. By Louis liu www.vmcd.org -------------------------------------- 1 - filter("CITY"='Madrid' AND "COUNTRY"='Spain') Note ----- - Warning: basic plan statistics not available. These are only collected when: * hint 'gather_plan_statistics' is used for the statement or * parameter 'statistics_level' is set to 'ALL', at session or system level 19 rows selected.
  • 28. By Louis liu www.vmcd.org use 10053 event to trace correlation of these two columns. SQL> conn /as sysdba Connected. SQL> oradebug setmypid Statement processed. SQL> oradebug unlimit Statement processed. SQL> oradebug event 10053 trace name context forever, level 1 Statement processed. SQL> SQL> EXPLAIN PLAN FOR SELECT * FROM TEST.sampletable WHERE country = 'Spain' and city = 'Madrid' ;
  • 29. By Louis liu www.vmcd.org Explained. SQL> oradebug event 10053 trace name context off Statement processed. SQL> SQL> oradebug tracefile_name /data/app1/oracle/diag/rdbms/testdb/testdb/trace/testdb_ora_8233.trc
  • 30. By Louis liu www.vmcd.org Rounded:2 Computer: 2.00
  • 31. By Louis liu www.vmcd.org Delete histograms SQL> EXEC SYS.DBMS_STATS.GATHER_TABLE_STATS (OwnName => 'TEST', TabName => 'sampletable', Method_Opt => 'FOR ALL COLUMNS size 1',Cascade => TRUE );
  • 32. By Louis liu www.vmcd.org Rounded: 2 Computed : 1.50 of rows~= total # of rows * (1/NDV for CITY) * (1/NDV for COUNTRY)*corStrength(correlation strength) = 6*(1/4)*(1/3)*2=1.5 Delete extended stats SQL> exec dbms_stats.DROP_EXTENDED_STATS('TEST','SAMPLETABLE','(CITY,COUNTRY)'); PL/SQL procedure successfully completed.
  • 33. By Louis liu www.vmcd.org Rounded: 1 Computed : 0.50 of rows~= total # of rows * (1/NDV for CITY) * (1/NDV for COUNTRY) /*corStrength(correlation strength)*/ = 6*(1/4)*(1/3)*1=0.5