I am building a database that contains a large number of pairs, each of which consists of two parts, an ID and a long string. Each ID is unique however there are only a handful of these long string attributes. To save space I was considering doing the following:
I'd have two tables, the first with pairs of the form ID and stringID and the second with pairs of the form stringID longString.
I'd like to know if this kind of space optimization is already done automatically in a mysql database. If it is then I won't bother implementing it myself. If this kind of space optimization is not done automatically, is there a better way of doing it? What is considered the best practice with regards to this type of optimization? Thanks
To make my question more concrete, consider the following original table:
employee WorkAddress (an extremely long string)
name1 address1
name2 address1
name3 address1
name4 address1
...
name1000 address2
name1001 address2
name1002 address2
...
etc
And the new more space efficient table:
employee addressID (much shorter than the long string)
name1 ID1
name2 ID1
...
name1000 ID2
name1001 ID2
name1002 ID2
...
etc
In addition to the second table:
addressID WorkAddress
ID1 address1
ID2 address2
...
etc
NOTE: If you think this question is not suited for stackoverflow, please recommend one of the other stackexchange sites for this type of question. Thanks
The solution with the two tables is certainly the right one. Not because of any space considerations (if you're in an environment where (external) space is really short, a fully blown DBMS is probably not the right tool anyway) but because of securing data integrity by normalization.
If that string values is directly in the table with the IDs and it changes, that means that every row in that table with that values has to be changed. For one that's more writing than just changing one row in the two table approach. But even worse, if you forget to update one or some rows by whatever circumstance you data is corrupted.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.