Documente Academic
Documente Profesional
Documente Cultură
Join order
Join method
Access method
Example Query
SQL> 2 3 4 5 6 7 8 9 10 11 select sale_date, product_name, customer_name, amount from sales, products, customers where sales.product_number=products.product_number and sales.customer_number=customers.customer_number and sale_date between to_date('01/01/2012','MM/DD/YYYY') and to_date('01/31/2012','MM/DD/YYYY') and product_type = 'Cheese' and customer_state = 'FL'; PRODUCT_NAME -----------Feta Chedder Feta Chedder CUSTOMER_NAME AMOUNT ----------------- ---------Sunshine State Co 300 Sunshine State Co 100 Green Valley Inc 400 Green Valley Inc 200
Join Order
Join Order = order in which tables in from clause are joined
join 1
customers
sales
products
join 1
sales
customers
products
Selectivity
Selectivity = percentage of rows accessed versus total rows
Selectivity of sub-tree
select count(*) from sales, products where sales.product_number=products.product_number and sale_date between to_date('01/01/2012','MM/DD/YYYY') and to_date('01/31/2012','MM/DD/YYYY') and product_type = 'Cheese';
SQL> 3 4 5 6 7 8
SQL> 2 3 4
COUNT(*) ---------4
Cardinality Hint
SQL> 2 3 4 5 6 7 8 9 10 11 select /*+cardinality(sales 1) */ sale_date, product_name, customer_name, amount from sales, products, customers where sales.product_number=products.product_number and sales.customer_number=customers.customer_number and sale_date between to_date('01/01/2012','MM/DD/YYYY') and to_date('01/31/2012','MM/DD/YYYY') and product_type = 'Cheese' and customer_state = 'FL'; PRODUCT_NAME -----------Feta Chedder Feta Chedder CUSTOMER_NAME AMOUNT ----------------- ---------Sunshine State Co 300 Sunshine State Co 100 Green Valley Inc 400 Green Valley Inc 200
Leading Hint
SQL> 2 3 4 5 6 7 8 9 10 11 select /*+leading(sales) */ sale_date, product_name, customer_name, amount from sales, products, customers where sales.product_number=products.product_number and sales.customer_number=customers.customer_number and sale_date between to_date('01/01/2012','MM/DD/YYYY') and to_date('01/31/2012','MM/DD/YYYY') and product_type = 'Cheese' and customer_state = 'FL'; PRODUCT_NAME -----------Feta Chedder Feta Chedder CUSTOMER_NAME AMOUNT ----------------- ---------Sunshine State Co 300 Sunshine State Co 100 Green Valley Inc 400 Green Valley Inc 200
Table created.
4 rows created.
Join Methods
Join Method = way that data from two sources is joined
Nested Loops
Small number of rows in first table Unique index on second large table Hash Join Smaller or equal number of rows in first table
No index required
use_hash
use_nl Add Index Hash_area_size parameter
Access Methods
Access method = way that data is retrieved from table
optimizer_index_caching
optimizer_index_cost_adj db_file_multiblock_read_count Set Parallel Degree > 1 Hints Full Index
Conclusion
Use count queries to determine selective parts of where clause
Modify the join order, join methods, and access methods using
Optimizer statistics Hints Initialization parameters Breaking the query into pieces Parallel degree Indexes Compare elapsed time of query with new plan to original
Elapsed: 00:00:00.00
Further Reading
Oracle Database Concepts Chapter 7 SQL Oracle Database Performance Tuning Guide Chapter 11 The Query Optimizer Chapter 19 Using Optimizer Hints Oracle Database Reference