设计一个表来存储 EXIF 数据

发布于 2024-12-06 19:45:33 字数 206 浏览 0 评论 0原文

我希望通过查询包含 EXIF 数据的表获得最佳性能。相关查询将仅在 EXIF 数据中搜索指定字符串并返回匹配的行索引。

话虽如此,将 EXIF 数据存储在每个标签具有单独列的表中是否会更好,或者将所有标签存储在单个列中作为一个长分隔字符串也适合我?

我将存储大约 115 个 EXIF 标签,如果连接成单个字符串,每条记录的长度约为 1500 到 2000 个字符。

I'm looking to get the best performance out of querying a table containing EXIF data. The queries in question will only search the EXIF data for the specified strings and return the row index on a match.

With that said, would it better to store the EXIF data in a table with separate columns for each of the tags, or would storing all of the tags in a single column as one long delimited string suit me just as well?

There are around 115 EXIF tags I'll be storing, and each record would be around 1500 to 2000 chars in length if concatenated into a single string.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

司马昭之心 2024-12-13 19:45:33

如果将它们全部存储在一列中,您将无法从索引中获得性能优势。您还将违反数据库设计的基本规则,这会产生其自身的后果(每一列应该只存储一条数据)。

我可能会使用与此类似的结构:

CREATE TABLE Image_EXIF (
    image_id    INT,
    exif_tag_id INT,
    exif_value  VARCHAR(100),  -- I don't know what an appropriate size would really be
    CONSTRAINT PK_Image_EXIF PRIMARY KEY CLUSTERED (image_id, exif_tag_id),
    CONSTRAINT FK_Image_EXIF_image_id FOREIGN KEY image_id REFERENCES Images (image_id),
    CONSTRAINT FK_Image_EXIF_exif_tag_id FOREIGN KEY exif_tag_id REFERENCES EXIF_Tags (exif_tag_id)
)

EXIF_Tags 表将包含所有有效标签,而 Images 表将保存图像。然后,您可以在 exif_t​​ag_id 列上建立索引,也可以在 exif_value 列上建立索引,以便快速搜索。

If you store them all in one column you're not going to be able to get performance benefits from indexes. You'll also be violating a cardinal rule of database design, which has its own consequences (each column should only store one piece of data).

I would probably use a structure similar to this:

CREATE TABLE Image_EXIF (
    image_id    INT,
    exif_tag_id INT,
    exif_value  VARCHAR(100),  -- I don't know what an appropriate size would really be
    CONSTRAINT PK_Image_EXIF PRIMARY KEY CLUSTERED (image_id, exif_tag_id),
    CONSTRAINT FK_Image_EXIF_image_id FOREIGN KEY image_id REFERENCES Images (image_id),
    CONSTRAINT FK_Image_EXIF_exif_tag_id FOREIGN KEY exif_tag_id REFERENCES EXIF_Tags (exif_tag_id)
)

The EXIF_Tags table would have all of the valid tags and the Images table would hold the images. You can then have indexes on the exif_tag_id column and possibly the exif_value column for quick searching.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文