什么是数据库中更好的额外查询或额外列? [英] What is better extra query or extra column in database?

查看:25
本文介绍了什么是数据库中更好的额外查询或额外列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最好是在数据库中增加额外的查询或额外的列,以获取只需要很少时间的数据.

What is better extra query or extra column in database for data that will be available very less time.

示例:在子用户管理的情况下,我在主用户​​表中添加了一个额外的列super_user_id,如果用户类型为sub_user且默认列值为-1则设置为enrty,或者在该表中创建新表并管理子用户

Example: In Case of sub user management either i add one extra column super_user_id in main users table and make enrty if users types are sub_user and the default column value is -1 or i create new table and manage sub user in that table.

但是在登录的情况下,我必须在两个表中进行搜索,而这又需要我进行一次查询.

But in case of login i have to search in two tables and this i have to make one more query.

谢谢

推荐答案

没有普遍的答案;您必须更具体.我所能提供的只是一般原则.

There is no general answer; you'll have to be more specific. All I can provide are general principles.

在所有其他条件相同的情况下,由于多种原因,使用没有冗余信息的规范化数据库会更好.但是在某些情况下,冗余信息可以节省您的程序很多时间.一个示例是使用Markdown格式化文本:您需要存储原始标记以进行编辑,但是每次需要输出时都要格式化源,这可能会给系统带来极大的负担.因此,您可以添加一个冗余列来存储格式化的输出,并承担确保该列保持最新状态的额外责任.

All else being equal, you'll be better off with a well-normalized database without redundant information, for a number of reasons. But there are situations where redundant information could save your program a lot of time. One example is text formatted with Markdown: you need to store the original markup to allow for editing, but formatting the source every time you need the output may be extremely taxing on the system. Therefore, you might add a redundant column to store the formatted output and assume the additional responsibility of ensuring that that column is kept up-to-date.

我对您的情况了解最多的是,假定的额外列将保存查询.唯一正确的答案是,除非您知道保存一个查询的性能优势将弥补这一问题,否则您应该保持表的清洁和最小化.请记住,过早的优化是万恶之源–无论如何,您可能会发现应用程序的运行速度不够快.如果在分析时发现额外的查询是一个重大瓶颈,那么您可以考虑添加该列.

All I know about your situation is that the postulated extra column would save a query. The only correct answer to that is that you should probably keep your table clean and minimal unless you know that the performance benefit of saving one query will make up for it. Remember, premature optimization is the root of all evil – you may find that your application runs more than fast enough anyways. If find while profiling that the extra query is a significant bottleneck, then you might consider adding the column.

同样,在没有更多了解您的情况的情况下,无法提供具体或具体的建议,但是我希望至少可以帮助您做出决定.

Again, without more knowledge of your situation, it is impossible to provide a specific or concrete recommendation, but I hope that I've at least helped you to come to a decision.

这篇关于什么是数据库中更好的额外查询或额外列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆