5 ms·
In the context of a maximum length string, what would be the downsides of having it be 0-terminated, as in C? All code would need to check max length as the max
by harperlee 3y ago
In the context of a maximum length string, what would be the downsides of having it be 0-terminated, as in C? All code would need to check max length as the maxlength strings dont end in 0.
It seems to me like an obvious solution that enables all strings to have a fixed length in memory/disk but are presented to the code as variable-up-to-a-max length, but surely there are subtleties that I’m not seeing.
- maweki 3y agoFrom a bird's eye view we would like to give the database hints on how to package tuples into pages. That's easier if the rows can not grow arbitrarily in width. In practice that means (and I think, MySQL did that) that arbitrary length strings or other data (Character Large Objects or Binary Large Objects) are packaged into different pages and require another seek operation, while strings/bytearrays with a maximum length can be packaged with the rest of the row. Of course, when the SQL standard was conceived, databases were much dumber than they are now and hardware was quite different. Your implementation may vary.
- TRiG_Ireland 3y agoNUL bytes are perfectly acceptable in the middle of a Unicode string, in almost any Unicode encoding.
- cryptonector 3y agoNUL is a character. It's not there only to support C strings but rather predates C. In principle it's possible to have ASCII and Unicode strings with NULs in the middle. Now, in practice and because of C, strings with NULs in the middle are a hazard -- a security hazard. And because of that one could forgive a SQL RDBMS doing as you say, but it would not meet the SQL standard.