Re: images in database?

From: Jerry Stuckle <jstucklex_at_attglobal.net>
Date: Mon, 6 Jun 2016 15:02:14 -0400
Message-ID: <nj4hbn$cji$1_at_jstuckle.eternal-september.org>


On 6/6/2016 12:53 PM, J.O. Aho wrote:
> On 06/06/2016 04:03 PM, Jerry Stuckle wrote:
>> On 6/6/2016 8:43 AM, mike7411_at_gmail.com wrote:
>>> I’m working on an advertising network.
>>>
>>> Is it better to store the banners in the database or on the file system?
>>
>> There are advantages and disadvantages to both. I like to store images
>> related to a page in a database. It helps maintain integrity - you
>> won't accidentally delete an image if you use the INNODB engine and set
>> up your referential integrity (foreign keys) properly.
>>
>> OTOH, if you're storing the images in the database, you'll need a script
>> to do the retrieval - you can't just do it in html. However, this can
>> also be advantageous because you can better control access to the images
>> (I've had other sites link to my images without my permissions before -
>> running up my bandwidth).
>>
>> Some people will say that images don't belong in a database. But when
>> you get right down to it, a file system is just a different kind of
>> database.
>
> Sure, but the file system seldom runs inside another file system and a
> database seldom handles directly with the block device, so could make
> things slower.
>

Which can be an advantage. The database may cache the images where the file system may have reused the cache holding the image. Also, databases are made for fast access to many rows; in a database 1,000,000 rows is not unusual. But that many files in a single directory in a file system will be much slower. On Unix it will also take a lot more inodes.

Now I highly doubt anyone other than the facebook or similar sites will have 1,000,000 images on their system. But accessing even 1,000 images (which is not at all unusual for an e-commerce site) can be faster through a database.

> But in the end it's just question about what solves the issue best.
>

Very true.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex_at_attglobal.net
==================
Received on Mon Jun 06 2016 - 21:02:14 CEST

Original text of this message