Re: Using bytea field...

Поиск
Список
Период
Сортировка
От Andy Colson
Тема Re: Using bytea field...
Дата
Msg-id 4D779362.9060404@squeakycode.net
обсуждение исходный текст
Ответ на Re: Using bytea field...  (Sim Zacks <sim@compulab.co.il>)
Ответы Re: Using bytea field...
Список pgsql-general
> On 03/08/2011 09:06 PM, Andy Colson wrote:
>
>> On 3/8/2011 12:28 PM, Andre Lopes wrote:
>>> Hi,
>>>
>>> I'm using a bytea field to store small images in base64. I need to
>>> know if I can compare bytea rows for equality. To know for example if
>>> the file already exists in the database, this is possible with bytea?
>>>
>>> Best Regads,
>>>
>>
>> You dont need to use both base64 and bytea. You can store base64 in
>> text field... or just store the photo as-is into bytea.
>>
>> To answer your question: it would be faster if you computed an md5 (or
>> sha or whatever) and stored it in the db, then you could check to see
>> if an image exists by searching for the md5, which would be way
>> faster, an send a lot less data over the wire.
>>
>> -Andy
>>
>
>

On 3/9/2011 5:27 AM, Sim Zacks wrote:
 > MD5 is not collision resistant (using the immortal words of wikipedia
 > http://en.wikipedia.org/wiki/MD5).
 >
 > This means that it is possible that multiple images will return the same
 > md5 hash.
 >
 > The question is, if it screws up and says that an image already exists
 > and then returns a different image when querying for it, how bad would
 > that be.
 >
 >
 > I've seen a lot of discussions in the past few years about how
 > problematic the md5 approach is.
 >
 >
 > Sim
 >
 >


It'll never happen:

http://stackoverflow.com/questions/862346/how-do-i-assess-the-hash-collision-probability

Sure you CAN go out of your way to generate collisions, but I'd bet
money you never see one from your setup.

The probability is extremely slim.  And if thats too much of a chance,
use sha2, its mind numbingly slim.

If you were doing cryptography it would be a problem, yes, but not
checking file equality.

-Andy

В списке pgsql-general по дате отправления:

Предыдущее
От: Andrew Sullivan
Дата:
Сообщение: Re: FW: backup using pg_dump postgreSQL 8.3.8
Следующее
От: Alexander Farber
Дата:
Сообщение: Re: Copying data from one table to another - how to specify fields?