A method, database system, and computer program are disclosed for
optimized costing. The method includes identifying a join that identifies
a first table and a second table. The method further includes determining
an optimized cost of reading the first table. If the number of unique
first table values is greater than the number of unique second table
values, the number of instances where a unique first table value matches
a unique second table value is returned. Otherwise, the number of unique
first table values is returned. The method further includes determining
an optimized cost of reading the second table. The optimized cost of
reading the second table includes the number of unique second table
values. The method also includes summing the optimized cost of reading
the first table and the optimized cost of reading the second table.