The best way to save custom settings for a website in MySQL is BINARY or INT

I know this question has been asked before, and the best answers seem to be the following: Best way to save user settings?

However, I have some additional criteria, so I ask this question again, I need to be able to compare 1 user settings with other user settings and quickly get the differences between two users. All user settings will be a boolean

What is the best way to achieve this?

I thought in the following lines: it has a binary number that represents all user settings: for example. 1100011100 .. each bit corresponds to a specific preference

and then either save it as a BINARY type (where can I store 255 bits, that is, 255 preferences settings - is that right?) or hide the binary in int and save it as int (then the choice between INT or BIGINT is INT = 4 * 8 = 32 bits, BIGINT = 8 * 8 = 64 bits)

Thus, I need to have only one additional column in my user table that stores preferences and it is easy to compare preferences between two users by simply taking a binary number

Does anyone have any other ideas on how to do what I'm trying to do, or see the problem in how I'm trying to do something here?

(Note: Databases are not my forte)

+3
source share
3 answers

BINARY Bitmask, .

, , .

SettingsTable
(
  FkUserId int,
  SettingKey varchar(1024),
  SettingValue varchar(1024)
);

, / .

- Key .

SettingsKeys
(
  KeyId int,
  SettingKey varchar(1024)
);



SettingsTable
(
  FkUserId int,
  FkKeyId int,
  SettingValue varchar(1024)
);

, , .

.

+2

Integer Idea , proc mysql, . SQL Server , .

0

- :

, ?

.

In general, a violation of the atomicity principle (and therefore 1NF) should be justified for some very good reason. In truth, you may actually have such reasons in saving space and performance for a particular (narrow) class of queries. Just make sure that the flexibility you lose is never needed in the future.

0
source

All Articles