4 ms·
There are limits and efficiency hits, they’re just edge cases / minor. For MySQL, anyway: VARCHAR > 255 requires an extra byte as a length prefix. This isn’t a
by sgarland 3y ago
There are limits and efficiency hits, they’re just edge cases / minor. For MySQL, anyway:
VARCHAR > 255 requires an extra byte as a length prefix. This isn’t a big deal for most people - even with a billion rows, you’ve only lost 1 GB of space (assuming you didn’t actually need the larger VARCHAR).
Additionally, there is a maximum row limit of 2^16-1 bytes, and collation must be considered. The modern standard in MySQL is utf8mb4, so each character can require 4 bytes. If you’re using an older collation like utf8mb3 or latin1, you can squeeze more in, but when/if those get deprecated (utf8mb3 will supposedly be at some point), the collation change might push you over the edge.
LONGTEXT can store 2^32-1 bytes, so even with utf8mb4 you can store 1 GiB in a single string. Please don’t do this.
Finally, if your table has any BLOB (including TEXT) types, you may get various limitations depending on the version, like implicit temp tables being unable to be created in memory resulting in disk hits; indexing fun (if you need to index a TEXT column - no you don’t), and other quirks.
Databases are fun.
- jeltz 3y agoIn PostgreSQL on the other hand there is no efficiency hit. A varchar(n) is on disk and in memory the exact same thing as a text.