Replies: 1 comment
-
Looks good to me, more readability is always a plus if it doesn't cause any performance issues. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello there! I recently had a discussion here #8377 (review) about these flags that are saved in our DB and that, honestly, in my opinion, sometimes are getting a little bit out of control.
While null values in MySQL do not consume any space (just a very small amount as stated here: https://dev.mysql.com/doc/refman/8.0/en/storage-requirements.html ) ...
...having dozens of fields to save every single flag/status is a bit weird.
However, since version 5.7 the new JSON fields have been introduced in MySQL, which are not only a way to convert our bitmask values into something which is better readable, but the JSON properties are also indexable and can be converted to generated columns that do not consume any further space, except the one for the index itself: https://www.compose.com/articles/mysql-for-json-generated-columns-and-indexing/
Moreover, we do not need any library to parse the JSON data from the DB, but we can use a syntax just like this:
And the same to update some properties:
This example is not the best one, but it should give the idea
This is similar to the concept of a NoSQL database inside MySQL and I successfully used this strategy for several of my Projects. Although I still think that bitmasks fields can and should be used for pure boolean flags, we can consider the JSON alternative when we want to store more dynamic information (e.g. inside the character database)
What do you think?
Beta Was this translation helpful? Give feedback.
All reactions