何时在mysql中使用文本而不是VARCHAR [duplicate]

时间:2022-03-30 16:54:31

Possible Duplicate:
MySQL: Large VARCHAR vs. TEXT?

可能重复:MySQL:大VARCHAR和文本?

Since VARCHAR can have 65k bytes now, when then should TEXT be used instead of VARCHAR?

既然VARCHAR现在可以有65k字节,那么什么时候应该使用文本而不是VARCHAR呢?

2 个解决方案

#1


57  

A long VARCHAR is stored in the same manner as a TEXT/BLOB field in InnoDB.

一个长VARCHAR以与InnoDB中的文本/BLOB字段相同的方式存储。

From storage prospective BLOB, TEXT as well as long VARCHAR are handled same way by Innodb. This is why Innodb manual calls it “long columns” rather than BLOBs.

从存储预期的BLOB、文本以及long VARCHAR都可以以同样的方式处理Innodb。这就是为什么Innodb手册称它为“长列”而不是blob的原因。

source

Unless you need to index these columns (in which case VARCHAR is much faster) there is no reason to use VARCHAR over TEXT for long fields - there are some engine specific optimisations in MySQL to tune the data retrieval according to length, and you should use the correct column type to take advantage of these.

除非你需要索引这些列(在这种情况下VARCHAR要快得多)没有理由使用VARCHAR长文本字段,有一些在MySQL引擎特定的优化调整数据检索根据长度,你应该使用正确的利用这些列类型。

In case you're using MyISAM an in-depth discussion on the topic is here.

如果您正在使用MyISAM,请在这里对这个主题进行深入的讨论。


TEXT and BLOB are stored off the table with the table just having a pointer to the location of the actual storage.

文本和BLOB存储在表外,表中只有指向实际存储位置的指针。

VARCHAR is stored inline with the table. VARCHAR is faster when the size is reasonable.

VARCHAR存储在表的内联。当尺寸合理时,VARCHAR速度更快。

According to this test, VARCHAR is about thrice as fast as text.

根据这个测试,VARCHAR的速度和文本一样快。

#2


4  

Text should be used for really long strings of indeterminate length. Also, queries that return TEXT fields tend to be much slower than their VARCHAR counterparts.

文本应该用于真正的长字符串的不确定长度。此外,返回文本字段的查询往往比VARCHAR查询慢得多。

#1


57  

A long VARCHAR is stored in the same manner as a TEXT/BLOB field in InnoDB.

一个长VARCHAR以与InnoDB中的文本/BLOB字段相同的方式存储。

From storage prospective BLOB, TEXT as well as long VARCHAR are handled same way by Innodb. This is why Innodb manual calls it “long columns” rather than BLOBs.

从存储预期的BLOB、文本以及long VARCHAR都可以以同样的方式处理Innodb。这就是为什么Innodb手册称它为“长列”而不是blob的原因。

source

Unless you need to index these columns (in which case VARCHAR is much faster) there is no reason to use VARCHAR over TEXT for long fields - there are some engine specific optimisations in MySQL to tune the data retrieval according to length, and you should use the correct column type to take advantage of these.

除非你需要索引这些列(在这种情况下VARCHAR要快得多)没有理由使用VARCHAR长文本字段,有一些在MySQL引擎特定的优化调整数据检索根据长度,你应该使用正确的利用这些列类型。

In case you're using MyISAM an in-depth discussion on the topic is here.

如果您正在使用MyISAM,请在这里对这个主题进行深入的讨论。


TEXT and BLOB are stored off the table with the table just having a pointer to the location of the actual storage.

文本和BLOB存储在表外,表中只有指向实际存储位置的指针。

VARCHAR is stored inline with the table. VARCHAR is faster when the size is reasonable.

VARCHAR存储在表的内联。当尺寸合理时,VARCHAR速度更快。

According to this test, VARCHAR is about thrice as fast as text.

根据这个测试,VARCHAR的速度和文本一样快。

#2


4  

Text should be used for really long strings of indeterminate length. Also, queries that return TEXT fields tend to be much slower than their VARCHAR counterparts.

文本应该用于真正的长字符串的不确定长度。此外,返回文本字段的查询往往比VARCHAR查询慢得多。