0

Most of the text stored in my DB is from 1MB to 1.5MB big. But not bigger then 1.5MB, because that's the limit I set.

Here are my needs:

  • I need it for lowering my mysql database size
  • I need it to be as fast as possible
  • no security needed
  • it must just work correctly, so that string_1 and string_2 can never have the same hash

I use PHP and MYSQL.

4

4 回答 4

1

A hash is not reversible. You can make a 1.5MB text into a small string with the help of hashing, but you cannot convert the same hash back into the original text.

What you are looking for is a compression algorithm. You can make the files a lot smaller with compression, but it's unlikely to be as small as a hash.

于 2013-09-13T17:16:42.153 回答
1

节省空间

  • MySQL 具有内置的COMPRESS()功能UNCOMPRESS(),可以节省数据库空间,并且必须编写额外的 PHP 代码。

检查唯一性

  • 而不是索引TEXT列[无论它们是否被压缩],您可以存储和索引 2 个相对较小的东西,以保证该文本是唯一的。

    1. 数据的散列,MD5,SHA,随便你。
    2. 未压缩数据的长度。
  • 对于大多数散列函数,您更可能被流星击中,而不是为不同的文本字符串设置 2 个相同的散列,并且拥有 2 个相同的长度和散列字符串比同时赢得三个彩票时被流星和闪电击中的可能性更小。

于 2013-09-13T17:26:58.603 回答
1

我建议使用 SHA1,因为 git 和类似的应用程序也使用它来识别字符串。

请参阅:https ://en.wikipedia.org/wiki/Sha1 和: http: //php.net/manual/en/function.hash.php

$hash = hash( 'sha1', $inputData );
于 2013-09-13T17:01:13.780 回答
0

我将假设您需要一种压缩算法来减小文本大小。

请参阅http://php.net/manual/en/function.gzcompress.php

于 2013-09-13T17:01:32.187 回答