Subject Optimizer selects non-optimal plan
Author jstahl80
I have the following two selects that deliver the same resultset,at
least as far as I can see, but then plan choosen for the second one
executes much slower than the first (see the natural, which is not
needed when optimized well). Shouldn't the optimizer translate the
second from clause to the first internally?

FIRST
=====
select distinct c.*, a.*
from cmd cmdm INNER JOIN ch_daten chdm ON (cmdm.objid=chdm.objid and
cmdm.typeofcmd=13)
inner join ch_daten c ON (c.objid=cmdm.to_objid)
LEFT JOIN auftrags_daten_run a ON c.objid = a.objid
LEFT JOIN wb_prg_run w ON c.objid = w.objid
LEFT JOIN pruefdaten_run p on a.objid=p.objid and a.nr=p.sub_id
where
chdm.dch_nr=70106234

PLAN:
PLAN SORT (JOIN (JOIN (JOIN (JOIN (CHDM INDEX (IX_CHD_1), CMDM INDEX
(IX_CMD_4), C INDEX (PK_CHD)), A INDEX (FK_ADR_CHD)), W INDEX
(PK_WBPR)), P
INDEX (PK_PRUEFR)))


SECOND
======
select distinct c.*, a.*
from (((ch_daten c LEFT JOIN auftrags_daten_run a ON c.objid =
a.objid)
LEFT JOIN wb_prg_run w ON c.objid = w.objid)
LEFT JOIN pruefdaten_run p on a.objid=p.objid and a.nr=p.sub_id)
INNER JOIN (
cmd cmdm INNER JOIN ch_daten chdm ON (cmdm.objid=chdm.objid and
cmdm.typeofcmd=13)
) ON (c.objid=cmdm.to_objid)
where
chdm.dch_nr=70106234

PLAN:
PLAN SORT (JOIN (JOIN (JOIN (JOIN (JOIN (C NATURAL, A INDEX
(FK_ADR_CHD)), W INDEX (PK_WBPR)), P INDEX (PK_PRUEFR)), CMDM INDEX
(IX_CMD_1)), CHDM INDEX (PK_CHD)))

-- Joja