5 ms·
> You don't have to specify a length--so you won't make a VARCHAR(255), then get burned when one day a value has more than 255 characters. Does MySQL not have
by pritambaral 9y ago
> You don't have to specify a length--so you won't make a VARCHAR(255), then get burned when one day a value has more than 255 characters.
Does MySQL not have a TEXT data type, or is it not well-supported or otherwise disadvantaged?
> It's very easy to add new fields. If, tomorrow, we decide that each unit type needs a `minSqft` and `maxSqft`, I can add them with no database migration.
TBF, column-adding being a pain is really a MySQL-specific problem.
> It makes it easy to use SQL directly, with no ORM. SQL is a powerful language; ORMs are often a leaky abstraction and a source of unessential complexity. With JSON columns for extensibility, you end up with way fewer migrations and way less need for auto-generated SQL.
ORMs being a "leaky abstraction" is a good thing; good ORMs are not too far removed from SQL precisely because they're leaky.
Pushing schema management to the app layer (as opposed to migrations) is also a source for "unnecessary complexity".
- pdonis 9y ago> Does MySQL not have a TEXT data type It does, but it's still length limited--more precisely, there are several different TEXT data types, with different length limits. This bit me recently on a project, where I was sending strings over the length limit to a TEXT field and wondered why they got truncated until I read the spec more carefully.
- nerfhammer 9y agodoes the new json storage not re-use mysql's TEXT storage? It is stored directly on the data pages? But then it would be limited in length, or does it use something else entirely?
- pdonis 9y agoFrom the documentation[1], it looks like the underlying storage requirement is similar to what would be required to store the string representation of the JSON in a TEXT-type field; however, unlike TEXT fields, there is no length limit other than the global system variable max_allowed_packet (which defaults to 4 MB). [1] https://dev.mysql.com/doc/refman/8.0/en/storage-requirements.html#data-types-storage-reqs-json https://dev.mysql.com/doc/refman/8.0/en/storage-requirements...
- nerfhammer 9y agomax_allowed_packet seems like it would limit the length of any internal string, so maybe it would bound the max length of any individual json field contents?
- pdonis 9y agoThe documentation seems to me to say that max_allowed_packet limits the total size of the storage that a JSON field can take. Of course that also puts an implicit limit on the size of individual keys or values in a JSON object stored in the field, or elements of a JSON array.