Subject Re: Optimization Question
Author Svein Erling
--- In firebird-support@yahoogroups.com, "Dan Wilson" wrote:
> I have a select statement with which I could use some help.
>
> select first 1 SpreadAction_ID from SpreadActionTable
> where Spread_ID = 9007 AND ( Status IS NULL OR Status != 2 )
> AND Action_Time >= 1073030400
> AND Action_Time <= 1075535999
> Order By Action_Time;

First, I'd try creating a separate index for Action_Time. If that
doesn't help you could try

select first 1 SpreadAction_ID from SpreadActionTable S
where Spread_ID = 9007 AND ( Status IS NULL OR Status != 2 )
AND Action_Time BETWEEN 1073030400 AND 1075535999
and not exists(select * from SpreadActionTable S2
where s2.Spread_ID = 9007 AND ( s2.Status IS NULL OR s2.Status != 2 )
and s2.Action_Time < s.Action_Time)

and if that doesn't help you could stop listening to my advice and
wait for Arno or Helen to answer ;o)

Set
- I support Firebird, I am a FirebirdSQL Foundation member.
- Join today at http://www.firebirdsql.org/ff/foundation