Reputation: 3
Say you design an SQL Table (postgresql or sqlite) and you have 2 Options for the Primary Key: (1) 64 bit Integer (autoincremented, indexed) (2) A String of 8byte (8 characters) whose first few letters are time dependant, hence sortable, also Indexed.
Would there be any performance / storage drawback to choosing the String version? Since they both take up 8 byte and are indexed and sortable by time (or order of insertion), they should also be the same speed for SELECT queries?
Upvotes: 0
Views: 742
Reputation: 1269503
Would there be any performance / storage drawback to choosing the String version?
Strings are much more complicated than they seem. For instance:
char()
or varchar()
?All of these things affect comparisons and cost -- in most databases. On the other hand, integers are simple. They simple are binary representations. Of course, they could be declared as unsigned versus signed, but that is one option versus many with strings.
SQLite uses an arcane data type system quite different from other databases (and from standard SQL), storing the type with the value rather than with the column definition. I don't know how that affects the performance of indexes in that database.
Upvotes: 1