Karl Reitschuster researches CBO cardinality
blog has some really good insights into the behavior of Oracle
cost-based SQL optimizer regarding how Oracle estimates
cardinality. Cardinality estimates are used when the optimizer
makes important decisions such as how to access a table, which index
to use, and what order to join tables together:
notes that when dealing with flat files (SQL*Loader, Oracle import,
external tables), Oracle seems to use a cardinality=1:
strange thing is the estimated Cardinality of the FULL Table Scan.
The optimizer believed that only one Compare between the
MainCustomer Column and the SubCustomer Column would meet the
Predicate. . .
estimates it’s costs in for a relational database (You may never
forget that). It believes that all important relational rules are
kept. Specially the rule of normalization. The Relationship designed
in the import table is flat and not expressible via a foreign key
explores the impact of CBO cardinality estimation of the choices of
join methods (nested loop vs. hash join) and demonstrates the use of
the CARDINALITY hint to force a hash join:
Oracle joins depends very strongly (sic) on the expected Cardinality
of the joined table.
Cardinality -> Nested Loops
. . .
Cardinality -> HASH JOIN
following example the true expected cardinality (sic) of the
operation was set via the CARDINALITY Hint. This hint makes only
sense if you now that the Cardinality is often the same which is
sometimes given for external application data or for static data.”
look at explain try to concentrate on the cardinality. It has a very
big impact on the design of the whole execution plan. Miss
estimations can lead to SQL’s with dramatically increased response