Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to create composite index on Integer fields?
Message
From
02/12/1997 20:37:39
Shihchau Tai
Apic Systems Pte Ltd
Singapore, Singapore
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00063211
Message ID:
00063473
Views:
63
>>>>I have a composite key that consists of two integer fields. How do I create the composite key?
>>>>
>>>>If I do STR(iKey1)+STR(iKey2), I will get a long string, right? I can't alltrim them because that will make the composite index wrong, right? Do I have to fix the number of characters for each field of the composite key?
>>>>
>>>>Thanks in advance.
>>>
>>>If this is neither a primary or candidate key, use:
>>>
>>>BINTOC(iKey1) + BINTOC(iKey2)
>>>
>>>These function where specifically designed to work with integer keys.
>>>
>>>hth,
>>>
>>>George
>>
>>Excellent, George. You never run out of opportunities to learn about functions you either missed or hadn't yet seen. :-)
>>
>>Bill
>
>Thanks, Bill. Actually, the above can be improved slightly by specifying the size (in bytes). For example, you can store over 4 billion values (2 billion positive) in only four bytes. That should be enough for anyone. Mac Ruebel had a long (several parts) article on this in FoxPro Advisor.
>
>Admittedly, at first, I kinda went, "Big Deal!" The "old school" (of which I'm part) would say that you should make the key character values anyway. This is because determining whether a character value is greater or less than another is made from left to right, and tends to be more efficient than, having to make the conversion and comparison via the numeric processor. But after examining the way the function returns it's values, I say yeah, good idea. Like a character string, BINTOC() returns the value from most significant byte to least, rather than the way the processor handles it (LSB to MSB). Further, positive values have bit 31 set, as opposed to cleared in the usual way.
>
>George

Thanks a lot.

Another question. If I don't specify the size in BINTOC, does it take 4 bytes? In other words, is BINTOC(key1)+BINTOC(key2) an 8 byte character index?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform