Subject | How to force a plan on a query |
---|---|
Author | colincoleman2002 |
Post date | 2004-08-19T09:37:05Z |
I have a simple query joining a few tables, but have found that
using FB 1.0 and IBO 4.x if I have a mixture of JOINS and LEFT JOINS
in a query it takes about 23 seconds to run, if i make ALL the joins
LEFT joins, it runs in 521ms, I have played with the SQL for days
now, trying to figure out why two tables that are connected using FK
joins behaves like this when using LEFT joins.
Over the years I always thought that a straight vanilla join used
the primary key index on the detail table to locate its data
(Lookup), but it appears using IB_Expert, that this is not the case
and it uses a non indexed read on the table in many instances.
Id like to try and force the SQL to use a "PLAN" i think should work
better. But I have never done this before and would be very
appreciative of any help.
THE SQL I USED
Select O.ZORD, O2W.ZWORD , O.zrate ,O.ZUOM, O.ZORDQTY, O.ZCUR,
O.ZCOMPLETED, O.ZDUEDATE
, S.zspecdesc ,S.ZPSTATE, S.ZOPENWIDTH
, V.ZLENGTH
, U.ZMULTIPLY
, PS.ZPSDESC
, C.ZREF, O.ZDLAREF, (C.ZADD4 ||','||C.ZADD5) AS CUST_ADDR
,(D.ZADD4 ||','||D.ZADD5) AS DLV_ADDR
FROM ACORD O
JOIN ACSPEC S ON (o.zspec = s.zspec)
JOIN ACUOM U ON (U.ZUOM = O.ZUOM)
JOIN PAPSTATE PS ON (PS.ZPSTATE = S.ZPSTATE)
JOIN ACCST C ON (C.ZCST = O.ZCST)
LEFT JOIN ACSCONV V ON (V.ZSPEC = S.ZSPEC)
LEFT JOIN ACDLA D ON (D.ZREF = O.ZDLAREF)
LEFT JOIN ORD2WKS O2W ON (O.zord = O2W.ZORD )
WHERE
O.zduedate BETWEEN '17 AUG 2004' and '20 AUG 2004'
ORDER BY O.ZDUEDATE
===================================================
Colin
using FB 1.0 and IBO 4.x if I have a mixture of JOINS and LEFT JOINS
in a query it takes about 23 seconds to run, if i make ALL the joins
LEFT joins, it runs in 521ms, I have played with the SQL for days
now, trying to figure out why two tables that are connected using FK
joins behaves like this when using LEFT joins.
Over the years I always thought that a straight vanilla join used
the primary key index on the detail table to locate its data
(Lookup), but it appears using IB_Expert, that this is not the case
and it uses a non indexed read on the table in many instances.
Id like to try and force the SQL to use a "PLAN" i think should work
better. But I have never done this before and would be very
appreciative of any help.
THE SQL I USED
Select O.ZORD, O2W.ZWORD , O.zrate ,O.ZUOM, O.ZORDQTY, O.ZCUR,
O.ZCOMPLETED, O.ZDUEDATE
, S.zspecdesc ,S.ZPSTATE, S.ZOPENWIDTH
, V.ZLENGTH
, U.ZMULTIPLY
, PS.ZPSDESC
, C.ZREF, O.ZDLAREF, (C.ZADD4 ||','||C.ZADD5) AS CUST_ADDR
,(D.ZADD4 ||','||D.ZADD5) AS DLV_ADDR
FROM ACORD O
JOIN ACSPEC S ON (o.zspec = s.zspec)
JOIN ACUOM U ON (U.ZUOM = O.ZUOM)
JOIN PAPSTATE PS ON (PS.ZPSTATE = S.ZPSTATE)
JOIN ACCST C ON (C.ZCST = O.ZCST)
LEFT JOIN ACSCONV V ON (V.ZSPEC = S.ZSPEC)
LEFT JOIN ACDLA D ON (D.ZREF = O.ZDLAREF)
LEFT JOIN ORD2WKS O2W ON (O.zord = O2W.ZORD )
WHERE
O.zduedate BETWEEN '17 AUG 2004' and '20 AUG 2004'
ORDER BY O.ZDUEDATE
===================================================
Colin