Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It's a good idea use filestream to store images and thumbnails?

We are designing a .NET application, that stores and search a large amount of images (>100.000).

When we upload an image, we need to create a thumbnail and store the original image and the thumbnail in the DB (SQL Server 2008 R2).

I've read that the best way to store images is using FILESTREAM

http://msdn.microsoft.com/en-us/library/cc949109.aspx

but when the images are smaller this is ineficient.

Is a good idea to store images and thumbnails using filestream? There is better alternative?

like image 258
Dr. No Avatar asked Dec 20 '11 11:12

Dr. No


2 Answers

There's a really good paper by Microsoft Research called To Blob or Not To Blob that discusses this topic in depth.

Their conclusion after a large number of performance tests and analysis is this:

  • if your pictures or document are typically below 256K in size, storing them in a database VARBINARY column is more efficient

  • if your pictures or document are typically over 1 MB in size, storing them in the filesystem is more efficient (and with SQL Server 2008's FILESTREAM attribute, they're still under transactional control and part of the database)

  • in between those two, it's a bit of a toss-up depending on your use

If you decide to put your pictures into a SQL Server table, I would strongly recommend using a separate table for storing those pictures - do not store the employee foto in the employee table - keep them in a separate table. That way, the Employee table can stay lean and mean and very efficient, assuming you don't always need to select the employee foto, too, as part of your queries.

For filegroups, check out Files and Filegroup Architecture for an intro. Basically, you would either create your database with a separate filegroup for large data structures right from the beginning, or add an additional filegroup later. Let's call it "LARGE_DATA".

Now, whenever you have a new table to create which needs to store VARCHAR(MAX) or VARBINARY(MAX) columns, you can specify this file group for the large data:

 CREATE TABLE dbo.YourTable
     (....... define the fields here ......)
     ON Data                   -- the basic "Data" filegroup for the regular data
     TEXTIMAGE_ON LARGE_DATA   -- the filegroup for large chunks of data

Check out the MSDN intro on filegroups, and play around with it!

like image 197
marc_s Avatar answered Oct 15 '22 22:10

marc_s


Actually the proper answer - it depends. If the images are relatively small - you can keep it in varbinary(max) field.

Why not FILESTREAM? - The FILESTREAM performance reaches its best on large BLOB values - 1Mb+

like image 34
Oleg Dok Avatar answered Oct 15 '22 20:10

Oleg Dok