Subject query speed - confusing
Author Nick Upson
I'm trying (and failing) to understand why these 2 queries have
different plans and hence different execution times, the first takes
around 250ms and the other takes 125ms. I know these sound very small
but this database has only 1% of the data (although the selectivity
will be similiar).

SELECT COUNT(*)
FROM  TBLOUTSTATION O
 LEFT JOIN TBLOSMETRIC OM ON OM.OUTSTATIONID = O.OUTSTATIONID AND
OM.BASEIDENT = O.BASEIDENT
 LEFT JOIN TBLELEMENT E ON E.OUTSTATIONID = O.OUTSTATIONID
 LEFT JOIN TBLASSET A ON A.ASSETID = E.ASSETID
WHERE O.ACTIVESTATUS = 0 AND UPPER(O.OSIDENT) STARTING WITH '110';

PLAN JOIN (JOIN (JOIN (O NATURAL, OM INDEX (FK_TBLOSMETRIC_1)), E
INDEX (IDX_TBLELEMENT_1)), A INDEX (PK_TBLASSET))


SELECT FIRST 25
O.OSIDENT, O.BASEIDENT, IIF(O.OSCONNECT <> O.OSIDENT, O.OSCONNECT, NULL),
O.CONNECTIONSTATUS, O.CONNSTATUSCHANGE, O.LASTRXMSG, O.UPDATESTATUS,
O.CONFIGSTATUS, O.AUTHSTATUS, O.LASTTXMSG, O.DATEADDED, O.RSSIAPP,
O.NUMAPPERROR, O.TMODEUL, O.TMODEDL, ( CAST(OM.METRIC AS NUMERIC(4,2)) ),
O.RELAYSTATUS, A.UNITIDENT, E.ELEMIDENT, A.ASSETFIELD1, A.ASSETFIELD2,
A.ASSETFIELD3, A.ASSETFIELD4, E.NUMLAMPS, A.ASSETSTATUS, E.ELEMSTATUS,
O.OUTSTATIONID, O.NUMCONERROR, O.RSSICON, O.OSCONNECT
FROM TBLOUTSTATION O
LEFT JOIN TBLOSMETRIC OM ON OM.OUTSTATIONID = O.OUTSTATIONID AND
OM.BASEIDENT = O.BASEIDENT
LEFT JOIN TBLELEMENT E ON E.OUTSTATIONID = O.OUTSTATIONID
LEFT JOIN TBLASSET A ON A.ASSETID = E.ASSETID
WHERE O.ACTIVESTATUS = 0 AND UPPER(O.OSIDENT) STARTING WITH '110'
ORDER BY 1 ASC;

PLAN JOIN (JOIN (JOIN (O ORDER UNQ_TBLOUTSTATION_2, OM INDEX
(FK_TBLOSMETRIC_1)), E INDEX (IDX_TBLELEMENT_1)), A INDEX
(PK_TBLASSET))