Subject Re: PLAN SORT
Author Adam
--- In firebird-support@yahoogroups.com, Alexandre Benson Smith
<iblist@...> wrote:
>
> Adam wrote:
> > --- In firebird-support@yahoogroups.com, "radevojvodic" <vrade@>
wrote:
> >
> >> Hi All,
> >>
> >> How can PLAN SORT be avoided in query. All indexes are used, no
> >> natural orders , slow quary.
> >>
> >
> > Don't use order by, group by, distinct or union.
> >
> > Adam

Also don't use joins.

> >
>
> Or add 0 to numeric fields or concatenate '' to char fields that are
> sorted, example:

No, it still does a sort. The only thing this will change

PLAN (FOO ORDER PK_FOO)

to

PLAN SORT ((FOO NATURAL))

The first plan is probably slower to complete, but much much faster to
retrieve the first record.

The OP should provide an example of what they are trying to achieve,
because sorting is required to implement the features like distinct
and group by. The only way to avoid sorting the dataset is to avoid
using queries that rely on the data being sorted.

Adam