Does it make sense to use CHAR if you have VARCHAR in the same table?

I just read the accepted answer of this question , which left me this question.

Here is a quote from this answer:

"But since you noted this question in MySQL, I mentioned a tip about MySQL: when your query implicitly generates a temporary table, for example, when sorting or GROUP BY, the VARCHARfields are converted to CHARto take advantage of working with fixed-width strings. If you use many fields VARCHAR(255)for data that shouldn't be so long can make the temporary table very large. "

As far as I understand, the advantage CHARis that you get rows with a fixed width, so that doesn't work VARCHARin the same table? Are there any benefits to using CHARif you have VARCHARone table?


Here is 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 a table with CHARwork better than a table without CHAR, and if so, in what situations?

+5
source share
1 answer

"VARCHAR" , , . "CHAR" , , "CHAR(100)", 100 .

, , - ( "VARCHAR" , "TEXT" ..). , "CHAR" "VARCHAR" , , MySQL.

"CHAR" , . , , , , . , .

, .

+2

All Articles