简体   繁体   English

具有二进制数据/图像的表中的性能

[英]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.

相关问题 在多平台项目中将用户图像存储为二进制数据还是静态文件的性能影响? - Performance impact of storing user images as binary data vs. static files in a multi-platform project? 图像的核心数据性能问题 - Core Data performance issue with images 针对各种数据库表验证数据的性能 - Performance for validating data against various database tables 获取多个表数据而不会损失性能? - Get multiple tables data without performance lost? 在共享首选项中保留显式数据与二进制数据(性能) - Persisting Explicit Data vs Binary Data (Performance) in Shared Preferences 如何提高二进制数据转换的Dart性能? - How to improve Dart performance of data conversion to/from binary? MySQL性能; 大型数据表还是多个数据表? - MySQL performance; large data table or multiple data tables? 如何提高查询性能,以将数据插入组合在一起的多个表中 - How to improve query performance that inserts data into multiple tables that combines it 一次渲染许多(32)表/数据时WPF性能问题 - WPF performance issue when rendering many (32) tables/data at once 如何在大型InnoDB表上提高LOAD DATA性能? - How can I improve LOAD DATA performance on large InnoDB tables?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM