[英]Performance in tables with binary data/images
I made a people maintenance screen. 我做了一个人员维护屏幕。 The client want me to store the photo of every person in the database, and I made it without problems. 客户希望我将每个人的照片存储在数据库中,而我做到了没有问题。 I have a separate table for the images with two fields, Id_person,and Image. 我有一个单独的图像表,其中包含两个字段Id_person和Image。
I'm a little worried because it's the first time that i work with images in database. 我有点担心,因为这是我第一次使用数据库中的图像。 will I have problems of performance when the table grows beyond 1000/5000 images? 当表格增长到超过1000/5000张图像时,我会遇到性能问题吗? I suppose that the size of every image will make a difference. 我想每个图像的大小都会有所不同。 I'm sure that I will need to control that the user don't save very big images in the Database. 我确定我需要控制用户不要在数据库中保存很大的图像。
What would be a good size limit? 好的尺寸限制是多少? The client only need pics of the face, but I'm sure that someone will try to make the pics with a "last model" camera in full quality ;) 客户只需要脸部照片,但我敢肯定,有人会尝试用“最新型号”的照相机来制作高质量的照片;)
Thanks. 谢谢。
It's usually preferred to keep a folder of images and the DB just references that folder. 通常最好保留一个图像文件夹,而DB仅引用该文件夹。 Ideally, each person has a unique ID and the files in the "images" folder match that ID. 理想情况下,每个人都有一个唯一的ID,并且“ images”文件夹中的文件与该ID匹配。
If you really want to store the binary data directly, you can get a reasonable quality photo in 8KB of a JPEG (approx 250x250 pix @ 25% quality). 如果您真的想直接存储二进制数据,则可以以8KB的JPEG格式获得质量合理的照片(约250x250像素@ 25%的质量)。 Of course, this would be unacceptable for printing, but is fine for identification. 当然,这对于打印将是不可接受的,但是对于识别是很好的。
Only you will know if you can accept an additional 8KB per row in your database server. 只有您知道您是否可以在数据库服务器中每行接受额外的8KB。
If you absoultely MUST do it this way, I would say limit it to just a few kilobytes each. 如果您绝对必须采用这种方式,我会说将其限制为每个千字节。 However, every database admin in the world will probably tell you that blobing images into a database field is a very, very bad idea. 但是,世界上每个数据库管理员都可能会告诉您,将图像膨胀到数据库字段是一个非常非常糟糕的主意。 Most noticably you will see the performance decrease drastically when the database file grows beyond two gigabytes in size. 最值得注意的是,当数据库文件的大小超过2 GB时,性能将急剧下降。
I would prefer to do as jheddings said and have a folder with each person's ID be the file name and just use a standard .jpg or something after that on a network share so all computers using the app can access the images. 我更愿意像jheddings所说的那样做,并在每个人的ID的文件夹中添加一个文件名,然后在网络共享上使用一个标准的.jpg或其他名称,以便使用该应用程序的所有计算机都可以访问这些图像。
Some find that simply using the ID isn't good enough incase the photo needs to be deleted or archived, in which case they will put a NVARCHAR(MAX) field into their database and store the network file path to the image instead of the actual image. 一些人发现,仅在需要删除或存档照片的情况下,仅使用ID是不够的,在这种情况下,他们会将NVARCHAR(MAX)字段放入其数据库中,并将网络文件路径存储为图像,而不是实际的图片。
I would only blob the image if your customer absolutely cannot have a network share path. 如果您的客户绝对不能拥有网络共享路径,我只会使图像模糊。
只要它在具有ID | BLOB的单独表中,获取该照片就不会有任何性能问题,但另一方面,我更喜欢在DB中仅保留对hdd上文件的引用(如果它仅包含用户照片,则更好;确实不需要引用,因为ID为1的用户访问/images/1.jpg)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.