Subject Re: slow query
Author Stephen Boyd
--- In firebird-support@yahoogroups.com, Svein Erling Tysvær <svein.erling.tysvaer@...> wrote:
>
> Don't invent your own optimizer, just add '', to your ORDER BY clause. E.g. rather than writing
>
> SELECT *
> FROM BILLING_IMG_TABLE
> WHERE LOCATION = 'XX' AND NUMBER = 123 AND IMAGE_TYPE = 'XX'
> ORDER BY AS$IMAGE_NUMBER;
>
> write
>
> SELECT *
> FROM BILLING_IMG_TABLE
> WHERE LOCATION = 'XX' AND NUMBER = 123 AND IMAGE_TYPE = 'XX'
> ORDER BY '', AS$IMAGE_NUMBER;
>
> This should work almost equally well with dynamically created queries (tested on Firebird 1.5, not 2.1). I find indexes a lot more useful in the WHERE than the ORDER BY clause, and I think it is only in cases with a lot of rows returned that an index for the ORDER BY clause may be useful.
>

Thanks for the tip. I wouldn't have thought of that. I'll try it and see how it works.