立即更新表或“批量”更新表稍后更新数据库吗?这是可取的吗?
我有一个关于数据库中半恒定更新的问题。简而言之,它涉及网页上的结帐功能,每次调用结帐功能时都会执行五个步骤。
我想尝试优化此功能,并关注每次执行结帐时更新表的步骤。我获取从购物车检索的信息,然后更新相关表。
我确实有一些索引,从中获得的收益比离开它们要大,所以这是我愿意承担的成本。
现在,我的问题是。在某种程度上,就性能而言,最好不要立即更新表,而是收集每个结帐项目并以某种方式保存它们(可能在文件中),然后在一天的特定时间(或几次)获取此文件并然后用新信息更新表。
然后我开始考虑是否有可能使用某种批量更新来获取文件、哈希图、数组(或?),然后更新它。
我正在使用 IBM DB2 版本 9.7
Mestika
I have a question regarding a semi-constant update in a database. In short it is regarding a checkout function on a web page, which each time the checkout function is evoked it do five steps.
I want to try to optimize this function and have my eye on a step where I update a table each time the checkout is performed. I take the information retrieved from the shopping cart and then update the table in question.
I do have some indexes on the table, the gain from those are greater than leaving them so this is a cost I’m willing to take.
Now, my question is. Could it in some way regarding to performance be better to not update the table instantly but collect every checkout items and save them in some way (maybe in a file) and then at a specific time (or several times) at day take this file and then update the table with the new information.
Then I started thinking about if there was a possibility to use some sort of Bulk Update to take a file, hashmap, array (or?) and then update it.
And I’m using IBM DB2 version 9.7
Mestika
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将失去进行事务的能力,或者在中途一步后从失败中恢复的能力,所以我会避免使用这种方法。您可以尝试使用准备好的语句,或 JDBC 2.0 提供的批量更新,其中多个语句作为一个单元提交到数据库。
You will lose the ability to do transactions, or to recover from failure after a step midway, so I would avoid using this approach. You could try using prepared statements, or batch updates offered by JDBC 2.0 where multiple statements are submitted to the DB as a single unit.