True/False vs 0/1 in MySQL

后端 未结 4 1340
忘了有多久
忘了有多久 2020-12-02 19:59

Which is faster in a MySQL database? Booleans, or using zero and one to represent boolean values? My frontend just has a yes/no radio button.

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 20:29

    Some "front ends", with the "Use Booleans" option enabled, will treat all TINYINT(1) columns as Boolean, and vice versa.

    This allows you to, in the application, use TRUE and FALSE rather than 1 and 0.

    This doesn't affect the database at all, since it's implemented in the application.

    There is not really a BOOLEAN type in MySQL. BOOLEAN is just a synonym for TINYINT(1), and TRUE and FALSE are synonyms for 1 and 0.

    If the conversion is done in the compiler, there will be no difference in performance in the application. Otherwise, the difference still won't be noticeable.

    You should use whichever method allows you to code more efficiently, though not using the feature may reduce dependency on that particular "front end" vendor.

提交回复
热议问题