MySQL Forums
Forum List  »  Optimizer & Parser

Re: TINYINT(1) or ENUM( 'true' , 'false')
Posted by: Jay Pipes
Date: February 23, 2006 11:12PM

yoderek wrote:
> Which would be the more optimzed way to store a
> boolean, TINYINT(1) or ENUM( 'true' , 'false')?
> It seems that when storing an enum w/ two settings
> should only take up one bit, 0 or 1, but would
> spend more time looking up the enums in the
> beginning of the query. tinyint(1) however would
> take up 4 bits assuming it ranged 0-9. So it seems
> if you just wanted to fetch the value, tinyint(1)
> would be faster, but if you are searching through
> lots of records enum('true','false') would be
> faster. Do you concur??

TINYINT takes up 1 byte (8 bits) of storage, regardless of whether only 0 and 1 are stored.

ENUM takes up 1 byte of storage, if < 256 elements, 2 bytes of storage for up to 65,535 elements.

You can also check out the BIT data type, which is, I think, what you are looking for:

http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html
http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html
http://dev.mysql.com/doc/refman/5.0/en/bit-field-values.html

Jay Pipes
Community Relations Manager, North America, MySQL Inc.

Got Cluster? http://www.mysql.com/cluster
Personal: http://jpipes.com

Options: ReplyQuote


Subject
Views
Written By
Posted
29904
February 23, 2006 01:56PM
Re: TINYINT(1) or ENUM( 'true' , 'false')
12637
February 23, 2006 11:12PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.