Board index » delphi » The Locate method seems not to use the Index in the first call

The Locate method seems not to use the Index in the first call

Hi

We've been making some testing with the Locate method and it seems to have a
problem.

If you put a TIBTable in a form, opening a table with 10,000 records, in the
first time you call the Locate method to seek for the last record, it takes
10 to 11 seconds to give the result. It's the same as calling the Last
method.

After the first call in the Locate method, other calls are faster (2
seconds). Why does it happen? It seems that in the first call the Locate
method does not use the Index.

Is there any solution for this?

 

Re:The Locate method seems not to use the Index in the first call


Quote
Gustavo Laet Gomes wrote:

> Hi

> We've been making some testing with the Locate method and it seems to have a
> problem.

> If you put a TIBTable in a form, opening a table with 10,000 records, in the
> first time you call the Locate method to seek for the last record, it takes
> 10 to 11 seconds to give the result. It's the same as calling the Last
> method.

> After the first call in the Locate method, other calls are faster (2
> seconds). Why does it happen? It seems that in the first call the Locate
> method does not use the Index.

None of the calls use an index.  The first call though got all the overhead of
retrieving the records locally.  The next two calls only did local scans of the
data.

Quote
> Is there any solution for this?

--
Jeff Overcash (TeamB)
      (Please do not email me directly unless  asked. Thank You)
The fool escaped from paradise will look over his shoulder and cry
Sit and chew on daffodils and struggle to answer why?
As you grow up and leave the playground
Where you kissed your Prince and found your frog
Remember the jester that showed you tears, the script for tears. (Fish)

Re:The Locate method seems not to use the Index in the first call


Thank you Jeff.

That was my only answer since Locate would take the same time as Last. But
look at what is written in Delphi's Help:

"Locate uses the fastest possible method to locate matching records. If the
search fields in KeyFields are indexed and the index is compatible with the
specified search options, Locate uses the index. Otherwise Locate creates a
filter for the search."

I'm definatly not defending the Locate method. The only thing I want is to
seek a record using an index (which would be, I believe, the fastest way).
So, do you know how can I use the index to search for records in a
DataSet???

"Jeff Overcash (TeamB)" <overc...@onramp.net> escreveu na mensagem
news:3C161E2C.9D67EAA5@onramp.net...

Quote

> None of the calls use an index.  The first call though got all the
overhead of
> retrieving the records locally.  The next two calls only did local scans
of the
> data.

Re:The Locate method seems not to use the Index in the first call


Quote
Gustavo Laet Gomes wrote:

> Thank you Jeff.

> That was my only answer since Locate would take the same time as Last. But
> look at what is written in Delphi's Help:

> "Locate uses the fastest possible method to locate matching records. If the
> search fields in KeyFields are indexed and the index is compatible with the
> specified search options, Locate uses the index. Otherwise Locate creates a
> filter for the search."

> I'm definatly not defending the Locate method. The only thing I want is to
> seek a record using an index (which would be, I believe, the fastest way).

but as you've seen in the second locates after the first the main delay is
fetching the records across the wire, not the non use of the index.  Even if the
index was used to find the last record, all the records before it would still
need to be retrieved to maintain the correct ordering of the result set thus the
main delay you are seeing would still occur.  TIBTable does do a quick query of
the DB to see if the record even exists and exits quickly if it does not.

Quote
> So, do you know how can I use the index to search for records in a
> DataSet???

The Help is incorrect.  It was cut 'n pasted from the BDE's version of Locate.

--
Jeff Overcash (TeamB)
      (Please do not email me directly unless  asked. Thank You)
The fool escaped from paradise will look over his shoulder and cry
Sit and chew on daffodils and struggle to answer why?
As you grow up and leave the playground
Where you kissed your Prince and found your frog
Remember the jester that showed you tears, the script for tears. (Fish)

Re:The Locate method seems not to use the Index in the first call


This paragraph does apply to BDE datasets only. Because IBX <> BDE,  there's
no way to make an indexed search on open TIBDataSets. You should always try
to get small datasets from the server (using a 'where' clause in the
SelectSQL property) and Locate should work OK.

Usually, what I do is to change the SelectSQL property "on the fly" to
retrieve only one record when searching, and then I restore the "normal"
SelectSQL to get the default dataset with a 'Remove Filter' button after the
search.

See http://ib.freeservers.com/ for more info on IBX.

HTH,

-Jorge

Quote
> That was my only answer since Locate would take the same time as Last. But
> look at what is written in Delphi's Help:

> "Locate uses the fastest possible method to locate matching records. If
the
> search fields in KeyFields are indexed and the index is compatible with
the
> specified search options, Locate uses the index. Otherwise Locate creates
a
> filter for the search."

Re:The Locate method seems not to use the Index in the first call


Quote
"Jeff Overcash (TeamB)" wrote:

> The Help is incorrect.  It was cut 'n pasted from the BDE's version of Locate.

        And it's not entirely correct for the BDE, either.  TQuery.Locate never
uses an index.

        -Craig

--
 Craig Stuntz (TeamB) Vertex Systems Corp. Columbus, OH
We're hiring: http://www.vertexsoftware.com/careerops.htm#sd
     Delphi/InterBase WebLog: http://delphi.weblogs.com

Re:The Locate method seems not to use the Index in the first call


"Craig Stuntz (TeamB)" <cstuntz@no_spam.vertexsoftware.com> schreef in
bericht news:3C165295.C8B1FA68@no_spam.vertexsoftware.com...

Quote

> "Jeff Overcash (TeamB)" wrote:

> > The Help is incorrect.  It was cut 'n pasted from the BDE's version of
Locate.

> And it's not entirely correct for the BDE, either.  TQuery.Locate never
> uses an index.

> -Craig

It's pretty safe to say that it only does that for local tables like DBF and
Paradox, right?

Re:The Locate method seems not to use the Index in the first call


Quote
Martijn Tonies wrote:

> "Craig Stuntz (TeamB)" <cstuntz@no_spam.vertexsoftware.com> schreef in
> bericht news:3C165295.C8B1FA68@no_spam.vertexsoftware.com...

> > "Jeff Overcash (TeamB)" wrote:

> > > The Help is incorrect.  It was cut 'n pasted from the BDE's version of
> Locate.

> > And it's not entirely correct for the BDE, either.  TQuery.Locate never
> > uses an index.

> > -Craig

> It's pretty safe to say that it only does that for local tables like DBF and
> Paradox, right?

Right.  In those cases it pulls the Index locally into the Engine to work.  

--
Jeff Overcash (TeamB)
      (Please do not email me directly unless  asked. Thank You)
The fool escaped from paradise will look over his shoulder and cry
Sit and chew on daffodils and struggle to answer why?
As you grow up and leave the playground
Where you kissed your Prince and found your frog
Remember the jester that showed you tears, the script for tears. (Fish)

Other Threads