Greg Longtin
05-09-2000, 09:10 AM
To All,
I finally converted a system to GUID's instead of integers for pk's.
The main test procedure involved seven SQL statements, at least six
containing joins.
For those unfamiliar with GUID's (globally unique identifier), they are
a 16 byte code generated by the OS. They should be unique across all
computers in the world. I wanted to use them instead of integers to
allow easier 'off-line/replicated' use, since using integers typically
requires all sorts of allocation by user/system/server hocus pocus.
Also, no db call is needed to retrieve the next id.
Bottom line - query time was essentially the same. Over the years,
since integers were supported, I've seen many references that implied
that they are much faster than strings. Depending on the application, I
think that is far from the truth.
Greg Longtin
Two notes -
1. The integer version used Set collate to "General". I've seen
articles that "General" can take longer than "Machine". The GUID
version had to use "Machine", and character fields were indexed using
Upper(). This was my first foray into "strings for pk's" (2.5 was along
time ago...), and I was surprised that collate affects joins. IOW, even
if pk/fk indexes are created with "machine" collate, and the fields
created with NOCPTRANS, collate still affects their use in the SQL join
'on' clause. This seems stupid. I hope the VFP team is considering
changing this in v7. IOW, any field created using NOCPTRANS should use
a collate sequence of "Machine".
2. Since I am returning an XML resultset, I also needed to convert
GUID's to an XML friendly string. I used a modified Base64 encoding
with BitAnd and BitShift functions. BTW, this results in a 24 byte xml
friendly id. This was an additional burden that the integer version
didn't have, since a UDF existed in the 'GUID' SQL statements. The
integer version converted the integer to a string, then appended a
character to it because xml id's cannot start with a numeric character.
This was be done inline (vs UDF).
I finally converted a system to GUID's instead of integers for pk's.
The main test procedure involved seven SQL statements, at least six
containing joins.
For those unfamiliar with GUID's (globally unique identifier), they are
a 16 byte code generated by the OS. They should be unique across all
computers in the world. I wanted to use them instead of integers to
allow easier 'off-line/replicated' use, since using integers typically
requires all sorts of allocation by user/system/server hocus pocus.
Also, no db call is needed to retrieve the next id.
Bottom line - query time was essentially the same. Over the years,
since integers were supported, I've seen many references that implied
that they are much faster than strings. Depending on the application, I
think that is far from the truth.
Greg Longtin
Two notes -
1. The integer version used Set collate to "General". I've seen
articles that "General" can take longer than "Machine". The GUID
version had to use "Machine", and character fields were indexed using
Upper(). This was my first foray into "strings for pk's" (2.5 was along
time ago...), and I was surprised that collate affects joins. IOW, even
if pk/fk indexes are created with "machine" collate, and the fields
created with NOCPTRANS, collate still affects their use in the SQL join
'on' clause. This seems stupid. I hope the VFP team is considering
changing this in v7. IOW, any field created using NOCPTRANS should use
a collate sequence of "Machine".
2. Since I am returning an XML resultset, I also needed to convert
GUID's to an XML friendly string. I used a modified Base64 encoding
with BitAnd and BitShift functions. BTW, this results in a 24 byte xml
friendly id. This was an additional burden that the integer version
didn't have, since a UDF existed in the 'GUID' SQL statements. The
integer version converted the integer to a string, then appended a
character to it because xml id's cannot start with a numeric character.
This was be done inline (vs UDF).