Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ALLTRIM vs PADL with Indexes
Message
 
 
À
19/04/2001 11:44:31
David Brunelle
Université de Sherbrooke
Sherbrooke, Québec, Canada
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00497311
Message ID:
00497346
Vues:
11
>Thank you... For some reason I though ALLTRIM would be a lot slower
>
>>>Here is a typical situation. There is a table with record of 4 long but most of them only have two letter and are put that way in the table : " AA" (2 spaces before) There is an index XINDEX on that record as : XINDEX = UPPER(field)
>>>There is a form that seek the table for a specific match : "AA"
>>>
>>>Which one is faster...?
>>>Padding the "AA" with 2 spaces and then do the SEEK, or use SEEK (ALLTRIM(field))
>>>Will both be the same speed or will one of them use the index where the other will not?
>>
>>They will both be the same speed and they will both use the index. By definition, SEEK always and only uses the index.

David,
There may be a misconception about what is going on. If you pad the value with spaces and then seek it, the seek will return .T.. If you attempt to seek the alltrim()ed value, the seek will fail.

Your index is built using the expression UPPER(FIELD). That mean that the nodes in your index have as their values the field uppered.
          Node1 - "  BB"
        /              \
      Node2 - "  AA"     Node3 - "  CC"
For example, if you have the "AA" and you want to search for it. If you pad it first, you will have "  AA". A seek merely compares the passed value with the value stored in the index node. In this case, seek will find the value in Node2, return .T. and position the record pointer on the record associated with that node.

If you apply an alltrim to the passed in value to seek(), then the value will never be found. The system will be comparing "  AA" with "AA" and they won't be equal. If you used ALLTRIM() in the index expression, the behavior would be reveresed but the speed would be the same because you are still using a simple binary search on an index.
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform