问题描述
嗨,克里斯/康纳,
我有一个表,有25列,其中col_1,col_2,col_3,col_4包含在复合唯一键中。
每天在此表上有60k的插入/更新。
我在这里的查询是-如果我们在特定表的4列上创建复合唯一键 (例如DML操作或索引维护中的缓慢),它会带来任何性能问题吗?
我有一个表,有25列,其中col_1,col_2,col_3,col_4包含在复合唯一键中。
每天在此表上有60k的插入/更新。
我在这里的查询是-如果我们在特定表的4列上创建复合唯一键 (例如DML操作或索引维护中的缓慢),它会带来任何性能问题吗?
专家解答
Oracle数据库支持使用 (唯一) 索引的唯一约束。每次插入/更新/删除行时,数据库都必须相应地修改索引。因此,它为您的数据更改增加了一些额外的开销。
但是!
唯一的约束可以保护您的数据,防止您插入重复项。删除约束以节省索引开销意味着you需要做这项工作。在多用户环境中确保此逻辑正确且快速是hard。
我的建议:
Keep the unique constraint。
60,000 inserts and updates per day works out at around one every second or two。Hardly worth worrying about the minimal index overhead compared to the effort of coding this yourself。
If you're really worried, load test your application。But don't just compare it with and without the constraint。Compare:
-您的应用程序按现在的情况,具有DB约束
-您的应用程序具有所有其他逻辑以进行唯一检查,并且没有约束的数据库
I'd be shocked if the second version turned out both faster and correct。
但是!
唯一的约束可以保护您的数据,防止您插入重复项。删除约束以节省索引开销意味着you需要做这项工作。在多用户环境中确保此逻辑正确且快速是hard。
我的建议:
Keep the unique constraint。
60,000 inserts and updates per day works out at around one every second or two。Hardly worth worrying about the minimal index overhead compared to the effort of coding this yourself。
If you're really worried, load test your application。But don't just compare it with and without the constraint。Compare:
-您的应用程序按现在的情况,具有DB约束
-您的应用程序具有所有其他逻辑以进行唯一检查,并且没有约束的数据库
I'd be shocked if the second version turned out both faster and correct。
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




