Unit 2 Query Plan
Unit 2 Query Plan
DEPARTMENT
Different Schemas
Different Costs
Different Schemas
Different Costs
Even if the schemas are the same, the optimizer can choose different execution plans if the costs
are different. Some factors that affect the costs include the following:
The PLAN_TABLE is automatically created as a global temporary table to hold the output of
an EXPLAIN PLAN statement for all users. PLAN_TABLE is the default sample output table
into which the EXPLAIN PLAN statement inserts rows describing execution plans
Display
EXPLAIN PLAN
Display output:
SELECT PLAN_TABLE_OUTPUT
https://docs.oracle.com/cd/B19306_01/server.102/b14211/ex_plan.htm#i21501
https://docs.oracle.com/cd/B19306_01/server.102/b14211/ex_plan.htm#i17492
Selection
For example, suppose column age has max value 25 and min value 18. We have
selection condition, age<= 20. Total number of records in table is 100. Then size
estimate is calculated as,
i.e.; approximately 29 records can be fetched from the table with age <=20. Suppose
the condition is age<15, then the probability of getting such records is zero; no records
are present with such age.
Cartesian Product
suppose we have 100 records in EMP and 5 records in DEPT. Say selectivity of table
EMP is 5 (columns) and DEPT is 3 (columns). Then cartesian product will have 500
records into the result set, copying 8 bytes of each record.
For example, assume left outer join between EMP and PROJECT. Let EMP has 1000
records and PROJECT has 30 records.
The left outer join between these two tables will have normal join between them for the
matching records and all other records from EMP for which there is no match in
PROJECT.
Projection
This is the operation of selecting particular column/s from a table. Hence its size
estimate is equal to number of distinct values of column/s present in the table.
Size estimate of selecting the column EMP_ID in EMP table is equal to total number of
records in EMP, since EMP_ID is the primary key. Let us assume there are only 6
different values for AGE in EMP. Then size estimate for projecting AGE from EMP is 6.
Aggregation
This is similar to projection. Here distinct values of column are grouped and their
aggregate values (like count, sum, max, min etc) are calculated. Hence its size estimate
is equal to number of distinct values of column present in the table.