Re: physical bytes
Posted by: Rick James
Date: September 08, 2011 08:30PM

CHAR(10) always takes 10 or 30 bytes.
VARCHAR(10) takes 1 to 11 or 1 to 31 bytes, depending on size of string.

The first numbers (10,1,11) refer to 1-byte character sets, such as latin1 or ascii.

The later numbers (30,1,31) refer to utf8. A 10-character Chinese phrase would take 30 bytes for the string itself. English: 10; French/Spanish/German: usually not much more than 10, never more than 20.

MyISAM takes another _bit_ for NULL.

InnoDB always adds 1 or 2 bytes per field; I think this includes NULLness. CHAR may act more like VARCHAR. The 1 vs 2 depends on how big the largest field is in the schema.

There is at least one SQL_MODE that impacts what I have said above.

Bottom line (and much simpler): Use CHAR for things that are really fixed length; else use VARCHAR (or TEXT, etc)

Options: ReplyQuote


Subject
Written By
Posted
September 07, 2011 02:03PM
Re: physical bytes
September 08, 2011 08:30PM
September 08, 2011 10:30PM
September 09, 2011 06:27PM
September 11, 2011 12:18PM
September 12, 2011 11:22AM
September 13, 2011 10:33PM


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.