Subject Re: [IBO] Order By
Author Helen Borrie (TeamIBO)
At 02:10 PM 04-03-02 +0000, you wrote:
>I have a query which returns instantly, until I add the 'Order By'
>clause and order the result with three fields. The query then takes
>50 seconds ( The plan stays the same ).

It would be interesting to see both the query statement and the plan. Can
you copy it and post it?

It sounds as if either you have no indexing on the three fields or, if you
do, you have conflicting indexes.

>Surely a result set should be ordered afterwards

Yes, it is. But the engine needs good indexes to work with, especially
when you are sorting by multiple columns - otherwise it just has to walk
the dataset multiple times and form intermediate sets until it completes
the required sort.

> - if not is there a
>way the tiboquery can order the result once the 'non-ordered' query
>has been executed ?


>A related 2nd question - if I get a result set and also want to count
>how many records in the result - I see the query is fired again when
>I use the recordcount method, replacing the select ... with select
>count(*) How can I just count the records of the result ?

Unless you have an absolute requirement to count records, DON'T.

You could *try*

myIBOQuery.InternalDataset.RecordCount immediately after the Open call, and
compare the speed of that with select count(*) which is horribly expensive...

Helen Borrie (TeamIBO Support)

** Please don't email your support questions privately **
Ask on the list and everyone benefits
Don't forget the IB Objects online FAQ - link from any page at