It was necessary to store in the database infu about the privacy of users and their individual sections in the form of numbers 1 or 2 or 3 ..., as well as setting the site of the same format. In some control systems of the site, they saw that they were stored in the database, each option in a separate field. The question arises, is it not costly? (for load or sampling rate of such tables). Wouldn't it be better to store in one field in the form of "234132321"? Accordingly, only one field will be pulled out, and then dealt with using "substr ()", "explode ()", etc. Who has any thoughts on the above?

    3 answers 3

    There is such science as relational algebra , on which relational databases are actually based. One of the consequences of this great science is the notion of data normalization , which was not invented to obscure brains, but with the very specific goal of eliminating redundancy and consistency of data.

    So, the presentation of data in your form to a normal form does not correspond to and does not at all correspond to the requirements of relationality, and the savings about which you write it are from the section on saving on matches.

    In general, I do not advise - hammer in as a whole field - in the end there are also short fields with the types boolean, byte, short and so on.

    • If I understand correctly, you need to keep such a single number (34232565, for example) in one field and not in several, and then disassemble it by numbers for further work? I, too, am inclined to such a decision. Well, damn, some site management systems are stored in different fields on one tsiferki. They are too lazy to parse one number into multiple numbers, or I don’t understand something? - Garik Pokrovskij
    • @Garik Pokrovskij it rather serves for "intelligence". I understand how this figure is responsible for what? - lampa
    • 2
      @Garik you understood exactly the exact opposite. It is impossible to push several properties / values ​​in one field! - Barmaley
    • It is possible, but it will not be a relational database, but a key-value. With all that it implies. - drdaeman

    Some forums (and not only) store some of the settings in the database as json. IMHO is also very convenient ...

    Meaning : collected the data in an array, wrote down json , recorded it in the database. It is necessary to read - pulled from the database, converted to an array using json_decode - got easy access to all these variables.

    Accordingly, only one field will be pulled out, and then dealt with using "substr ()", "explode ()", etc.

    the load on the database will decrease, and the server will process the rows for each request, which will most likely increase the load.

    • saving on matches. - lampa
    • "Load on the database" just will not decrease. And with certain selections, it will also increase significantly. - Indifferent
    • Duck all the same, how better to do? Each number stored in a separate field or something else? - Garik Pokrovskij
    • You need to store records in separate fields, or use other databases, for example, MongoDB. Unless of course we are talking about improving performance and scaling. - naOy