开发者

MYSQL manual problem varchar with frequent updates

MYSQL documentation says this:

"For MyISAM tables that change frequently, you should try to avoid all variable-length columns (VARCHAR, BLOB, and TEXT). The table uses dynamic row format if it includes even a single variable-length column. See Chapter 13, Storage Engines. "

The table I am building will have: 1st column: auto incrementing INT, set as primary key Then 20 columns of Varchar(255) 3 million rows

The varchar columns will have text entered, usually around 100 characters, but in rare cases up to 255 characters could be entered. Every read of the table also does an update (data is read, proc开发者_开发百科essed and then table updated with new info), hence there is a lot of "change" on the table. But is this the same change the article quote above refers to?

I have been told this is a non "textbook" setup, but it is built for speed alone, and is ok. so, the question is does the manual quote above mean I should use Char(255) instead of varchar for my needs?


This is the change that the article is talking about. Char(255) should yield better performance but this will cost diskspace 255 bytes-(actual data length). Also if you do this you may also have to add trims to your client code. According to the documentation

When CHAR values are stored, they are right-padded with spaces to the specified length. When CHAR values are retrieved, trailing spaces are removed.

So there's no concern about trailing spaces, unless you use the binary strings.

For binary strings, all characters are significant in comparisons, 
including trailing spaces: 

mysql> SET NAMES binary;
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT 'a ' = 'a';
+------------+
| 'a ' = 'a' |
+------------+
|          0 |
+------------+
1 row in set (0.00 sec)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜