I just read the accepted answer of this question, which left me with this question.
Here's a quote from that answer:
"But since you tagged this question with MySQL, I'll mention a MySQL-specific tip: when your query implicitly generates a temporary table, for instance while sorting or GROUP BY
, VARCHAR
fields are converted to CHAR
to gain the advantage of working with fixed-width rows. If you use a lot of VARCHAR(255)
fields for data that doesn't need to be that long, this can make the temporary table very large."
As I understand it, the advantage of CHAR
is that you get fixed-width rows, so doesn't a VARCHAR
in the same table mess that up? Are there any advantages of using CHAR
when you have a VARCHAR
in the same table?
Here's an example:
Table with CHAR
:
CREATE TABLE address (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
street VARCHAR(100) NOT NULL,
postcode CHAR(8) NOT NULL,
PRIMARY KEY (id)
);
Table without CHAR
:
CREATE TABLE address (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
street VARCHAR(100) NOT NULL,
postcode VARCHAR(8) NOT NULL,
PRIMARY KEY (id)
);
Will the table with CHAR
perform any better than the table without CHAR
, and if so, in what situations?