When storing a large blob containing textual data, consider compressing it first. 当存储一个包含文本数据的大博客时,首先考虑压缩它。Do not use this technique when the entire table is compressed by 当整个表由InnoDB
or MyISAM
.InnoDB
或MyISAM压缩时,不要使用此技术。
For a table with several columns, to reduce memory requirements for queries that do not use the BLOB column, consider splitting the BLOB column into a separate table and referencing it with a join query when needed.对于具有多个列的表,为了减少不使用BULB列的查询的内存需求,请考虑将BULB列拆分为单独的表,并在需要时将其引用到联接查询。
Since the performance requirements to retrieve and display a BLOB value might be very different from other data types, you could put the BLOB-specific table on a different storage device or even a separate database instance. 由于检索和显示BLOB值的性能要求可能与其他数据类型非常不同,因此可以将特定于BLOB的表放在不同的存储设备上,甚至放在单独的数据库实例上。For example, to retrieve a BLOB might require a large sequential disk read that is better suited to a traditional hard drive than to an SSD device.例如,检索BLOB可能需要一个大的顺序磁盘读取,这比SSD设备更适合传统硬盘驱动器。
See Section 8.4.2.2, “Optimizing for Character and String Types” for reasons why a binary 有关二进制VARCHAR列有时优于等效BLOB列的原因,请参见第8.4.2.2节,“优化字符和字符串类型”。VARCHAR
column is sometimes preferable to an equivalent BLOB column.
Rather than testing for equality against a very long text string, you can store a hash of the column value in a separate column, index that column, and test the hashed value in queries. 您可以将列值的散列存储在单独的列中,为该列编制索引,并在查询中测试散列值,而不是对很长的文本字符串进行相等性测试。(Use the (使用MD5()
or CRC32()
function to produce the hash value.) MD5()
或CRC32()
函数生成哈希值。)Since hash functions can produce duplicate results for different inputs, you still include a clause 由于散列函数可以为不同的输入生成重复的结果,因此在查询中仍然包括一个子句AND
in the query to guard against false matches; the performance benefit comes from the smaller, easily scanned index for the hashed values.blob_column
= long_string_value
AND
,以防止错误匹配;性能优势来自于散列值的较小、易于扫描的索引。blob_column
= long_string_value