将 BLOB 字段添加到表中的性能开销

发布于 2024-07-17 06:15:38 字数 427 浏览 4 评论 0原文

我正在尝试在两种可能的实现之间做出决定,并且渴望选择最好的一种:)

我需要向当前只有 3 个简单字段的表添加一个可选的 BLOB 字段。 据预测,新字段将在不到 10%、甚至可能不到 5% 的情况下使用,因此对于大多数行来说它将为空 - 事实上,我们的大多数客户可能永远不会有任何 BLOB 数据。

一位同事的第一个想法是添加一个新表来仅保存 BLOB,并在第一个表中添加一个(可为空的)外键。 他预测这将在查询第一个表时带来性能优势。

我的想法是,将 BLOB 直接存储在原始表中更符合逻辑,也更容易。 我们的任何查询都不会从该表中执行 SELECT * 操作,因此我的直觉是直接存储它不会产生显着的性能开销。

我将对这两种选择进行基准测试,但我希望一些 SQL 专家能从经验中得到任何建议。

使用 MSSQL 和 Oracle。

I am trying to decide between two possible implementations and am eager to choose the best one :)

I need to add an optional BLOB field to a table which currently only has 3 simple fields. It is predicted that the new field will be used in fewer than 10%, maybe even less than 5% of cases so it will be null for most rows - in fact most of our customers will probably never have any BLOB data in there.

A colleague's first inclination was to add a new table to hold just the BLOBs, with a (nullable) foreign key in the first table. He predicts this will have performance benefits when querying the first table.

My thoughts were that it is more logical and easier to store the BLOB directly in the original table. None of our queries do SELECT * from that table so my intuition is that storing it directly won't have a significant performance overhead.

I'm going to benchmark both choices but I was hoping some SQL gurus had any advice from experience.

Using MSSQL and Oracle.

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

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

发布评论

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

评论(1

枉心 2024-07-24 06:15:38

对于 MSSQL,blob 将存储在数据库中的单独页面上,因此如果列为空,它们不会影响性能。

如果您使用 IMAGE 数据类型,则数据始终存储在行外。
如果您使用 varbinary(max) 数据类型,那么如果数据 > 8kb 它存储在行外部,否则根据表选项,它可能存储在行中。

如果只有几行包含 blob,则性能不应受到影响。

For MSSQL, the blobs will be stored on a separate page in the database so they should not affect performance if the column is null.

If you use the IMAGE data type then the data is always stored out of the row.
If you use the varbinary(max) data type then if the data is > 8kb it is stored outside the row, otherwise it may be stored in the row depending on the table options.

If you only have a few rows with blobs the performance should not be affected.

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