Subject | RE: [firebird-support] Optimize this query ... |
---|---|
Author | Alan McDonald |
Post date | 2004-02-03T09:59:41Z |
> One of my queries runs normally. But as soon as I add an ORDERWithou an ORDER BY clause you are retrieving the records in natural order.
> BY clause to
> it, it slows down considerably. I am only selecting first n
> records from a
> view.
>
> SELECT FIRST n SKIP m * FROM VU1
> WHERE
> Field1 = Value1
> AND Field2 IN
> (SELECT Field2 FROM AnotherTable) -->
> AND (Field3 IS NULL OR Field3 = ''
> AND Field4 IN
> (SELECT Field4 FROM YetAnotherTable
> WHERE SomeField = SomeValue AND SomeOtherField IS NULL)
>
> ORDER BY Field6
>
>
> As it is the query runs alright. The view VU1 uses a JOIN of
> two tables. I
> can't add ORDER BY to the view's definition because I think
> ORDER BY is not
> allowed in the view.
>
That's as fast as it can be. With and ORDER by clause, unless you have an
index placed on the field in question, you will be asking the server to
retrieve in natural order then sort the records.
Do you have an index on the field in question?
Alan