Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it bad to use boolean flags in databases? And what should be used instead?

I've been reading through some of guides on database optimization and best practices and a lot of them suggest not using boolean flags at all in the DB schema (ex http://forge.mysql.com/wiki/Top10SQLPerformanceTips). However, they never provide any reason as to why this is bad. Is it a peformance issue? is it hard to index or query properly?

Furthermore, if boolean flags are bad, what should you use to store boolean values in a database? Is it better to store boolean flags as an integer and use a bitmask? This seems like it would be less readable.

like image 389
David Chanin Avatar asked Jun 15 '10 04:06

David Chanin


1 Answers

I don't think it is bad and I've never seen a reason stated for this either. Perhaps some old database engines couldn't store them efficiently, but modern ones do. As you say, it's a lot more readable to use booleans than bitmasks. See this question for a similar discussion: Is adding a bit mask to all tables in a database useful?

like image 83
EMP Avatar answered Sep 28 '22 10:09

EMP