We have a query
select *
from B
where br_id = 'COMPANY'
and id in (select id from id_list_table A)
and reasn_cd = '1'
Table B has 48 million records, table A has 52,000 records.
1. Scenario:
Table B has runstats information in ( with cards, indexes, no distribution). table A no runstats. ( -1)
do explain plan and get Total cost: 1.03042e+06 , optimizer consider 1000 rows as default for table A. Real run time 4 hours.
2. Scenario:
Table B has runstats information in ( with cards, indexes, no distribution). table A has runstats. ( 52,000 cards )
do explain plan and get Total Cost: 8.50476e+06 , even though this time total cost much lager than first scenario, the query run much faster that no runstats, only take about 40 minutes. Strange???
Question: What make db2 optimizer pick up path and decided total cost, why cost higher but real run faster?
Thanks in advance.
GY