Subject Re: How to force a plan on a query
Author Svein Erling Tysvær
Colin,
the simple answer is to tell you to use PLAN <YourPlan> between the
WHERE and ORDER BY clause, but it would be better if you showed us the
plan Firebird chooses and then the plan you think is better. Maybe it
is possible to tweak the SQL, something that generally is better if
the plan includes any systemgenerated indexes.

Set

--- In firebird-support@yahoogroups.com, Colin Coleman wrote:
> 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