Author Topic: Is it worth using mysql set fields?  (Read 208 times)

Offline hiigara

  • Level 10
  • *
  • Posts: 64
  • Reputation: +0/-0
    • View Profile
Is it worth using mysql set fields?
« on: January 22, 2012, 04:52:29 AM »
I have a table with a few Yes/No fields. I am thinking of using enums. In the best possible case a set field will decrease a table size by a factor of 8 if used instead of an enum.
But to update set fields the maintenance cost is higher. The code is ugly and error prone.
Since disk space these days is not an issue I don't think I ever gonna use sets.
Do you use sets?

Offline boolean

  • Level 4
  • *
  • Posts: 12
  • Reputation: +0/-0
    • View Profile
Re: Is it worth using mysql set fields?
« Reply #1 on: January 22, 2012, 08:50:10 AM »
First of all: http://komlenic.com/244/8-reasons-why-mysqls-enum-data-type-is-evil

Second, can you not use a BIT field? 0 for false/no, 1 for true/yes?

If you are worried that there may be more options in the future (yes, no, undecided) I'd definitely split them out to a separate table and reference that through a foreign key. To avoid confusion in your actual code you could then create some Enums in there instead.

Code: [Select]
public enum UserChoice
{
No = 0,
Yes = 1,
Undecided = 2
}

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,152
  • Reputation: +27/-1
    • View Profile
Re: Is it worth using mysql set fields?
« Reply #2 on: January 22, 2012, 09:41:59 AM »
I'm using bits heavily, but not BIT or ENUM fields, I don't trust these, just a simple INT and then use standard binary operators (^ & |). Also, since I'm using standard INT I can do identical operations on PHP side.
I can't imagine writing anything without these, it reduces the dataset soo much in many cases (it's 32 booleans in one int field, this makes you simply don't care about the aboundance of various flags in your data).

Offline hiigara

  • Level 10
  • *
  • Posts: 64
  • Reputation: +0/-0
    • View Profile
Re: Is it worth using mysql set fields?
« Reply #3 on: January 22, 2012, 11:23:18 AM »
First of all: http://komlenic.com/244/8-reasons-why-mysqls-enum-data-type-is-evil

Second, can you not use a BIT field? 0 for false/no, 1 for true/yes?


This expert doesn't like BIT fields either:
http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/

Offline boolean

  • Level 4
  • *
  • Posts: 12
  • Reputation: +0/-0
    • View Profile
Re: Is it worth using mysql set fields?
« Reply #4 on: January 22, 2012, 11:34:40 AM »
huh, well I'll be.

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,152
  • Reputation: +27/-1
    • View Profile
Re: Is it worth using mysql set fields?
« Reply #5 on: January 22, 2012, 12:42:04 PM »
First of all: http://komlenic.com/244/8-reasons-why-mysqls-enum-data-type-is-evil

Second, can you not use a BIT field? 0 for false/no, 1 for true/yes?


This expert doesn't like BIT fields either:
http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/
I kind of agree. The bitfield can hold 8,16,32,64 bits. Any data structure that hold a different number of bits will be unoptimized or the space will be secretly wasted (CPU is basicly not able to operate on different amounts of bits in any bulk operations). The BIT datatype is a confusing one, you don't really know how much it stores... That's why I just ignore it and use TINYINT (8 bits), SMALLINT (16 bits) and INT (32 bits). Perfectly clear and compatible with every storage engine that ever existed in history and that will ever exist in future (until quantum computers I guess :D).

"Bitwise arithmetic can also be pretty tricky to write, and even harder to read." - I strongly disagree with this statement through. Either we are programmers or we are not. Bit operations are the very core of computers, if you are a programmer learn these, even if you never intend to use them. Being a programmer and not knowing what bit operators are is like being a husband and not knowing what sex is :)

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal