Key-Six
Key-Six

Reputation: 2469

Is using many boolean columns faster than a longer string in MySQL combined with PHP?

In MySQL, would it be faster to use:

  1. many boolean columns (for example 100)
  2. varchar(100) string (consisting of 0 and 1)

The advantage of the first option is the ability to read and update specific values only. In the second one this would have to be handled via PHP.

The possible disadvantage of the first option may be the column count if the whole row has to be selected (or even more of them). In the second option only one varchar value would be selected per row and the rest handled via PHP. Not exactly sure about this one.

PS: Around what column count would the answer change if at all?

Upvotes: 2

Views: 107

Answers (1)

sagi
sagi

Reputation: 40481

As I see it, the use of a long varchar column , that consist many properties inside it, is wrong , because the maintenance and the handling with it will be bad and difficult , and could lead to many errors that will be hard to spot.

Each indication should have a column of it's own , and the optimizer should know how to deal with many boolean columns efficiently .

Upvotes: 1

Related Questions